Java Code Examples for oracle.jdbc.pool.OracleDataSource

The following are top voted examples for showing how to use oracle.jdbc.pool.OracleDataSource. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: midao   File: OracleParameters.java   Source Code and License 8 votes vote down vote up
public static Connection createConnection() throws SQLException {
    MjdbcUtils.loadDriver("oracle.jdbc.pool.OracleDataSource");

    OracleDataSource ds = new oracle.jdbc.pool.OracleDataSource();

    ds.setDriverType("thin");
    ds.setServerName("localhost");
    ds.setDatabaseName("xe");
    ds.setPortNumber(1521);
    ds.setUser("chris");
    ds.setPassword("welcome1");

    Connection conn = ds.getConnection();

    return conn;
}
 
Example 2
Project: Runway-SDK   File: Oracle.java   Source Code and License 7 votes vote down vote up
public void initialSetup(String rootUser, String rootPass, String rootDb)
{
  try
  {
    // Set up the root connection
    OracleDataSource oracleRootSource = new OracleDataSource();

    oracleRootSource.setServerName(DatabaseProperties.getServerName());
    oracleRootSource.setServiceName(rootDb);
    oracleRootSource.setPortNumber(DatabaseProperties.getPort());
    oracleRootSource.setDriverType("thin");
    oracleRootSource.setUser(rootUser);
    oracleRootSource.setPassword(rootPass);

    this.rootDataSource = oracleRootSource;
  }
  catch (SQLException e)
  {
    throwDatabaseException(e);
  }

  this.dropUser();

  this.createUser();
}
 
Example 3
Project: Patterdale   File: HikariDataSourceProvider.java   Source Code and License 6 votes vote down vote up
private static HikariDataSource dataSource(PatterdaleRuntimeParameters runtimeParameters, DatabaseDefinition databaseDefinition, Passwords passwords, Logger logger)
        throws SQLException {
    try {
        OracleDataSource oracleDataSource = new OracleDataSource();
        oracleDataSource.setUser(databaseDefinition.user);

        String password = passwords.byDatabaseName(databaseDefinition.name).value;
        oracleDataSource.setPassword(password);

        HikariDataSource hikariDataSource = new HikariDataSource(jdbcConfig(runtimeParameters, databaseDefinition, password));
        hikariDataSource.setDataSource(oracleDataSource);
        return hikariDataSource;
    } catch (Exception e) {
        logger.error("Error occurred initialising Oracle and Hikari data sources.", e);
        throw e;    // caught by the RetryPolicy
    }
}
 
Example 4
Project: gemfirexd-oss   File: DBUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a database connection pool object using JDBC 2.0.
 */
private OracleDataSource createConnectionPool() {
  try {
    // Create a OracleConnectionPoolDataSource instance.
    OracleDataSource ds = new OracleDataSource();
    ds.setConnectionCacheName("oraCache");
    ds.setConnectionCachingEnabled(true);
    ds.setURL(TestConfig.tab().stringAt(JtaPrms.jdbcUrl));
    ds.setUser(TestConfig.tab().stringAt(JtaPrms.rdbUser));
    ds.setPassword(TestConfig.tab().stringAt(JtaPrms.rdbPassword));

    Properties cacheProps = new Properties();
    cacheProps.setProperty("MinLimit",
        String.valueOf(TestConfig.tab().intAt(JtaPrms.poolMinLimit)));
    ds.setConnectionCacheProperties(cacheProps);
    return ds;
  } catch (Exception ex) {
    Log.getLogWriter().info("Unable to create connection pool: " + ex, ex);
    throw new HydraRuntimeException("Problem creating Oracle connection pool", ex);
  }
}
 
Example 5
Project: gemfirexd-oss   File: DBUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a database connection pool object using JDBC 2.0.
 */
private OracleDataSource createConnectionPool() {
  try {
    // Create a OracleConnectionPoolDataSource instance.
    OracleDataSource ds = new OracleDataSource();
    ds.setConnectionCacheName("oraCache");
    ds.setConnectionCachingEnabled(true);
    ds.setURL(TestConfig.tab().stringAt(JtaPrms.jdbcUrl));
    ds.setUser(TestConfig.tab().stringAt(JtaPrms.rdbUser));
    ds.setPassword(TestConfig.tab().stringAt(JtaPrms.rdbPassword));

    Properties cacheProps = new Properties();
    cacheProps.setProperty("MinLimit",
        String.valueOf(TestConfig.tab().intAt(JtaPrms.poolMinLimit)));
    ds.setConnectionCacheProperties(cacheProps);
    return ds;
  } catch (Exception ex) {
    Log.getLogWriter().info("Unable to create connection pool: " + ex, ex);
    throw new HydraRuntimeException("Problem creating Oracle connection pool", ex);
  }
}
 
Example 6
Project: plsql-from-java-maven-plugin   File: ObjectTypeGenerator.java   Source Code and License 6 votes vote down vote up
public void generate(Settings settings) {
    try {
        OracleDataSource oracleDataSource = new OracleDataSource();
        oracleDataSource.setURL(settings.getJdbcUrl());
        TypeCatalogDAO typeCatalogDAO = new TypeCatalogDAO(oracleDataSource);

        List<String> types = typeCatalogDAO.getTypeList();

        for (String typeName : types) {
            List<TypeAttribute> typeAttributes = typeCatalogDAO.getTypeAttributes(typeName);

            String className = StringHelper.toCamelCase(typeName);
            VelocityRenderer velocityRenderer = new VelocityRenderer("typepojo.vm");

            velocityRenderer.put("className", className);
            velocityRenderer.put("targetPackage", settings.getEntityPackageName());
            velocityRenderer.put("attrList", typeAttributes);

            FileUtils.writeStringToFile(new File(settings.getBasePath() + "/" + settings.getEntityPackageName().replace(".", "/") + "/" + className + ".java"), velocityRenderer.render());

        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 7
Project: PageServer   File: AccessManager.java   Source Code and License 6 votes vote down vote up
public AccessManager(ServletContext context, OracleDataSource ods) {
	
	// This is wasteful for the initial load, but prevents an unreachable database
	// Connection from storing a null reference instead of an empty HashMap
	permissionMap = new HashMap<String, accessLevel>();
	ipAccessList = new HashSet<InetAddress>();
	
	this.ods = ods;
	
	// The only IN Parameter is accessLevel 
	roleMappingSql = context.getInitParameter("roleMappingSQL");

	// IN Parameters are all (accessLevel, username)
	updateRoleSql = context.getInitParameter("updateRoleSQL");
	addUserSql = context.getInitParameter("addUserSQL");
	removeUserSql = context.getInitParameter("removeUserSQL");

	try {
		this.refresh();
		this.refreshAddressList();
	}catch (SQLException e){
		log.error(e);
	}
}
 
Example 8
Project: dbadvisor   File: AbstractIT.java   Source Code and License 5 votes vote down vote up
@Bean
PrivilegedDataSourceProvider privilegedBankDataSource() throws SQLException {
    OracleDataSource dataSource = new OracleDataSource();
    dataSource.setUser("system");
    dataSource.setPassword("oracle");
    dataSource.setURL("jdbc:oracle:thin:@//localhost:1521/XE");

    return DefaultPrivilegedDataSourceProvider.builder()
        .dataSourceName("dataSource")
        .privilegedDataSource(dataSource)
        .schemas(Arrays.asList("BANK"))
        .build();
}
 
Example 9
Project: SQL-dumper   File: OracleConnection.java   Source Code and License 5 votes vote down vote up
/**
 * Creates a connection to an oracle database
 * @param username A username, e.g. "DB_USER"
 * @param password A password, e.g. "rainbow123"
 * @param connectionString A connection string, e.g. "jdbc:oracle:thin:@sdwh.cooperation.net:1331:SDWH"
 * @param log Object for accessing the console
 * @return a Connection object
 * @throws SQLException
 */
public static Connection Create(String username, String password, String connectionString, Log log) throws SQLException {
    PingPong ping = log.info("connecting to database...");
    OracleDataSource ods = new OracleDataSource();
    ods.setUser(username);
    ods.setPassword(password);
    ods.setURL(connectionString);
    log.finished(ping);
    return ods.getConnection();
}
 
Example 10
Project: WQP-WQX-Services   File: TestSpringConfig.java   Source Code and License 5 votes vote down vote up
@Bean
public OracleDataSource dataSource() throws SQLException {
	OracleDataSource ds = new OracleDataSource();
	ds.setURL(WqpEnv.get("test.datasource.url"));
	ds.setUser(WqpEnv.get("test.datasource.username"));
	ds.setPassword(WqpEnv.get("test.datasource.password"));
	return ds;
}
 
Example 11
Project: WQP-WQX-Services   File: TestSpringConfig.java   Source Code and License 5 votes vote down vote up
@Bean
public OracleDataSource dbUnitDataSource() throws SQLException {
	OracleDataSource ds = new OracleDataSource();
	ds.setURL(WqpEnv.get("test.datasource.url"));
	ds.setUser(WqpEnv.get("test.dbunit.username"));
	ds.setPassword(WqpEnv.get("test.dbunit.password"));
	return ds;
}
 
Example 12
Project: WQP-WQX-Services   File: JndiUtilsTest.java   Source Code and License 5 votes vote down vote up
public Context getInitialContext(Hashtable<?, ?> arg0) throws NamingException {
	Context envContext = Mockito.mock(Context.class);
	try {
		Mockito.when(envContext.lookup(TEST_JNDI)).thenReturn(new OracleDataSource());
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	Context context = Mockito.mock(Context.class);
	Mockito.when(context.lookup(CTX_NAME)).thenReturn(envContext);
	return context;
}
 
Example 13
Project: mdb-oracle   File: ScriptRunner.java   Source Code and License 5 votes vote down vote up
public ScriptRunner(final String jdbcUrl, final String username, final String password) throws SQLException {
  OracleDataSource ds = new OracleDataSource();
  ds.setURL(jdbcUrl);
  ds.setUser(username);
  ds.setPassword(password);
  this.dataSource = ds;
}
 
Example 14
Project: dbexp   File: OracleConnectionCommand.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(ExecutionState state) throws CommandException {
    try {
        OracleDataSource dataSource = JdbcUtil.connectToOracle(this);
        Connection connection = dataSource.getConnection();
        
        SourceSql src = new OracleSource(connection, state.getDebug());
        state.setSourceSql(src);

    } catch (SQLException ex) {
        throw new CommandException("unable to connect to database", ex);
    }
}
 
Example 15
Project: HorusFramework   File: HorusOracleDriveConnection.java   Source Code and License 5 votes vote down vote up
private void StartConnection() {
	try {
		Locale.setDefault(new Locale(stringConnection.language(), stringConnection.country()));
		OracleDataSource ods = new OracleDataSource();
		ods.setURL("jdbc:oracle:thin:@" + stringConnection.host() + ":" + stringConnection.port() + ":" + stringConnection.database());
		ods.setUser(stringConnection.user());
		ods.setPassword(stringConnection.password());
		connection = ods.getConnection();
		connection.setAutoCommit(stringConnection.autoCommit());
	} catch (SQLException e) {
		System.out.println("Could not connect - StartConnection (). Let's try again!");
		e.printStackTrace();
		StartConnection();
	}
}
 
Example 16
Project: plsql-from-java-maven-plugin   File: ProcedureGenerator.java   Source Code and License 5 votes vote down vote up
public void generate(Settings settings) {
    try {
        OracleDataSource oracleDataSource = new OracleDataSource();
        oracleDataSource.setURL(settings.getJdbcUrl());

        ProcedureCatalogDAO procedureCatalogDAO = new ProcedureCatalogDAO(oracleDataSource);

        List<Procedure> allProcedures = procedureCatalogDAO.getAllProcedures("");

        for (Procedure p : allProcedures) {

            List<ProcedureArgument> procedureArguments = procedureCatalogDAO.getProcedureArguments(p.getObjectName(), p.getProcedureName(), p.getOverload());

            String className = StringHelper.toCamelCase(p.getObjectName() + "_" + p.getProcedureName() + "_" + p.getOverload());
            VelocityRenderer velocityRenderer = new VelocityRenderer("sppojo.vm");

            velocityRenderer.put("className", className);
            velocityRenderer.put("procedure", p);
            velocityRenderer.put("procedureName", p.getObjectName() + "." + p.getProcedureName());
            velocityRenderer.put("targetPackage", settings.getProcedurePackageName());
            velocityRenderer.put("par", procedureArguments);
            velocityRenderer.put("modelPackage", settings.getEntityPackageName());
            velocityRenderer.put("converterPackage", settings.getConverterPackageName());
            velocityRenderer.put("utilPackage", settings.getUtilPackageName());

            FileUtils.writeStringToFile(new File(settings.getBasePath() + "/" + settings.getProcedurePackageName().replace(".", "/") + "/" + className + ".java"), velocityRenderer.render());

        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 17
Project: plsql-from-java-maven-plugin   File: ServiceGenerator.java   Source Code and License 5 votes vote down vote up
public void generate(Settings settings) {
    try {
        OracleDataSource oracleDataSource = new OracleDataSource();
        oracleDataSource.setURL(settings.getJdbcUrl());

        List<String> servicePackages = new ServiceCatalogDAO(oracleDataSource).getServicePackages();

        for (String s : servicePackages) {

            List<Procedure> packageServiceProcedures = new ServiceCatalogDAO(oracleDataSource).getPackageServiceProcedures(s);

            VelocityRenderer velocityRenderer = new VelocityRenderer("serviceclass.vm");

            String className = StringHelper.toCamelCase(s);

            System.out.println(className);

            velocityRenderer.put("className", className);
            velocityRenderer.put("service", packageServiceProcedures);
            velocityRenderer.put("servicePackage", settings.getServicePackageName());
            velocityRenderer.put("modelPackage", settings.getEntityPackageName());
            velocityRenderer.put("utilPackage", settings.getUtilPackageName());
            velocityRenderer.put("procPackage", settings.getProcedurePackageName());
            FileUtils.writeStringToFile(new File(settings.getBasePath() + "/" + settings.getServicePackageName().replace(".", "/") + "/" + className + ".java"), velocityRenderer.render());

        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 18
Project: plsql-from-java-maven-plugin   File: ObjectTypeConverterGenerator.java   Source Code and License 5 votes vote down vote up
public void generate(Settings settings) {
    try {
        OracleDataSource oracleDataSource = new OracleDataSource();
        oracleDataSource.setURL(settings.getJdbcUrl());
        TypeCatalogDAO typeCatalogDAO = new TypeCatalogDAO(oracleDataSource);

        List<String> types = typeCatalogDAO.getTypeList();

        for (String typeName : types) {
            List<TypeAttribute> typeAttributes = typeCatalogDAO.getTypeAttributes(typeName);

            String className = StringHelper.toCamelCase(typeName);
            String smallClassName = StringHelper.toCamelCaseSmallBegin(typeName);
            VelocityRenderer velocityRenderer = new VelocityRenderer("typegenerator.vm");

            velocityRenderer.put("className", className);
            velocityRenderer.put("smallClassName", smallClassName);
            velocityRenderer.put("typeName", typeName);
            velocityRenderer.put("targetPackage", settings.getConverterPackageName());
            velocityRenderer.put("attrList", typeAttributes);
            velocityRenderer.put("oracleTypesPackage", settings.getEntityPackageName());

            FileUtils.writeStringToFile(new File(settings.getBasePath() + "/" + settings.getConverterPackageName().replace(".", "/") + "/" + className + "Converter.java"), velocityRenderer.render());


        }

    } catch (Exception e) {
        throw new RuntimeException(e);

    }
}
 
Example 19
Project: model-repository-benchmark   File: JVMOracleCDOModelRepository.java   Source Code and License 5 votes vote down vote up
protected DataSource createDataSource() {
	try {
		OracleDataSource source = new OracleDataSource();
		source.setUser(USER);
		source.setPassword(PASS);
		source.setURL(getDataSourceURL());		
		return source;
	} catch (SQLException e) {
		logger.error("Error while creating datasource for oracle", e);
		fireRepositoryEvent(EventLevel.ERROR, "Error while creating datasource for oracle", e);
	}
    return null;
}
 
Example 20
Project: psi-probe-plus   File: OracleDatasourceAccessor.java   Source Code and License 5 votes vote down vote up
public DataSourceInfo getInfo(Object resource) throws Exception {
    DataSourceInfo dataSourceInfo = null;

    if (canMap(resource)) {
        OracleDataSource source = (OracleDataSource) resource;
        OracleConnectionCacheManager occm = OracleConnectionCacheManager.getConnectionCacheManagerInstance();
        Properties cacheProperties = source.getConnectionCacheProperties();
        String cacheName = source.getConnectionCacheName();
        cacheName = cacheName != null && occm.existsCache(cacheName) ? cacheName : null;

        if (cacheProperties != null) {

            dataSourceInfo = new DataSourceInfo();
            if (cacheName != null) {
                dataSourceInfo.setBusyConnections(occm.getNumberOfActiveConnections(cacheName));
                dataSourceInfo.setEstablishedConnections(occm.getNumberOfAvailableConnections(cacheName) + dataSourceInfo.getBusyConnections());
            } else {
                dataSourceInfo.setBusyConnections(0);
                dataSourceInfo.setEstablishedConnections(0);
            }

            dataSourceInfo.setMaxConnections(Utils.toInt(cacheProperties.getProperty("MaxLimit"), -1));
            dataSourceInfo.setJdbcURL(source.getURL());
            dataSourceInfo.setUsername(source.getUser());
            dataSourceInfo.setResettable(true);
        }
    }
    return dataSourceInfo;
}
 
Example 21
Project: psi-probe-plus   File: OracleDatasourceAccessor.java   Source Code and License 5 votes vote down vote up
public boolean reset(Object resource) throws Exception {
    if (canMap(resource)) {
        ((OracleDataSource) resource).close();
        return true;
    }
    return false;
}
 
Example 22
Project: PageServer   File: OraclePagecontrolDriver.java   Source Code and License 5 votes vote down vote up
public OraclePagecontrolDriver(AffiliationCache affilCache, OracleDataSource ods) throws SQLException{
	
	log.trace("Instantiating Pagecontrol object");
	this.affilCache = affilCache;
	this.ods = ods;
	this.printerGroupId = new HashMap<String, Integer>();
	this.printerGroupName = new HashMap<Integer, String>();
	
	this.pageCost = new HashMap<String, Integer>();
	this.pageCostByGroupName = new HashMap<String, Integer>();
	this.databaseBypass = false;
	this.purchaseEnabled = true;
	this.academicCalendar = new Semester();

	Connection connection = ods.getConnection();
	
	PreparedStatement printerLookup = connection.prepareStatement("SELECT p.hostname, p.printer_group_id, pg.name, pg.value FROM printer p, printergroup pg WHERE p.printer_group_id = pg.printer_group_id");
	
	ResultSet printerResults = printerLookup.executeQuery();
	while (printerResults.next() ){
		printerGroupId.put(printerResults.getString("hostname"), printerResults.getInt("printer_group_id"));
		String pgName=printerResults.getString("name");
		int pgCost = printerResults.getInt("value");
		printerGroupName.put(printerResults.getInt("printer_group_id"), pgName);
		pageCost.put(printerResults.getString("hostname"), pgCost);
		if (!pageCostByGroupName.containsKey(pgName)) pageCostByGroupName.put(pgName, pgCost);
	}
	printerResults.close();
	printerLookup.close();
	if (connection != null && !connection.isClosed() ) connection.close();
	log.trace("Finished Instantiating Pagecontrol object");
	
}
 
Example 23
Project: Oracle-CommittingData   File: CommittingData.java   Source Code and License 5 votes vote down vote up
/**
 * Constructs a CommittingData object.
 * @throws SQLException Any database error while
 * opening a database connection
 */
public CommittingData() throws SQLException {
	OracleDataSource ods = new OracleDataSource();
	ods.setDriverType("thin");
	ods.setServerName(host);
	ods.setPortNumber(port);
	ods.setServiceName(serviceName);
	ods.setUser(userName);
	ods.setPassword(password);

	myConnection = ods.getConnection();
	myConnection.setAutoCommit(false);
}
 
Example 24
Project: MuSe   File: Database.java   Source Code and License 5 votes vote down vote up
private Database() {
	try {
		ods = new OracleDataSource();
		ods.setURL(ApplicationConfig.DB_CONNECTION);
		ods.setUser(ApplicationConfig.DB_USER);
		ods.setPassword(ApplicationConfig.DB_PASSWORD);

		// Load driver
		Class.forName(ApplicationConfig.JDBC_CLASS);
	} catch (SQLException e1) {
		LOG.warn("Connection failed!");
	} catch (ClassNotFoundException e) {
		LOG.warn("Driver not found!");
	}
}
 
Example 25
Project: Runway-SDK   File: Oracle.java   Source Code and License 5 votes vote down vote up
@Override
public void close()
{
  try
  {
    ((OracleDataSource)this.dataSource).close();
  }
  catch (SQLException e)
  {
    Database.throwDatabaseException(e);
  }
}
 
Example 26
Project: cadsr-semantic-tools   File: MainTestCase.java   Source Code and License 5 votes vote down vote up
protected DataSource createDefaultDataSource()
        throws Exception
{
    OracleDataSource unitDataSource = new OracleDataSource();

    String url = propertyManager.getUnitDataSourceURL();
    String user = propertyManager.getUnitDataSourceUser();
    String password = propertyManager.getUnitDataSourcePassword();

    unitDataSource.setURL(url);
    unitDataSource.setUser(user);
    unitDataSource.setPassword(password);

    return unitDataSource;
}
 
Example 27
Project: psi-probe-plus   File: OracleDatasourceAccessor.java   Source Code and License 4 votes vote down vote up
public boolean canMap(Object resource) {
    return "oracle.jdbc.pool.OracleDataSource".equals(resource.getClass().getName()) &&
            resource instanceof OracleDataSource;
}
 
Example 28
Project: hibernate-master-class   File: AbstractTest.java   Source Code and License 4 votes vote down vote up
@Override
public Class<? extends DataSource> dataSourceClassName() {
    return OracleDataSource.class;
}
 
Example 29
Project: easydao   File: OracleDataSourceConfig.java   Source Code and License 4 votes vote down vote up
@Bean(name = "sampledb")
public DataSource dataSource() throws SQLException {
    OracleDataSource d = new OracleDataSource();
    d.setServerName(host);
    d.setDatabaseName(databaseName);
    d.setPortNumber(portNumber);
    d.setUser(user);
    d.setPassword(password);
    return d;
}
 
Example 30
Project: ats-framework   File: Test_DbConnOracle.java   Source Code and License 3 votes vote down vote up
@Test
public void getDataSource() {

    DbConnOracle dbConnection = new DbConnOracle("host", "db", "user", "pass");

    assertEquals(OracleDataSource.class, dbConnection.getDataSource().getClass());
}
 
Example 31
Project: kafka-connect-cdc-oracle   File: ConnectionPoolingTest.java   Source Code and License 2 votes vote down vote up
@Test
public void test() {
  OracleDataSource oracleDataSource;


}