/** * Converts {@link ResourceProfile} into {@link JdbcProfile}. * * @param profile target profile * @return the converted profile * @throws IllegalArgumentException if profile is not valid, or any parameter is {@code null} */ public static JdbcProfile convert(ResourceProfile profile) { if (profile == null) { throw new IllegalArgumentException("profile must not be null"); // $NON-NLS-1$ } String resourceName = profile.getName(); ClassLoader classLoader = profile.getContext().getClassLoader(); String driver = extract(profile, KEY_DRIVER); String url = extract(profile, KEY_URL); String user = extract(profile, KEY_USER, null); String password = extract(profile, KEY_PASSWORD, null); Map<String, String> connectionProperties = PropertiesUtil.createPrefixMap(profile.getConfiguration(), KEY_PREFIX_PROPERTIES); 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, DEFAULT_TRUNCATE_STATEMENT); 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); return result; }