/** * Adds a DataSourceDefinition from the given properties. * * @param props the properties (key and values must be strings) * @throws ConfigurationException on error */ public void addDataSourceDefinition(String name, Properties props) throws ConfigurationException { DataSourceDefinition def = new DataSourceDefinition(name, props); for (DataSourceDefinition existing : defs) { if (existing.getLogicalName().equals(def.getLogicalName())) { throw new ConfigurationException("Duplicate logicalName for a DataSource: " + def.getLogicalName()); } } defs.add(def); }
if (isJndiConfig()) { for (Object propName : props.keySet()) { if (!allJndiPropNames.contains((String) propName)) {
if (isJndiConfig()) { for (Object propName : props.keySet()) { if (!allJndiPropNames.contains((String) propName)) {
if (isJndiConfig()) { for (Object propName : props.keySet()) { if (!allJndiPropNames.contains((String) propName)) {
/** * Registers a number of data sources. * * @param dsc the {@link DataSourceConfig} which contains the configuration */ public void registerDataSources(DataSourceConfig dsc) throws RepositoryException { synchronized (lock) { sanityCheck(); for (DataSourceDefinition def : dsc.getDefinitions()) { Class<?> driverClass = getDriverClass(def.getDriver()); if (driverClass != null && Context.class.isAssignableFrom(driverClass)) { DataSource ds = getJndiDataSource((Class<Context>) driverClass, def.getUrl()); nameToDataSource.put(def.getLogicalName(), ds); nameToDataSourceDef.put(def.getLogicalName(), def); } else { BasicDataSource bds = getDriverDataSource(driverClass, def.getUrl(), def.getUser(), def.getPassword()); if (def.getMaxPoolSize() > 0) { bds.setMaxActive(def.getMaxPoolSize()); } if (def.getValidationQuery() != null && !"".equals(def.getValidationQuery().trim())) { bds.setValidationQuery(def.getValidationQuery()); } nameToDataSource.put(def.getLogicalName(), bds); nameToDataSourceDef.put(def.getLogicalName(), def); } } } }
/** * Registers a number of data sources. * * @param dsc the {@link DataSourceConfig} which contains the configuration */ public void registerDataSources(DataSourceConfig dsc) throws RepositoryException { synchronized (lock) { sanityCheck(); for (DataSourceDefinition def : dsc.getDefinitions()) { Class<?> driverClass = getDriverClass(def.getDriver()); if (driverClass != null && Context.class.isAssignableFrom(driverClass)) { DataSource ds = getJndiDataSource((Class<Context>) driverClass, def.getUrl()); nameToDataSource.put(def.getLogicalName(), ds); nameToDataSourceDef.put(def.getLogicalName(), def); } else { BasicDataSource bds = getDriverDataSource(driverClass, def.getUrl(), def.getUser(), def.getPassword()); if (def.getMaxPoolSize() > 0) { bds.setMaxActive(def.getMaxPoolSize()); } if (def.getValidationQuery() != null && !"".equals(def.getValidationQuery().trim())) { bds.setValidationQuery(def.getValidationQuery()); } nameToDataSource.put(def.getLogicalName(), bds); nameToDataSourceDef.put(def.getLogicalName(), def); } } } }
/** * Registers a number of data sources. * * @param dsc the {@link DataSourceConfig} which contains the configuration */ public void registerDataSources(DataSourceConfig dsc) throws RepositoryException { synchronized (lock) { sanityCheck(); for (DataSourceDefinition def : dsc.getDefinitions()) { Class<?> driverClass = getDriverClass(def.getDriver()); if (driverClass != null && Context.class.isAssignableFrom(driverClass)) { DataSource ds = getJndiDataSource((Class<Context>) driverClass, def.getUrl()); nameToDataSource.put(def.getLogicalName(), ds); nameToDataSourceDef.put(def.getLogicalName(), def); } else { BasicDataSource bds = getDriverDataSource(driverClass, def.getUrl(), def.getUser(), def.getPassword()); if (def.getMaxPoolSize() > 0) { bds.setMaxActive(def.getMaxPoolSize()); } if (def.getValidationQuery() != null && !"".equals(def.getValidationQuery().trim())) { bds.setValidationQuery(def.getValidationQuery()); } nameToDataSource.put(def.getLogicalName(), bds); nameToDataSourceDef.put(def.getLogicalName(), def); } } } }
/** * @param logicalName the name of the {@code DataSource} * @return the configured database type * @throws RepositoryException if there is no {@code DataSource} with the given name */ public String getDataBaseType(String logicalName) throws RepositoryException { synchronized (lock) { sanityCheck(); DataSourceDefinition def = nameToDataSourceDef.get(logicalName); if (def == null) { throw new RepositoryException("DataSource with logicalName " + logicalName + " has not been configured"); } return def.getDbType(); } }
/** * @param logicalName the name of the {@code DataSource} * @return the configured database type * @throws RepositoryException if there is no {@code DataSource} with the given name */ public String getDataBaseType(String logicalName) throws RepositoryException { synchronized (lock) { sanityCheck(); DataSourceDefinition def = nameToDataSourceDef.get(logicalName); if (def == null) { throw new RepositoryException("DataSource with logicalName " + logicalName + " has not been configured"); } return def.getDbType(); } }
/** * Adds a DataSourceDefinition from the given properties. * * @param props the properties (key and values must be strings) * @throws ConfigurationException on error */ public void addDataSourceDefinition(String name, Properties props) throws ConfigurationException { DataSourceDefinition def = new DataSourceDefinition(name, props); for (DataSourceDefinition existing : defs) { if (existing.getLogicalName().equals(def.getLogicalName())) { throw new ConfigurationException("Duplicate logicalName for a DataSource: " + def.getLogicalName()); } } defs.add(def); }
/** * Adds a DataSourceDefinition from the given properties. * * @param props the properties (key and values must be strings) * @throws ConfigurationException on error */ public void addDataSourceDefinition(String name, Properties props) throws ConfigurationException { DataSourceDefinition def = new DataSourceDefinition(name, props); for (DataSourceDefinition existing : defs) { if (existing.getLogicalName().equals(def.getLogicalName())) { throw new ConfigurationException("Duplicate logicalName for a DataSource: " + def.getLogicalName()); } } defs.add(def); }
/** * @param logicalName the name of the {@code DataSource} * @return the configured database type * @throws RepositoryException if there is no {@code DataSource} with the given name */ public String getDataBaseType(String logicalName) throws RepositoryException { synchronized (lock) { sanityCheck(); DataSourceDefinition def = nameToDataSourceDef.get(logicalName); if (def == null) { throw new RepositoryException("DataSource with logicalName " + logicalName + " has not been configured"); } return def.getDbType(); } }
public void testMinimalRegularConfig() throws ConfigurationException { cfg.addDataSourceDefinition("ds", minimalProps); DataSourceDefinition def = cfg.getDefinitions().get(0); assertEquals("ds", def.getLogicalName()); assertEquals("org.apache.derby.jdbc.EmbeddedDriver", def.getDriver()); assertEquals("url", def.getUrl()); assertEquals("dbType", def.getDbType()); // check default values: assertNull(def.getUser()); assertNull(def.getPassword()); assertNull(def.getValidationQuery()); assertEquals(-1, def.getMaxPoolSize()); // unlimited }