class JDBCObjectStoreFactory implements ObjectStoreFactory {

    @Override
    public ObjectStore create(PrivateKeyStore keyStore) {
        final String jdbcStore = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RW_STORE);
        final String jdbcUser = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RW_USER);
        final String password = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RW_PASSWORD, "");
        final String jdbcAppName = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_APP_NAME, JDBC);
        String jdbcPassword = keyStore.getApplicationSecret(jdbcAppName, password);
        
        Properties readWriteProperties = new Properties();
        readWriteProperties.setProperty(ZMSConsts.DB_PROP_USER, jdbcUser);
        readWriteProperties.setProperty(ZMSConsts.DB_PROP_PASSWORD, jdbcPassword);
        readWriteProperties.setProperty(ZMSConsts.DB_PROP_VERIFY_SERVER_CERT,
                System.getProperty(ZMSConsts.ZMS_PROP_JDBC_VERIFY_SERVER_CERT, "false"));
        readWriteProperties.setProperty(ZMSConsts.DB_PROP_USE_SSL,
                System.getProperty(ZMSConsts.ZMS_PROP_JDBC_USE_SSL, "false"));
        readWriteProperties.setProperty(ZMSConsts.DB_PROP_TLS_PROTOCOLS,
                System.getProperty(ZMSConsts.ZMS_PROP_JDBC_TLS_VERSIONS, "TLSv1.2,TLSv1.3"));

        PoolableDataSource readWriteSrc = DataSourceFactory.create(jdbcStore, readWriteProperties);
        
        // now check to see if we also have a read-only jdbc store configured
        // if no username and password are specified then we'll use the
        // read-write store credentials
        
        PoolableDataSource readOnlySrc = null;
        String jdbcReadOnlyStore = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RO_STORE);
        if (jdbcReadOnlyStore != null && jdbcReadOnlyStore.startsWith("jdbc:")) {
            final String jdbcReadOnlyUser = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RO_USER, jdbcUser);
            final String readOnlyPassword = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RO_PASSWORD, password);
            final String jdbcReadOnlyPassword = keyStore.getApplicationSecret(jdbcAppName, readOnlyPassword);
            
            Properties readOnlyProperties = new Properties();
            readOnlyProperties.setProperty(ZMSConsts.DB_PROP_USER, jdbcReadOnlyUser);
            readOnlyProperties.setProperty(ZMSConsts.DB_PROP_PASSWORD, jdbcReadOnlyPassword);
            readOnlyProperties.setProperty(ZMSConsts.DB_PROP_VERIFY_SERVER_CERT,
                    System.getProperty(ZMSConsts.ZMS_PROP_JDBC_VERIFY_SERVER_CERT, "false"));
            readOnlyProperties.setProperty(ZMSConsts.DB_PROP_USE_SSL,
                    System.getProperty(ZMSConsts.ZMS_PROP_JDBC_USE_SSL, "false"));
            readOnlyProperties.setProperty(ZMSConsts.DB_PROP_TLS_PROTOCOLS,
                    System.getProperty(ZMSConsts.ZMS_PROP_JDBC_TLS_VERSIONS, "TLSv1.2,TLSv1.3"));
            readOnlySrc = DataSourceFactory.create(jdbcReadOnlyStore, readOnlyProperties);
        }
        
        return new JDBCObjectStore(readWriteSrc, readOnlySrc);
    }

}