本文整理匯總了Java中java.util.Properties.setProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java Properties.setProperty方法的具體用法?Java Properties.setProperty怎麽用?Java Properties.setProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Properties
的用法示例。
在下文中一共展示了Properties.setProperty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Service
import java.util.Properties; //導入方法依賴的package包/類
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;
}
}
示例2: testGetShortProperty
import java.util.Properties; //導入方法依賴的package包/類
@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));
}
示例3: compile
import java.util.Properties; //導入方法依賴的package包/類
/**
* 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);
}
示例4: init
import java.util.Properties; //導入方法依賴的package包/類
@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);
}
示例5: createRegion
import java.util.Properties; //導入方法依賴的package包/類
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;
}
示例6: testBug27655
import java.util.Properties; //導入方法依賴的package包/類
/**
* 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();
}
}
}
示例7: validateRegionMap
import java.util.Properties; //導入方法依賴的package包/類
@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();
}
示例8: getClientInfo
import java.util.Properties; //導入方法依賴的package包/類
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;
}
示例9: loadProperties
import java.util.Properties; //導入方法依賴的package包/類
/**
* 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;
}
示例10: object2Properties
import java.util.Properties; //導入方法依賴的package包/類
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;
}
示例11: testBug26173
import java.util.Properties; //導入方法依賴的package包/類
/**
* 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();
}
}
}
示例12: configureSparkContext
import java.util.Properties; //導入方法依賴的package包/類
/**
* 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);
}
示例13: main
import java.util.Properties; //導入方法依賴的package包/類
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);
}
示例14: testBug72712
import java.util.Properties; //導入方法依賴的package包/類
/**
* 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
}
示例15: testTruncationDisable
import java.util.Properties; //導入方法依賴的package包/類
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);
}