@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; } }
public void createTablesIfRequired(JDBCSecurityServiceConfig config) throws IOException { if (this.canCreateStore() == false) return; if (config.isCreatingTables() == false) return; if (tablesAlreadyCreated()) return; Connection con = null; PreparedStatement ps = null; try { con = datasource.getConnection(); if (con.getAutoCommit() == true) con.setAutoCommit(false); con = getConnection(); for (String stmt : getOrderedNamesForCreate()) { ps = getDDLStatement(stmt, con); ps.execute(); ps.close(); } con.commit(); } catch (SQLException ex) { throw new IOException(ex); } finally { closeFinally(con, ps, null); } }
@Override public void updateModel() { super.updateModel(); comp.updateModel(); creatingTablesComponent.updateModel(); propertyFileNameDDLComponent.updateModel(); propertyFileNameDMLComponent.updateModel(); JDBCSecurityServiceConfig config = (JDBCSecurityServiceConfig) configHelper.getConfig(); JDBCConnectConfig c = comp.getModelObject(); config.setJndiName(null); config.setDriverClassName(null); config.setConnectURL(null); config.setUserName(null); config.setPassword(null); config.setJndi(c.getType().equals(JDBCConnectConfig.TYPEJNDI)); if (config.isJndi()) { config.setJndiName(c.getJndiName()); } else { config.setDriverClassName(c.getDriverName()); config.setConnectURL(c.getConnectURL()); config.setUserName(c.getUsername()); config.setPassword(c.getPassword()); } }