@Override protected void initializeComponents() { super.initializeComponents(); JDBCSecurityServiceConfig config = (JDBCSecurityServiceConfig) configHelper.getConfig(); if (config.isJndi()) { comp = new JDBCConnectFormComponent( "jdbcConnectFormComponent", Mode.DYNAMIC, config.getJndiName()); } else { comp = new JDBCConnectFormComponent( "jdbcConnectFormComponent", Mode.DYNAMIC, config.getDriverClassName(), config.getConnectURL(), config.getUserName(), config.getPassword()); } addOrReplace(comp); add(creatingTablesComponent = new CheckBox("config.creatingTables")); propertyFileNameDDLComponent = new TextField<String>("config.propertyFileNameDDL"); add(propertyFileNameDDLComponent); propertyFileNameDMLComponent = new TextField<String>("config.propertyFileNameDML"); add(propertyFileNameDMLComponent); };
/** * initialize a {@link DataSource} form a {@link JdbcSecurityServiceConfig} object * * @param config * @throws IOException */ public void initializeDSFromConfig(SecurityNamedServiceConfig namedConfig) throws IOException { JDBCSecurityServiceConfig config = (JDBCSecurityServiceConfig) namedConfig; if (config.isJndi()) { String jndiName = config.getJndiName(); try { Context initialContext = new InitialContext(); datasource = (DataSource) initialContext.lookup(jndiName); } catch (NamingException e) { throw new IOException(e); } } else { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(config.getDriverClassName()); bds.setUrl(config.getConnectURL()); bds.setUsername(config.getUserName()); bds.setPassword(config.getPassword()); bds.setDefaultAutoCommit(false); bds.setDefaultTransactionIsolation(DEFAULT_ISOLATION_LEVEL); bds.setMaxActive(10); datasource = bds; } }