@Test(expected = IllegalArgumentException.class) public void convert_invalid_batchPutUnit() throws Exception { Map<String, String> map = new HashMap<>(); map.put(JdbcProfile.KEY_DRIVER, org.h2.Driver.class.getName()); map.put(JdbcProfile.KEY_URL, h2.getJdbcUrl()); map.put(JdbcProfile.KEY_BATCH_PUT_UNIT, "Hello, world!"); JdbcProfile.convert(toProfile(map)); }
public static JdbcProfile convert(ResourceProfile profile) { if (profile == null) { throw new IllegalArgumentException("profile must not be null"); } String resourceName = profile.getName(); ClassLoader classLoader = profile.getContext().getClassLoader(); String driver = extract(profile, KEY_DRIVER, true); String url = extract(profile, KEY_URL, true); String user = extract(profile, KEY_USER, false); String password = extract(profile, KEY_PASSWORD, false); Map<String, String> connectionProperties = extractConnectionProperties(profile); JdbcProfile result = new JdbcProfile( resourceName, classLoader, driver, url, user, password, connectionProperties); int batchGetUnit = extractInt(profile, KEY_BATCH_GET_UNIT, 0, DEFAULT_BATCH_GET_UNIT); long batchPutUnit = extractLong(profile, KEY_BATCH_PUT_UNIT, 1, DEFAULT_BATCH_PUT_UNIT); int connectRetryCount = extractInt(profile, KEY_CONNECT_RETRY_COUNT, 0, DEFAULT_CONNECT_RETRY_COUNT); int connectRetryInterval = extractInt(profile, KEY_CONNECT_RETRY_INTERVAL, 1, DEFAULT_CONNECT_RETRY_INTERVAL); String truncateStatement = extract(profile, KEY_TRUNCATE_STATEMENT, false); if (truncateStatement == null) { truncateStatement = DEFAULT_TRUNCATE_STATEMENT; } Set<String> optimizations = extractSet(profile, KEY_OPTIMIZATIONS); try { MessageFormat.format(truncateStatement, "dummy"); } catch (IllegalArgumentException e) { WGLOG.error("E00001", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement); throw new IllegalArgumentException(MessageFormat.format( "The \"{1}\" must be a valid MessageFormat: {2} (resource={0})", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement), e); } result.setBatchGetUnit(batchGetUnit); result.setBatchPutUnit(batchPutUnit); result.setConnectRetryCount(connectRetryCount); result.setConnectRetryInterval(connectRetryInterval); result.setTruncateStatement(truncateStatement); result.setOptimizations(optimizations); return result; }
JdbcProfile { public static JdbcProfile convert(ResourceProfile profile) { if (profile == null) { throw new IllegalArgumentException("profile must not be null"); } String resourceName = profile.getName(); ClassLoader classLoader = profile.getContext().getClassLoader(); String driver = extract(profile, KEY_DRIVER, true); String url = extract(profile, KEY_URL, true); String user = extract(profile, KEY_USER, false); String password = extract(profile, KEY_PASSWORD, false); Map<String, String> connectionProperties = extractConnectionProperties(profile); JdbcProfile result = new JdbcProfile( resourceName, classLoader, driver, url, user, password, connectionProperties); int batchGetUnit = extractInt(profile, KEY_BATCH_GET_UNIT, 0, DEFAULT_BATCH_GET_UNIT); long batchPutUnit = extractLong(profile, KEY_BATCH_PUT_UNIT, 1, DEFAULT_BATCH_PUT_UNIT); int connectRetryCount = extractInt(profile, KEY_CONNECT_RETRY_COUNT, 0, DEFAULT_CONNECT_RETRY_COUNT); int connectRetryInterval = extractInt(profile, KEY_CONNECT_RETRY_INTERVAL, 1, DEFAULT_CONNECT_RETRY_INTERVAL); String truncateStatement = extract(profile, KEY_TRUNCATE_STATEMENT, false); if (truncateStatement == null) { truncateStatement = DEFAULT_TRUNCATE_STATEMENT; } Set<String> optimizations = extractSet(profile, KEY_OPTIMIZATIONS); try { MessageFormat.format(truncateStatement, "dummy"); } catch (IllegalArgumentException e) { WGLOG.error("E00001", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement); throw new IllegalArgumentException(MessageFormat.format( "The \"{1}\" must be a valid MessageFormat: {2} (resource={0})", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement), e); } result.setBatchGetUnit(batchGetUnit); result.setBatchPutUnit(batchPutUnit); result.setConnectRetryCount(connectRetryCount); result.setConnectRetryInterval(connectRetryInterval); result.setTruncateStatement(truncateStatement); result.setOptimizations(optimizations); return result; } }
JdbcProfile { public static JdbcProfile convert(ResourceProfile profile) { if (profile == null) { throw new IllegalArgumentException("profile must not be null"); } String resourceName = profile.getName(); ClassLoader classLoader = profile.getContext().getClassLoader(); String driver = extract(profile, KEY_DRIVER, true); String url = extract(profile, KEY_URL, true); String user = extract(profile, KEY_USER, false); String password = extract(profile, KEY_PASSWORD, false); Map<String, String> connectionProperties = extractConnectionProperties(profile); JdbcProfile result = new JdbcProfile( resourceName, classLoader, driver, url, user, password, connectionProperties); int batchGetUnit = extractInt(profile, KEY_BATCH_GET_UNIT, 0, DEFAULT_BATCH_GET_UNIT); long batchPutUnit = extractLong(profile, KEY_BATCH_PUT_UNIT, 1, DEFAULT_BATCH_PUT_UNIT); int connectRetryCount = extractInt(profile, KEY_CONNECT_RETRY_COUNT, 0, DEFAULT_CONNECT_RETRY_COUNT); int connectRetryInterval = extractInt(profile, KEY_CONNECT_RETRY_INTERVAL, 1, DEFAULT_CONNECT_RETRY_INTERVAL); String truncateStatement = extract(profile, KEY_TRUNCATE_STATEMENT, false); if (truncateStatement == null) { truncateStatement = DEFAULT_TRUNCATE_STATEMENT; } Set<String> optimizations = extractSet(profile, KEY_OPTIMIZATIONS); try { MessageFormat.format(truncateStatement, "dummy"); } catch (IllegalArgumentException e) { WGLOG.error("E00001", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement); throw new IllegalArgumentException(MessageFormat.format( "The \"{1}\" must be a valid MessageFormat: {2} (resource={0})", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement), e); } result.setBatchGetUnit(batchGetUnit); result.setBatchPutUnit(batchPutUnit); result.setConnectRetryCount(connectRetryCount); result.setConnectRetryInterval(connectRetryInterval); result.setTruncateStatement(truncateStatement); result.setOptimizations(optimizations); return result; } JdbcProfile(
            String resourceName,
            ClassLoader classLoader,
            String driver,
            String url,
            String user,
            String password,
            long batchPutUnit);  JdbcProfile(
            String resourceName,
            ClassLoader classLoader,
            String driver,
            String url,
            String user,
            String password,
            Map<String, String> connectionProperties); }
JdbcProfile { public static JdbcProfile convert(ResourceProfile profile) { if (profile == null) { throw new IllegalArgumentException("profile must not be null"); } String resourceName = profile.getName(); ClassLoader classLoader = profile.getContext().getClassLoader(); String driver = extract(profile, KEY_DRIVER, true); String url = extract(profile, KEY_URL, true); String user = extract(profile, KEY_USER, false); String password = extract(profile, KEY_PASSWORD, false); Map<String, String> connectionProperties = extractConnectionProperties(profile); JdbcProfile result = new JdbcProfile( resourceName, classLoader, driver, url, user, password, connectionProperties); int batchGetUnit = extractInt(profile, KEY_BATCH_GET_UNIT, 0, DEFAULT_BATCH_GET_UNIT); long batchPutUnit = extractLong(profile, KEY_BATCH_PUT_UNIT, 1, DEFAULT_BATCH_PUT_UNIT); int connectRetryCount = extractInt(profile, KEY_CONNECT_RETRY_COUNT, 0, DEFAULT_CONNECT_RETRY_COUNT); int connectRetryInterval = extractInt(profile, KEY_CONNECT_RETRY_INTERVAL, 1, DEFAULT_CONNECT_RETRY_INTERVAL); String truncateStatement = extract(profile, KEY_TRUNCATE_STATEMENT, false); if (truncateStatement == null) { truncateStatement = DEFAULT_TRUNCATE_STATEMENT; } Set<String> optimizations = extractSet(profile, KEY_OPTIMIZATIONS); try { MessageFormat.format(truncateStatement, "dummy"); } catch (IllegalArgumentException e) { WGLOG.error("E00001", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement); throw new IllegalArgumentException(MessageFormat.format( "The \"{1}\" must be a valid MessageFormat: {2} (resource={0})", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement), e); } result.setBatchGetUnit(batchGetUnit); result.setBatchPutUnit(batchPutUnit); result.setConnectRetryCount(connectRetryCount); result.setConnectRetryInterval(connectRetryInterval); result.setTruncateStatement(truncateStatement); result.setOptimizations(optimizations); return result; } JdbcProfile(
            String resourceName,
            ClassLoader classLoader,
            String driver,
            String url,
            String user,
            String password,
            long batchPutUnit);  JdbcProfile(
            String resourceName,
            ClassLoader classLoader,
            String driver,
            String url,
            String user,
            String password,
            Map<String, String> connectionProperties); static JdbcProfile convert(ResourceProfile profile); String getResourceName(); ClassLoader getClassLoader(); Connection openConnection(); Map<String, String> getConnectionProperties(); int getBatchGetUnit(); void setBatchGetUnit(int value); long getBatchPutUnit(); void setBatchPutUnit(long value); int getConnectRetryCount(); void setConnectRetryCount(int value); int getConnectRetryInterval(); void setConnectRetryInterval(int value); String getTruncateStatement(String tableName); void setTruncateStatement(String pattern); Set<String> getOptimizations(); void setOptimizations(Collection<String> optimizations); }
JdbcProfile { public static JdbcProfile convert(ResourceProfile profile) { if (profile == null) { throw new IllegalArgumentException("profile must not be null"); } String resourceName = profile.getName(); ClassLoader classLoader = profile.getContext().getClassLoader(); String driver = extract(profile, KEY_DRIVER, true); String url = extract(profile, KEY_URL, true); String user = extract(profile, KEY_USER, false); String password = extract(profile, KEY_PASSWORD, false); Map<String, String> connectionProperties = extractConnectionProperties(profile); JdbcProfile result = new JdbcProfile( resourceName, classLoader, driver, url, user, password, connectionProperties); int batchGetUnit = extractInt(profile, KEY_BATCH_GET_UNIT, 0, DEFAULT_BATCH_GET_UNIT); long batchPutUnit = extractLong(profile, KEY_BATCH_PUT_UNIT, 1, DEFAULT_BATCH_PUT_UNIT); int connectRetryCount = extractInt(profile, KEY_CONNECT_RETRY_COUNT, 0, DEFAULT_CONNECT_RETRY_COUNT); int connectRetryInterval = extractInt(profile, KEY_CONNECT_RETRY_INTERVAL, 1, DEFAULT_CONNECT_RETRY_INTERVAL); String truncateStatement = extract(profile, KEY_TRUNCATE_STATEMENT, false); if (truncateStatement == null) { truncateStatement = DEFAULT_TRUNCATE_STATEMENT; } Set<String> optimizations = extractSet(profile, KEY_OPTIMIZATIONS); try { MessageFormat.format(truncateStatement, "dummy"); } catch (IllegalArgumentException e) { WGLOG.error("E00001", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement); throw new IllegalArgumentException(MessageFormat.format( "The \"{1}\" must be a valid MessageFormat: {2} (resource={0})", profile.getName(), KEY_TRUNCATE_STATEMENT, truncateStatement), e); } result.setBatchGetUnit(batchGetUnit); result.setBatchPutUnit(batchPutUnit); result.setConnectRetryCount(connectRetryCount); result.setConnectRetryInterval(connectRetryInterval); result.setTruncateStatement(truncateStatement); result.setOptimizations(optimizations); return result; } JdbcProfile(
            String resourceName,
            ClassLoader classLoader,
            String driver,
            String url,
            String user,
            String password,
            long batchPutUnit);  JdbcProfile(
            String resourceName,
            ClassLoader classLoader,
            String driver,
            String url,
            String user,
            String password,
            Map<String, String> connectionProperties); static JdbcProfile convert(ResourceProfile profile); String getResourceName(); ClassLoader getClassLoader(); Connection openConnection(); Map<String, String> getConnectionProperties(); int getBatchGetUnit(); void setBatchGetUnit(int value); long getBatchPutUnit(); void setBatchPutUnit(long value); int getConnectRetryCount(); void setConnectRetryCount(int value); int getConnectRetryInterval(); void setConnectRetryInterval(int value); String getTruncateStatement(String tableName); void setTruncateStatement(String pattern); Set<String> getOptimizations(); void setOptimizations(Collection<String> optimizations); static final String KEY_DRIVER; static final String KEY_URL; static final String KEY_USER; static final String KEY_PASSWORD; static final String KEY_BATCH_PUT_UNIT; static final String KEY_BATCH_GET_UNIT; static final String KEY_CONNECT_RETRY_COUNT; static final String KEY_CONNECT_RETRY_INTERVAL; static final String KEY_TRUNCATE_STATEMENT; static final String KEY_PREFIX_PROPERTIES; static final String KEY_OPTIMIZATIONS; static final int DEFAULT_BATCH_GET_UNIT; static final long DEFAULT_BATCH_PUT_UNIT; static final int DEFAULT_CONNECT_RETRY_COUNT; static final int DEFAULT_CONNECT_RETRY_INTERVAL; static final String DEFAULT_TRUNCATE_STATEMENT; }