コード例 #1
0
 @Bean
 public JndiObjectFactoryBean dataSource() {
   // Production profile not used in this app, but demonstration how production datasource lookup
   // could be
   JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
   jndiObjectFactoryBean.setJndiName("jdbc/myOracleDb");
   return jndiObjectFactoryBean;
 }
コード例 #2
0
 @Bean(name = "datasource")
 public JndiObjectFactoryBean dataSource() {
   JndiObjectFactoryBean jndiObjectFB = new JndiObjectFactoryBean();
   jndiObjectFB.setJndiName(jndiName);
   jndiObjectFB.setResourceRef(true);
   jndiObjectFB.setProxyInterface(javax.sql.DataSource.class);
   return jndiObjectFB;
 }
コード例 #3
0
  public static IDatabasePlatform createDatabasePlatform(
      ApplicationContext springContext,
      TypedProperties properties,
      DataSource dataSource,
      boolean waitOnAvailableDatabase) {
    if (dataSource == null) {
      String jndiName = properties.getProperty(ParameterConstants.DB_JNDI_NAME);
      if (StringUtils.isNotBlank(jndiName)) {
        try {
          log.info("Looking up datasource in jndi.  The jndi name is {}", jndiName);
          JndiObjectFactoryBean jndiFactory = new JndiObjectFactoryBean();
          jndiFactory.setJndiName(jndiName);
          jndiFactory.afterPropertiesSet();
          dataSource = (DataSource) jndiFactory.getObject();

          if (dataSource == null) {
            throw new SymmetricException(
                "Could not locate the configured datasource in jndi.  The jndi name is %s",
                jndiName);
          }
        } catch (IllegalArgumentException e) {
          throw new SymmetricException(
              "Could not locate the configured datasource in jndi.  The jndi name is %s",
              e, jndiName);
        } catch (NamingException e) {
          throw new SymmetricException(
              "Could not locate the configured datasource in jndi.  The jndi name is %s",
              e, jndiName);
        }
      }

      String springBeanName = properties.getProperty(ParameterConstants.DB_SPRING_BEAN_NAME);
      if (isNotBlank(springBeanName) && springContext != null) {
        log.info("Using datasource from spring.  The spring bean name is {}", springBeanName);
        dataSource = (DataSource) springContext.getBean(springBeanName);
      }

      if (dataSource == null) {
        dataSource =
            BasicDataSourceFactory.create(
                properties, SecurityServiceFactory.create(SecurityServiceType.CLIENT, properties));
      }
    }
    if (waitOnAvailableDatabase) {
      waitForAvailableDatabase(dataSource);
    }
    boolean delimitedIdentifierMode =
        properties.is(ParameterConstants.DB_DELIMITED_IDENTIFIER_MODE, true);
    boolean caseSensitive = !properties.is(ParameterConstants.DB_METADATA_IGNORE_CASE, true);
    return JdbcDatabasePlatformFactory.createNewPlatformInstance(
        dataSource, createSqlTemplateSettings(properties), delimitedIdentifierMode, caseSensitive);
  }