desc.setName(defn.name()); desc.setClassName(defn.className()); if (defn.description() != null && !defn.description().equals("")) { desc.setDescription(defn.description()); if (defn.serverName() != null && !defn.serverName().equals("localhost")) { desc.setServerName(defn.serverName()); if (defn.portNumber() != -1) { desc.setPortNumber(defn.portNumber()); if (defn.databaseName() != null && !defn.databaseName().equals("")) { desc.setDatabaseName(defn.databaseName()); if (defn.url() != null && !defn.url().equals("")) { desc.setUrl(defn.url()); if (defn.user() != null && !defn.user().equals("")) { desc.setUser(defn.user()); if (defn.password() != null /*ALLOW EMPTY PASSWORDS && !defn.password().equals("")*/) { desc.setPassword(defn.password()); if (defn.isolationLevel() != -1) { desc.setIsolationLevel(String.valueOf(defn.isolationLevel())); if (defn.transactional()) { desc.setTransactional(true);
private void setDataSourcePropertiesFromConfiguredValues(@Nonnull DataSourceDefinition dsDef) { try { BeanInfo beanInfo = Introspector.getBeanInfo(dsClass, Object.class); PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors(); setProperty(properties, "url", dsDef.url()); setProperty(properties, "user", dsDef.user()); setProperty(properties, "password", dsDef.password()); } catch (IntrospectionException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }
private DataSource createDelegate(DataSourceDefinition dataSourceDefinition) { HikariConfig config = new HikariConfig(); if (dataSourceDefinition.url() != null) { config.setJdbcUrl(dataSourceDefinition.url()); } if (dataSourceDefinition.user() != null) { config.setUsername(dataSourceDefinition.user()); config.setPassword(dataSourceDefinition.password()); } if (dataSourceDefinition.maxPoolSize() > 0) { config.setMaximumPoolSize(dataSourceDefinition.maxPoolSize()); } config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); return wrap(new HikariDataSource(config)); }
String name = def.name(); String className = def.className(); factory.setDriverClass(driverClass); if (! "".equals(def.url())) factory.setUrl(def.url()); if (! "".equals(def.databaseName())) factory.setDatabaseName(def.databaseName()); if (! "".equals(def.user())) factory.setUser(def.user()); if (! "".equals(def.password())) factory.setPassword(def.password());
public HammockDataSource(DataSourceDefinition dataSourceDefinition) { this.name = dataSourceDefinition.name(); this.delegate = createDelegate(dataSourceDefinition); }
private void instantiateConfiguredDataSourceClass(@Nonnull DataSourceDefinition dsDef) { String className = dsDef.className(); try { //noinspection unchecked dsClass = (Class<? extends CommonDataSource>) Class.forName(className); //noinspection ClassNewInstance ds = dsClass.newInstance(); } catch (ClassNotFoundException | IllegalAccessException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e.getCause()); } }
private void introspectClass(String location, DataSourceDefinition def) { String name = def.name(); ValueGenerator gen = bindGenerator(location, def); if (name != null && ! "".equals(name)) { bindJndi(name, gen, name); } }
dataSource.setName(d.name()); dataSource.setClassName(d.className()); dataSource.setTransactional(d.transactional()); if (!d.databaseName().isEmpty()) { dataSource.setDatabaseName(d.databaseName()); if (d.initialPoolSize() != -1) { dataSource.setInitialPoolSize(d.initialPoolSize()); if (d.isolationLevel() != -1) { dataSource.setIsolationLevel(IsolationLevel.fromFlag(d.isolationLevel())); if (d.loginTimeout() != 0) { dataSource.setLoginTimeout(d.loginTimeout()); if (d.maxIdleTime() != -1) { dataSource.setMaxIdleTime(d.maxIdleTime()); if (d.maxPoolSize() != -1) { dataSource.setMaxPoolSize(d.maxPoolSize()); if (d.maxStatements() != -1) { dataSource.setMaxStatements(d.maxStatements()); if (d.minPoolSize() != -1) { dataSource.setMinPoolSize(d.minPoolSize()); if (!d.password().isEmpty()) {
private void createDataSource(@Nonnull DataSourceDefinition dsDef) { String configuredDataSourceName = InjectionPoint.getNameFromJNDILookup(dsDef.name()); if (configuredDataSourceName.equals(dsName)) { instantiateConfiguredDataSourceClass(dsDef); setDataSourcePropertiesFromConfiguredValues(dsDef); } }
dataSource.setName(d.name()); dataSource.setClassName(d.className()); dataSource.setTransactional(d.transactional()); if (!d.databaseName().isEmpty()) { dataSource.setDatabaseName(d.databaseName()); if (d.initialPoolSize() != -1) { dataSource.setInitialPoolSize(d.initialPoolSize()); if (d.isolationLevel() != -1) { dataSource.setIsolationLevel(IsolationLevel.fromFlag(d.isolationLevel())); if (d.loginTimeout() != 0) { dataSource.setLoginTimeout(d.loginTimeout()); if (d.maxIdleTime() != -1) { dataSource.setMaxIdleTime(d.maxIdleTime()); if (d.maxPoolSize() != -1) { dataSource.setMaxPoolSize(d.maxPoolSize()); if (d.maxStatements() != -1) { dataSource.setMaxStatements(d.maxStatements()); if (d.minPoolSize() != -1) { dataSource.setMinPoolSize(d.minPoolSize()); if (!d.password().isEmpty()) {
private DataSource findDataSource(DataSourceDefinition dsDefinition, JndiConsumer annotatedApp) { String dsDefinitionName = getJndiName(dsDefinition.name().trim()); Collection<DataSource> dataSources = annotatedApp.getDataSource(); for (DataSource ds : dataSources) { String dsName = getJndiName(ds.getName().trim()); if (dsDefinitionName.equals(dsName)) { return ds; } } return null; }
if (!existing) { dataSource = new DataSource(); dataSource.setName(dsDefinition.name()); dataSource.setClassName(dsDefinition.className()); if (dataSource.getDescription() == null && dsDefinition.description().trim().length() > 0) { dataSource.setDescriptions(new Text[]{new Text(null, dsDefinition.description().trim())}); if (dataSource.getUser() == null && dsDefinition.user().trim().length() > 0) { dataSource.setUser(dsDefinition.user().trim()); if (dataSource.getPassword() == null && dsDefinition.password().trim().length() > 0) { dataSource.setPassword(dsDefinition.password().trim()); if (dataSource.getDatabaseName() == null && dsDefinition.databaseName().trim().length() > 0) { dataSource.setDatabaseName(dsDefinition.databaseName().trim()); if (dataSource.getPortNumber() == null && dsDefinition.portNumber() != -1) { dataSource.setPortNumber(dsDefinition.portNumber()); if (dataSource.getServerName() == null && dsDefinition.serverName().trim().length() > 0) { dataSource.setServerName(dsDefinition.serverName().trim()); if (dataSource.getUrl() == null && dsDefinition.url().trim().length() > 0) { dataSource.setUrl(dsDefinition.url().trim()); if (dataSource.getInitialPoolSize() == null && dsDefinition.initialPoolSize() != -1) { dataSource.setInitialPoolSize(dsDefinition.initialPoolSize());
public void registerDataSources(@Observes AfterBeanDiscovery afterBeanDiscovery) { DataSourceDefinition defaultDataSource = dataSourceDefinitions.stream() .filter(dsd -> dsd.name().equals(EntityManagerFactoryProvider.DEFAULT_EMF)) .findFirst() .orElse(null); Bean<ws.ament.hammock.jpa.DataSourceDefinition> defaultBean = beanDelegates .stream() .filter(b -> b.getName().equals(EntityManagerFactoryProvider.DEFAULT_EMF)) .findFirst() .orElse(null); dataSourceDefinitions.stream().map(dataSourceDefinitionDataSourceDefinitionFunction) .map(dataSourceDefinition -> new DataSourceDelegateBean(dataSourceDefinition.getName(), () -> dataSourceDefinition)) .forEach(afterBeanDiscovery::addBean); beanDelegates.stream().map(bean -> new DataSourceDelegateBean(bean.getName(), () -> bean.create(null))) .forEach(afterBeanDiscovery::addBean); databaseProducers.stream().map(producer -> new DataSourceDelegateBean(producer, create(producer))) .forEach(afterBeanDiscovery::addBean); if (defaultBean == null && defaultDataSource == null) { afterBeanDiscovery.addBean(new DefaultDataSourceBean()); } }
if (desc.getName().equals(defn.name())) { desc.setClassName(defn.className()); if (defn.description() != null && !defn.description().equals("")) { desc.setDescription(defn.description()); if (defn.serverName() != null && !defn.serverName().equals("localhost")) { desc.setServerName(defn.serverName()); if (defn.portNumber() != -1) { desc.setPortNumber(defn.portNumber()); if (defn.databaseName() != null && !defn.databaseName().equals("")) { desc.setDatabaseName(defn.databaseName()); !(desc.getPortNumber() != -1 && desc.getServerName() != null && (desc.getDatabaseName() != null))) { if (defn.url() != null && !defn.url().equals("")) { desc.setUrl(defn.url()); if (defn.user() != null && !defn.user().equals("")) { desc.setUser(defn.user()); if (defn.password() != null /*ALLOW EMPTY PASSWORDS && !defn.password().equals("")*/) { desc.setPassword(defn.password()); if (defn.isolationLevel() != -1) { desc.setIsolationLevel(String.valueOf(defn.isolationLevel()));
private ConfigProgram generateProgram(AnnotatedField<?> field, DataSourceDefinition def) throws ConfigException { String name = def.name(); Field javaField = field.getJavaMember(); String location = getLocation(javaField); Class<?> bindType = javaField.getType(); ValueGenerator gen = bindGenerator(location, def); if (name != null && ! "".equals(name)) bindJndi(name, gen, name); bindJndi(javaField, gen); return new FieldGeneratorProgram(javaField, gen); }
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts) throws AnnotationProcessorException { DataSourceDefinitions defns = (DataSourceDefinitions) ainfo.getAnnotation(); DataSourceDefinition values[] = defns.value(); Set duplicates = new HashSet(); if(values != null && values.length >0){ for(DataSourceDefinition defn : values){ String defnName = DataSourceDefinitionDescriptor.getJavaName(defn.name()); if(duplicates.contains(defnName)){ String localString = localStrings.getLocalString( "enterprise.deployment.annotation.handlers.datasourcedefinitionsduplicates", "@DataSourceDefinitions cannot have multiple definitions with same name : '{0}'", defnName); throw new IllegalStateException(localString); /* //TODO V3 should we throw exception or return failure result ? return getFailureResult(ainfo, "@DataSourceDefinitions cannot have multiple" + " definitions with same name [ "+defnName+" ]", true ); */ }else{ duplicates.add(defnName); } DataSourceDefinitionHandler handler = new DataSourceDefinitionHandler(); handler.processAnnotation(defn, ainfo, rcContexts); } duplicates.clear(); } return getDefaultProcessedResult(); }
private ConfigProgram generateProgram(AnnotatedMethod<?> method, DataSourceDefinition def) throws ConfigException { String name = def.name(); Method javaMethod = method.getJavaMember(); String location = getLocation(javaMethod); ValueGenerator gen = bindGenerator(location, def); if (name != null && ! "".equals(name)) bindJndi(name, gen, name); bindJndi(javaMethod, gen); return new MethodGeneratorProgram(javaMethod, gen); }