コード例 #1
0
 public static String getConfigFilePath(Properties props) {
   String configResourcePath =
       PropertiesHelper.getString(CacheEnvironment.CONFIG_FILE_PATH_LEGACY, props, null);
   if (StringHelper.isEmpty(configResourcePath)) {
     configResourcePath =
         PropertiesHelper.getString(CacheEnvironment.CONFIG_FILE_PATH, props, null);
   }
   return configResourcePath;
 }
コード例 #2
0
  public void testParseExceptions() {
    boolean b = PropertiesHelper.getBoolean("parse.error", props);
    assertFalse("parse exception case - boolean", b);

    try {
      PropertiesHelper.getInt("parse.error", props, 20);
      fail("parse exception case - int");
    } catch (NumberFormatException expected) {
    }

    try {
      PropertiesHelper.getInteger("parse.error", props);
      fail("parse exception case - Integer");
    } catch (NumberFormatException expected) {
    }
  }
コード例 #3
0
 public static int getLockTimeoutInMillis(Properties props) {
   int timeout = -1;
   try {
     timeout = PropertiesHelper.getInt(LOCK_TIMEOUT, props, -1);
   } catch (Exception e) {
     Logger.getLogger(CacheEnvironment.class).finest(e);
   }
   if (timeout < 0) {
     timeout = MAXIMUM_LOCK_TIMEOUT;
   }
   return timeout;
 }
コード例 #4
0
  public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
    tableName = PropertiesHelper.getString(ID_TABLE, params, DEFAULT_TABLE);
    pkColumnName = PropertiesHelper.getString(PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN);
    valueColumnName = PropertiesHelper.getString(VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN);
    String schemaName = params.getProperty(SCHEMA);
    String catalogName = params.getProperty(CATALOG);
    keySize = PropertiesHelper.getInt(PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH);
    String keyValue = PropertiesHelper.getString(PK_VALUE_NAME, params, params.getProperty(TABLE));

    if (tableName.indexOf('.') < 0) {
      tableName = Table.qualify(catalogName, schemaName, tableName);
    }

    query =
        "select "
            + valueColumnName
            + " from "
            + dialect.appendLockHint(LockMode.UPGRADE, tableName)
            + " where "
            + pkColumnName
            + " = '"
            + keyValue
            + "'"
            + dialect.getForUpdateString();

    update =
        "update "
            + tableName
            + " set "
            + valueColumnName
            + " = ? where "
            + valueColumnName
            + " = ? and "
            + pkColumnName
            + " = '"
            + keyValue
            + "'";

    insert =
        "insert into "
            + tableName
            + "("
            + pkColumnName
            + ", "
            + valueColumnName
            + ") "
            + "values('"
            + keyValue
            + "', ?)";

    // hilo config
    maxLo = PropertiesHelper.getInt(MAX_LO, params, Short.MAX_VALUE);
    lo = maxLo + 1; // so we "clock over" on the first invocation
    returnClass = type.getReturnedClass();
  }
コード例 #5
0
  /**
   * Builds a new {@link Cache} instance, and gets it's properties from the OSCache {@link Config}
   * which reads the properties file (<code>oscache.properties</code>) from the classpath. If the
   * file cannot be found or loaded, an the defaults are used.
   *
   * @param region
   * @param properties
   * @return
   * @throws CacheException
   */
  public Cache buildCache(String region, Properties properties) throws CacheException {

    int refreshPeriod =
        PropertiesHelper.getInt(
            StringHelper.qualify(region, OSCACHE_REFRESH_PERIOD),
            OSCACHE_PROPERTIES,
            CacheEntry.INDEFINITE_EXPIRY);
    String cron = OSCACHE_PROPERTIES.getProperty(StringHelper.qualify(region, OSCACHE_CRON));

    // construct the cache
    final OSCache cache = new OSCache(refreshPeriod, cron, region);

    // Integer capacity = PropertiesHelper.getInteger(
    // StringHelper.qualify(region, OSCACHE_CAPACITY), OSCACHE_PROPERTIES );
    // if ( capacity!=null ) cache.setCacheCapacity( capacity.intValue() );

    return cache;
  }
コード例 #6
0
  public void testPlaceholderReplacement() {
    PropertiesHelper.resolvePlaceHolders(props);

    String str = PropertiesHelper.getString("my.nonexistent.prop", props, "did.not.exist");
    assertEquals("did.not.exist", str);
    str = PropertiesHelper.getString("my.nonexistent.prop", props, null);
    assertNull(str);
    str = PropertiesHelper.getString("my.string.prop", props, "na");
    assertEquals("replacement did not occur", "string", str);
    str = PropertiesHelper.getString("my.string.prop", props, "did.not.exist");
    assertEquals("replacement did not occur", "string", str);

    boolean bool = PropertiesHelper.getBoolean("my.nonexistent.prop", props);
    assertFalse("non-exists as boolean", bool);
    bool = PropertiesHelper.getBoolean("my.nonexistent.prop", props, false);
    assertFalse("non-exists as boolean", bool);
    bool = PropertiesHelper.getBoolean("my.nonexistent.prop", props, true);
    assertTrue("non-exists as boolean", bool);
    bool = PropertiesHelper.getBoolean("my.boolean.prop", props);
    assertTrue("boolean replacement did not occur", bool);
    bool = PropertiesHelper.getBoolean("my.boolean.prop", props, false);
    assertTrue("boolean replacement did not occur", bool);

    int i = PropertiesHelper.getInt("my.nonexistent.prop", props, -1);
    assertEquals(-1, i);
    i = PropertiesHelper.getInt("my.int.prop", props, 100);
    assertEquals(1, i);

    Integer I = PropertiesHelper.getInteger("my.nonexistent.prop", props);
    assertNull(I);
    I = PropertiesHelper.getInteger("my.integer.prop", props);
    assertEquals(I, new Integer(1));

    str = props.getProperty("partial.prop1");
    assertEquals("partial replacement (ends)", "tmp/middle/dir/tmp.txt", str);

    str = props.getProperty("partial.prop2");
    assertEquals("partial replacement (midst)", "basedir/tmp/myfile.txt", str);
  }
コード例 #7
0
 public static boolean isExplicitVersionCheckEnabled(Properties props) {
   return PropertiesHelper.getBoolean(CacheEnvironment.EXPLICIT_VERSION_CHECK, props, false);
 }
コード例 #8
0
 public static boolean shutdownOnStop(Properties props, boolean defaultValue) {
   return PropertiesHelper.getBoolean(CacheEnvironment.SHUTDOWN_ON_STOP, props, defaultValue);
 }
コード例 #9
0
 public static boolean isNativeClient(Properties props) {
   return PropertiesHelper.getBoolean(CacheEnvironment.USE_NATIVE_CLIENT, props, false);
 }
コード例 #10
0
 public static String getInstanceName(Properties props) {
   return PropertiesHelper.getString(HAZELCAST_INSTANCE_NAME, props, null);
 }