Search in sources :

Example 31 with DataSource

use of javax.sql.DataSource in project eweb4j-framework by laiweiwei.

the class DAOFactory method getDivPageDAO.

/**
	 * 创建DivPageDAOImpl实例
	 * 
	 * @param dsName
	 *            数据库配置信息Bean的名字,默认下在eweb4j-dbInfo-config.xml文件中<name></name>
	 *            找到这个值
	 * @return
	 */
public static DivPageDAO getDivPageDAO(String dsName) {
    DataSource ds = DataSourceWrapCache.get(dsName);
    DBInfoConfigBean dcb = DBInfoConfigBeanCache.get(dsName);
    return new DivPageDAOImpl(ds, dcb.getDataBaseType());
}
Also used : DivPageDAOImpl(org.eweb4j.orm.dao.select.DivPageDAOImpl) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) DataSource(javax.sql.DataSource)

Example 32 with DataSource

use of javax.sql.DataSource in project eweb4j-framework by laiweiwei.

the class DAOFactory method getInsertDAO.

public static InsertDAO getInsertDAO() {
    DataSource ds = DataSourceWrapCache.get();
    DBInfoConfigBean dcb = DBInfoConfigBeanCache.get();
    return new InsertDAOImpl(ds, dcb.getDataBaseType());
}
Also used : InsertDAOImpl(org.eweb4j.orm.dao.insert.InsertDAOImpl) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) DataSource(javax.sql.DataSource)

Example 33 with DataSource

use of javax.sql.DataSource in project eweb4j-framework by laiweiwei.

the class DAOImpl method execute.

public Number execute() {
    Number rs = 0;
    String sql = this.sql.toString().replace("${_where_}", this.condition.toString()).replace("'?'", "?");
    DataSource ds = DataSourceWrapCache.get(dsName);
    try {
        if (args != null && args.size() > 0) {
            rs = JdbcUtil.updateWithArgs(ds.getConnection(), sql, args.toArray(new Object[] {}));
        } else {
            rs = JdbcUtil.update(ds.getConnection(), sql);
        }
    } catch (SQLException e) {
        log.error("sql-->" + sql, e);
        throw new DAOException(sql + " execute exception", e);
    }
    //this.clear();
    return rs;
}
Also used : SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource)

Example 34 with DataSource

use of javax.sql.DataSource in project head by mifos.

the class ApplicationInitializer method initJNDIforPentaho.

private void initJNDIforPentaho(ApplicationContext applicationContext) {
    try {
        InitialContext ic = new InitialContext();
        //check if ds is already bound
        boolean dataSourceBound = true;
        boolean dataSourceBoundDw = true;
        try {
            DataSource datasource = (DataSource) ic.lookup("jdbc/SourceDB");
            if (datasource != null) {
                dataSourceBound = true;
            }
        } catch (Exception ex) {
            dataSourceBound = false;
        }
        try {
            DataSource datasourcedw = (DataSource) ic.lookup("jdbc/DestinationDB");
            if (datasourcedw != null) {
                dataSourceBoundDw = true;
            }
        } catch (Exception ex) {
            dataSourceBoundDw = false;
        }
        if (!dataSourceBound) {
            Object dataSource = applicationContext.getBean("dataSource");
            try {
                ic.createSubcontext("jdbc");
            } catch (NameAlreadyBoundException ex) {
                logger.info("Subcontext jdbc was already bound");
            }
            ic.bind("jdbc/SourceDB", dataSource);
            logger.info("Bound datasource to jdbc/SourceDB");
        } else {
            logger.info("jdbc/SourceDB is already bound");
        }
        if (!dataSourceBoundDw) {
            Object dataSourcedw = applicationContext.getBean("dataSourcePentahoDW");
            try {
                ic.createSubcontext("jdbc");
            } catch (NameAlreadyBoundException ex) {
                logger.info("Subcontext jdbc was already bound");
            }
            ic.bind("jdbc/DestinationDB", dataSourcedw);
            logger.info("Bound datasource to jdbc/DestinationDB");
        } else {
            logger.info("jdbc/DestinationDB is already bound");
        }
    } catch (Exception ex) {
        logger.error("Unable to bind dataSource to JNDI");
    }
}
Also used : NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) InitialContext(javax.naming.InitialContext) SystemException(org.mifos.framework.exceptions.SystemException) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) XMLReaderException(org.mifos.framework.exceptions.XMLReaderException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) AppNotConfiguredException(org.mifos.framework.exceptions.AppNotConfiguredException) AccountException(org.mifos.accounts.exceptions.AccountException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) HibernateStartUpException(org.mifos.framework.exceptions.HibernateStartUpException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) DataSource(javax.sql.DataSource)

Example 35 with DataSource

use of javax.sql.DataSource in project databus by linkedin.

the class OracleEventProducerFactory method buildEventProducer.

public EventProducer buildEventProducer(PhysicalSourceStaticConfig physicalSourceConfig, SchemaRegistryService schemaRegistryService, DbusEventBufferAppendable dbusEventBuffer, MBeanServer mbeanServer, DbusEventsStatisticsCollector dbusEventsStatisticsCollector, MaxSCNReaderWriter _maxScnReaderWriter) throws DatabusException, EventCreationException, UnsupportedKeyException, SQLException, InvalidConfigException {
    // Make sure the URI from the configuration file identifies an Oracle JDBC source.
    String uri = physicalSourceConfig.getUri();
    if (!uri.startsWith("jdbc:oracle")) {
        throw new InvalidConfigException("Invalid source URI (" + physicalSourceConfig.getUri() + "). Only jdbc:oracle: URIs are supported.");
    }
    // Parse each one of the logical sources
    List<OracleTriggerMonitoredSourceInfo> sources = new ArrayList<OracleTriggerMonitoredSourceInfo>();
    for (LogicalSourceStaticConfig sourceConfig : physicalSourceConfig.getSources()) {
        OracleTriggerMonitoredSourceInfo source = buildOracleMonitoredSourceInfo(sourceConfig, physicalSourceConfig, schemaRegistryService);
        sources.add(source);
    }
    DataSource ds = null;
    try {
        ds = OracleJarUtils.createOracleDataSource(uri);
    } catch (Exception e) {
        String errMsg = "Oracle URI likely not supported. Trouble creating OracleDataSource";
        _log.error(errMsg);
        throw new InvalidConfigException(errMsg + e.getMessage());
    }
    // Create the event producer
    EventProducer eventProducer = new OracleEventProducer(sources, ds, dbusEventBuffer, true, dbusEventsStatisticsCollector, _maxScnReaderWriter, physicalSourceConfig, ManagementFactory.getPlatformMBeanServer());
    _log.info("Created OracleEventProducer for config:  " + physicalSourceConfig + " with slowSourceQueryThreshold = " + physicalSourceConfig.getSlowSourceQueryThreshold());
    return eventProducer;
}
Also used : ArrayList(java.util.ArrayList) OracleEventProducer(com.linkedin.databus2.producers.db.OracleEventProducer) EventProducer(com.linkedin.databus2.producers.EventProducer) OracleEventProducer(com.linkedin.databus2.producers.db.OracleEventProducer) LogicalSourceStaticConfig(com.linkedin.databus2.relay.config.LogicalSourceStaticConfig) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) UnsupportedKeyException(com.linkedin.databus.core.UnsupportedKeyException) SQLException(java.sql.SQLException) NoSuchSchemaException(com.linkedin.databus2.schemas.NoSuchSchemaException) EventCreationException(com.linkedin.databus2.producers.EventCreationException) DatabusException(com.linkedin.databus2.core.DatabusException) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) OracleTriggerMonitoredSourceInfo(com.linkedin.databus2.producers.db.OracleTriggerMonitoredSourceInfo) DataSource(javax.sql.DataSource)

Aggregations

DataSource (javax.sql.DataSource)546 Connection (java.sql.Connection)200 Test (org.junit.Test)192 SQLException (java.sql.SQLException)118 Context (javax.naming.Context)70 ResultSet (java.sql.ResultSet)59 Statement (java.sql.Statement)59 NamingException (javax.naming.NamingException)57 InitialContext (javax.naming.InitialContext)55 EJBException (javax.ejb.EJBException)40 HashMap (java.util.HashMap)38 PreparedStatement (java.sql.PreparedStatement)37 Properties (java.util.Properties)35 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)34 RemoteException (java.rmi.RemoteException)32 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)31 UserTransaction (javax.transaction.UserTransaction)30 IOException (java.io.IOException)29 ArrayList (java.util.ArrayList)26 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)21