Java Code Examples for java.util.Properties.setProperty()

The following are Jave code examples for showing how to use setProperty() of the java.util.Properties class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: dbg-amqp-dispatch-workshop   File: Service.java   View Source Code Vote up 6 votes
public Service() throws NamingException {
    System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
    System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
    System.setProperty("org.slf4j.simpleLogger.dateTimeFormat", "yyyy-MM-dd HH:mm:ss Z");
    System.setProperty("org.slf4j.simpleLogger.showThreadName", "false");

    try {
        Properties properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
        properties.setProperty("connectionfactory.connection", String.format(
                "amqp://%s:%d?amqp.idleTimeout=30000&jms.forceAsyncSend=true",
                "localhost",
                5672));
        properties.setProperty("queue.time", "/time");
        properties.setProperty("queue.date", "/date");
        this.context = new InitialContext(properties);
    } catch (NamingException ex) {
        LOGGER.error("Unable to proceed with broadcast receiver", ex);
        throw ex;
    }
}
 
Example 2
Project: apollo-custom   File: DefaultConfigTest.java   View Source Code Vote up 6 votes
@Test
public void testGetShortProperty() throws Exception {
  String someStringKey = "someStringKey";
  String someStringValue = "someStringValue";

  String someKey = "someKey";
  Short someValue = 2;

  Short someDefaultValue = -1;

  //set up config repo
  someProperties = new Properties();
  someProperties.setProperty(someStringKey, someStringValue);
  someProperties.setProperty(someKey, String.valueOf(someValue));
  when(configRepository.getConfig()).thenReturn(someProperties);

  DefaultConfig defaultConfig =
      new DefaultConfig(someNamespace, configRepository);

  assertEquals(someValue, defaultConfig.getShortProperty(someKey, someDefaultValue));
  assertEquals(someDefaultValue, defaultConfig.getShortProperty(someStringKey, someDefaultValue));
}
 
Example 3
Project: incubator-netbeans   File: Xsd2Java.java   View Source Code Vote up 6 votes
/**
 * Compile the XSD, if needed, to generate JAX-B binding library jars
 */
public boolean compile() throws IOException {
    if (getJaxbJarFile() != null) {
        return true;
    }
    
    FileObject jaxbBaseDir = getOrCreateJaxbFolder();
    FileObject userBuildFile = SaasServicesModel.getWebServiceHome()
            .getParent().getParent().getFileObject("build.properties");
    File jaxbBasePath = FileUtil.normalizeFile(FileUtil.toFile(jaxbBaseDir));
    File xsdFilePath = FileUtil.normalizeFile(FileUtil.toFile(xsdFile));
    File userBuildPath = FileUtil.normalizeFile(FileUtil.toFile(userBuildFile));
    
    Properties p = new Properties();
    p.setProperty(PROP_XSD_FILE, xsdFilePath.getPath());
    p.setProperty(PROP_PACKAGE_NAME, packageName);
    p.setProperty(PROP_JAXB_BASE, jaxbBasePath.getPath());
    p.setProperty(PROP_JAXB_JAR, jaxbJarPath);
    p.setProperty(PROP_JAXB_SRC_JAR, jaxbSourceJarPath);
    p.setProperty(PROP_USER_BUILD_PROPERTIES, userBuildPath.getPath());
    
    return createJaxBJar(p);
}
 
Example 4
Project: ditb   File: ConstantOccupancyWorkload.java   View Source Code Vote up 6 votes
@Override
public void init(Properties p) throws WorkloadException {
  disksize = Long.parseLong(p.getProperty(DISK_SIZE_PROPERTY, String.valueOf(DISK_SIZE_PROPERTY_DEFAULT)));
  storageages = Long.parseLong(p.getProperty(STORAGE_AGE_PROPERTY, String.valueOf(STORAGE_AGE_PROPERTY_DEFAULT)));
  occupancy = Double.parseDouble(p.getProperty(OCCUPANCY_PROPERTY, String.valueOf(OCCUPANCY_PROPERTY_DEFAULT)));

  if (p.getProperty(Client.RECORD_COUNT_PROPERTY) != null ||
      p.getProperty(Client.INSERT_COUNT_PROPERTY) != null ||
      p.getProperty(Client.OPERATION_COUNT_PROPERTY) != null) {
    System.err.println("Warning: record, insert or operation count was set prior to initting " +
        "ConstantOccupancyWorkload.  Overriding old values.");
  }
  NumberGenerator g = CoreWorkload.getFieldLengthGenerator(p);
  double fieldsize = g.mean();
  int fieldcount = Integer.parseInt(p.getProperty(FIELD_COUNT_PROPERTY, FIELD_COUNT_PROPERTY_DEFAULT));

  objectCount = (long) (occupancy * (disksize / (fieldsize * fieldcount)));
  if (objectCount == 0) {
    throw new IllegalStateException("Object count was zero.  Perhaps disksize is too low?");
  }
  p.setProperty(Client.RECORD_COUNT_PROPERTY, String.valueOf(objectCount));
  p.setProperty(Client.OPERATION_COUNT_PROPERTY, String.valueOf(storageages * objectCount));
  p.setProperty(Client.INSERT_COUNT_PROPERTY, String.valueOf(objectCount));

  super.init(p);
}
 
Example 5
Project: monarch   File: PersistentPartitionedRegionJUnitTest.java   View Source Code Vote up 6 votes
private Region createRegion(int ttl) {
  Properties props = new Properties();
  props.setProperty(MCAST_PORT, "0");
  props.setProperty(LOG_LEVEL, "info");
  // props.setProperty("log-file", "junit.log");
  cache = new CacheFactory(props).create();
  cache.createDiskStoreFactory().setMaxOplogSize(1).setDiskDirs(new File[] {dir}).create("disk");


  RegionFactory<Object, Object> rf = cache.createRegionFactory()
      .setDataPolicy(DataPolicy.PERSISTENT_PARTITION).setDiskStoreName("disk");
  rf.setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(1).create());
  if (ttl > 0) {
    rf.setEntryTimeToLive(new ExpirationAttributes(ttl, ExpirationAction.DESTROY));
  }
  Region region = rf.create("region");
  return region;
}
 
Example 6
Project: OpenVertretung   File: ConnectionRegressionTest.java   View Source Code Vote up 6 votes
/**
 * Tests fix for BUG#27655 - getTransactionIsolation() uses
 * "SHOW VARIABLES LIKE" which is very inefficient on MySQL-5.0+
 * 
 * @throws Exception
 */
public void testBug27655() throws Exception {
    Properties props = new Properties();
    props.setProperty("profileSQL", "true");
    props.setProperty("logger", "StandardLogger");
    StandardLogger.startLoggingToBuffer();

    Connection loggedConn = null;

    try {
        loggedConn = getConnectionWithProps(props);
        loggedConn.getTransactionIsolation();

        if (versionMeetsMinimum(8, 0, 3)) {
            assertEquals(-1, StandardLogger.getBuffer().toString().indexOf("SHOW VARIABLES LIKE 'transaction_isolation'"));
        } else if (versionMeetsMinimum(4, 0, 3)) {
            assertEquals(-1, StandardLogger.getBuffer().toString().indexOf("SHOW VARIABLES LIKE 'tx_isolation'"));
        }
    } finally {
        StandardLogger.dropBuffer();
        if (loggedConn != null) {
            loggedConn.close();
        }
    }
}
 
Example 7
Project: monarch   File: RegionMapFactoryImplTest.java   View Source Code Vote up 6 votes
@Test
public void validateRegionMap() {
  Properties properties = new Properties();
  properties.setProperty("mcast-port", "0");
  CacheFactory cacheFactory = new CacheFactory(properties);
  Cache cache = cacheFactory.create();
  Region<Object, Object> replicatedRegion =
      cache.createRegionFactory(RegionShortcut.REPLICATE).create("ReplicatedRegion");
  assertTrue(((LocalRegion) replicatedRegion).entries instanceof VMRegionMap);
  replicatedRegion.destroyRegion();

  Region<Object, Object> partitionRegion =
      cache.createRegionFactory(RegionShortcut.PARTITION).create("PartitionRegion");

  assertTrue(((LocalRegion) partitionRegion).entries instanceof VMRegionMap);
  partitionRegion.destroyRegion();

  Region<Object, Object> partitionRegionLRU =
      cache.createRegionFactory(RegionShortcut.PARTITION_OVERFLOW).create("PartitionRegionLRU");

  assertTrue(((LocalRegion) partitionRegionLRU).entries instanceof VMLRURegionMap);
  partitionRegionLRU.destroyRegion();
  cache.close();
}
 
Example 8
Project: ProyectoPacientes   File: JDBC4ClientInfoProviderSP.java   View Source Code Vote up 6 votes
public synchronized Properties getClientInfo(java.sql.Connection conn) throws SQLException {
    ResultSet rs = null;

    Properties props = new Properties();

    try {
        this.getClientInfoBulkSp.execute();

        rs = this.getClientInfoBulkSp.getResultSet();

        while (rs.next()) {
            props.setProperty(rs.getString(1), rs.getString(2));
        }
    } finally {
        if (rs != null) {
            rs.close();
        }
    }

    return props;
}
 
Example 9
Project: apfloat   File: ApfloatContext.java   View Source Code Vote up 6 votes
/**
 * Loads properties from a properties file or resource bundle.
 * First the <code>ResourceBundle</code> by the name "apfloat" is
 * located, then all properties found from that resource bundle
 * are put to a <code>Properties</code> object.<p>
 *
 * The resource bundle is found basically using the following logic
 * (note that this is standard Java <code>ResourceBundle</code>
 * functionality), in this order whichever is found first:
 *
 * <ol>
 *   <li>From the class named <code>apfloat</code> (that should be a subclass of <code>ResourceBundle</code>), in the current class path</li>
 *   <li>From the file "apfloat.properties" in the current class path</li>
 * </ol>
 *
 * @return Properties found in the "apfloat" resource bundle, or an empty <code>Properties</code> object, if the resource bundle is not found.
 */

public static Properties loadProperties()
    throws ApfloatRuntimeException
{
    Properties properties = new Properties();

    try
    {
        ResourceBundle resourceBundle = ResourceBundle.getBundle("apfloat");

        Enumeration<String> keys = resourceBundle.getKeys();
        while (keys.hasMoreElements())
        {
            String key = keys.nextElement();
            properties.setProperty(key, resourceBundle.getString(key));
        }
    }
    catch (MissingResourceException mre)
    {
        // Ignore - properties file or class is not found or can't be read
    }

    return properties;
}
 
Example 10
Project: rmq4note   File: MixAll.java   View Source Code Vote up 6 votes
public static Properties object2Properties(final Object object) {
    Properties properties = new Properties();

    Field[] fields = object.getClass().getDeclaredFields();
    for (Field field : fields) {
        if (!Modifier.isStatic(field.getModifiers())) {
            String name = field.getName();
            if (!name.startsWith("this")) {
                Object value = null;
                try {
                    field.setAccessible(true);
                    value = field.get(object);
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    e.printStackTrace();
                }

                if (value != null) {
                    properties.setProperty(name, value.toString());
                }
            }
        }
    }

    return properties;
}
 
Example 11
Project: ProyectoPacientes   File: ResultSetRegressionTest.java   View Source Code Vote up 5 votes
/**
 * Tests fix for BUG#26173 - fetching rows via cursor retrieves corrupted
 * data.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug26173() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    createTable("testBug26173", "(fkey int, fdate date, fprice decimal(15, 2), fdiscount decimal(5,3))", "InnoDB");
    this.stmt.executeUpdate("insert into testBug26173 values (1, '2007-02-23', 99.9, 0.02)");

    Connection fetchConn = null;
    Statement stmtRead = null;

    Properties props = new Properties();
    props.setProperty("useServerPrepStmts", "true");
    props.setProperty("useCursorFetch", "true");

    try {

        fetchConn = getConnectionWithProps(props);
        stmtRead = fetchConn.createStatement();
        stmtRead.setFetchSize(1000);

        this.rs = stmtRead.executeQuery("select extract(year from fdate) as fyear, fprice * (1 - fdiscount) as fvalue from testBug26173");

        assertTrue(this.rs.next());
        assertEquals(2007, this.rs.getInt(1));
        assertEquals("97.90200", this.rs.getString(2));
    } finally {
        if (stmtRead != null) {
            stmtRead.close();
        }

        if (fetchConn != null) {
            fetchConn.close();
        }
    }
}
 
Example 12
Project: Sempala   File: Spark.java   View Source Code Vote up 5 votes
/**
 * Add specific configuration for Spark SQL execution.
 */
public void configureSparkContext(){
	Properties properties = new Properties();
	properties.setProperty("spark.sql.parquet.filterPushdown", "true");
	properties.setProperty("spark.sql.inMemoryColumnarStorage.batchSize", "20000");
	if(dfPartitions != 0){
		properties.setProperty("spark.sql.shuffle.partitions", Integer.toString(dfPartitions));
	}
	
	hiveContext.setConf(properties);
}
 
Example 13
Project: bestconf   File: DDSSampler.java   View Source Code Vote up 5 votes
public static void main(String[] args){
	ArrayList<Attribute> atts = new ArrayList<Attribute>();
	
	Properties p1 = new Properties();
	p1.setProperty("range", "[0,1]");
	ProtectedProperties prop1 = new ProtectedProperties(p1);
	
	Properties p2 = new Properties();
	p2.setProperty("range", "[321,1E9]");
	ProtectedProperties prop2 = new ProtectedProperties(p2);
	
	Properties p3 = new Properties();
	p3.setProperty("range", "[1,30]");
	ProtectedProperties prop3 = new ProtectedProperties(p3);
	
	ArrayList<String> attVals = new ArrayList<String>();
	for (int i = 0; i < 5; i++)
	      attVals.add("val" + (i+1));
	
	atts.add(new Attribute("att1", prop1));
	atts.add(new Attribute("att2", prop2));
	atts.add(new Attribute("att3", prop3));
	//atts.add(new Attribute("att4", attVals));
	//Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
	//Instances data = LHSInitializer.getMultiDim(atts, 10, false);
	DDSSampler sampler = new DDSSampler(3);
	
	sampler.setCurrentRound(0);
	Instances data = sampler.sampleMultiDimContinuous(atts, 2, false);
	System.out.println(data);
	
	sampler.setCurrentRound(01);
	data = sampler.sampleMultiDimContinuous(atts, 2, false);
	System.out.println(data);
	
	sampler.setCurrentRound(2);
	data = sampler.sampleMultiDimContinuous(atts, 2, false);
	System.out.println(data);
}
 
Example 14
Project: BibliotecaPS   File: ConnectionRegressionTest.java   View Source Code Vote up 5 votes
/**
 * Test for Bug#72712 - SET NAMES issued unnecessarily.
 * 
 * Using a statement interceptor, ensure that SET NAMES is not
 * called if the encoding requested by the client application
 * matches that of character_set_server.
 * 
 * Also test that character_set_results is not set unnecessarily.
 */
public void testBug72712() throws Exception {
    // this test is only run when character_set_server=latin1
    if (!((MySQLConnection) this.conn).getServerVariable("character_set_server").equals("latin1")) {
        return;
    }

    Properties p = new Properties();
    p.setProperty("characterEncoding", "cp1252");
    p.setProperty("characterSetResults", "cp1252");
    p.setProperty("statementInterceptors", Bug72712StatementInterceptor.class.getName());

    getConnectionWithProps(p);
    // exception will be thrown from the statement interceptor if any SET statements are issued
}
 
Example 15
Project: BibliotecaPS   File: ResultSetRegressionTest.java   View Source Code Vote up 5 votes
public void testTruncationDisable() throws Exception {
    Properties props = new Properties();
    props.setProperty("jdbcCompliantTruncation", "false");
    Connection truncConn = null;

    truncConn = getConnectionWithProps(props);
    this.rs = truncConn.createStatement().executeQuery("SELECT " + Long.MAX_VALUE);
    this.rs.next();
    this.rs.getInt(1);

}
 
Example 16
Project: ProyectoPacientes   File: ResultSetRegressionTest.java   View Source Code Vote up 5 votes
public void testNPEWithUsageAdvisor() throws Exception {
    Connection advisorConn = null;

    Properties props = new Properties();
    props.setProperty("useUsageAdvisor", "true");

    advisorConn = getConnectionWithProps(props);
    this.pstmt = advisorConn.prepareStatement("SELECT 1");
    this.rs = this.pstmt.executeQuery();
    this.rs.close();
    this.rs = this.pstmt.executeQuery();
}
 
Example 17
Project: monarch   File: ConnectionPoolingJUnitTest.java   View Source Code Vote up 5 votes
@Before
public void setUp() throws Exception {
  encounteredException = false;
  props = new Properties();
  props.setProperty(MCAST_PORT, "0");
  String path = TestUtil.getResourcePath(ConnectionPoolingJUnitTest.class, "/jta/cachejta.xml");
  props.setProperty(CACHE_XML_FILE, path);
  ds1 = DistributedSystem.connect(props);
  cache = CacheFactory.create(ds1);
}
 
Example 18
Project: OftenPorter   File: MyBatisBridge.java   View Source Code Vote up 5 votes
/**
 * 见{@linkplain MyBatisOption#dataSource}
 * @param propertiesJson dsType{@linkplain DataSource}实现类.
 * @return
 */
public static DataSource buildDataSource(JSONObject propertiesJson)
{
    String dsType = (String) propertiesJson.remove("dsType");
    Properties properties = new Properties();
    for (String key : propertiesJson.keySet())
    {
        if(key.endsWith("--ignore")){
            continue;
        }
        properties.setProperty(key, propertiesJson.getString(key));
    }
    return buildDataSource(dsType, properties);
}
 
Example 19
Project: monarch   File: Bug32947ValueConstraintJUnitTest.java   View Source Code Vote up 5 votes
@Before
public void setUp() throws java.lang.Exception {
  Properties properties = new Properties();
  properties.setProperty(MCAST_PORT, "0");
  distributedSystem = DistributedSystem.connect(properties);
  cache = CacheFactory.create(distributedSystem);
}
 
Example 20
Project: monarch   File: LocatorDUnitTest.java   View Source Code Vote up 4 votes
/**
 * Tests starting, stopping, and restarting a locator. See bug 32856.
 * 
 * @since GemFire 4.1
 */
@Test
public void testRestartLocator() throws Exception {
  disconnectAllFromDS();
  port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
  DistributedTestUtils.deleteLocatorStateFile(port1);
  File logFile = new File("");
  File stateFile = new File("locator" + port1 + "state.dat");
  VM vm0 = Host.getHost(0).getVM(0);
  final Properties p = new Properties();
  p.setProperty(LOCATORS, Host.getHost(0).getHostName() + "[" + port1 + "]");
  p.setProperty(MCAST_PORT, "0");
  p.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
  addDSProps(p);
  if (stateFile.exists()) {
    stateFile.delete();
  }

  org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Starting locator");
  Locator locator = Locator.startLocatorAndDS(port1, logFile, p);
  try {

    vm0.invoke(() -> {
      DistributedSystem.connect(p);
      return null;
    });

    LogWriterUtils.getLogWriter().info("Stopping locator");
    locator.stop();

    LogWriterUtils.getLogWriter().info("Starting locator");
    locator = Locator.startLocatorAndDS(port1, logFile, p);

    vm0.invoke("disconnect", () -> {
      DistributedSystem.connect(p).disconnect();
      return null;
    });

  } finally {
    locator.stop();
  }

}