Search in sources :

Example 1 with EmbeddedDataSource

use of org.apache.derby.jdbc.EmbeddedDataSource in project jetty.project by eclipse.

the class DataSourceLoginServiceTest method configureLoginService.

public static DataSourceLoginService configureLoginService() throws Exception {
    DataSourceLoginService loginService = new DataSourceLoginService();
    loginService.setUserTableName("users");
    loginService.setUserTableKey("id");
    loginService.setUserTableUserField("username");
    loginService.setUserTablePasswordField("pwd");
    loginService.setRoleTableName("roles");
    loginService.setRoleTableKey("id");
    loginService.setRoleTableRoleField("role");
    loginService.setUserRoleTableName("user_roles");
    loginService.setUserRoleTableRoleKey("role_id");
    loginService.setUserRoleTableUserKey("user_id");
    loginService.setJndiName("dstest");
    loginService.setName(__realm);
    if (_testServer != null)
        loginService.setServer(_testServer.getServer());
    //create a datasource
    EmbeddedDataSource ds = new EmbeddedDataSource();
    File db = new File(DatabaseLoginServiceTestServer.getDbRoot(), "loginservice");
    ds.setDatabaseName(db.getAbsolutePath());
    org.eclipse.jetty.plus.jndi.Resource binding = new org.eclipse.jetty.plus.jndi.Resource(null, "dstest", ds);
    assertThat("Created binding for dstest", binding, notNullValue());
    return loginService;
}
Also used : DataSourceLoginService(org.eclipse.jetty.plus.security.DataSourceLoginService) EmbeddedDataSource(org.apache.derby.jdbc.EmbeddedDataSource) File(java.io.File)

Example 2 with EmbeddedDataSource

use of org.apache.derby.jdbc.EmbeddedDataSource in project torodb by torodb.

the class OfficialDerbyDriver method getConfiguredDataSource.

@Override
public DataSource getConfiguredDataSource(DerbyDbBackendConfiguration configuration, String poolName) {
    DataSource dataSource;
    if (configuration.embedded()) {
        EmbeddedDataSource embeddedDataSource = new EmbeddedDataSource();
        embeddedDataSource.setCreateDatabase("create");
        if (configuration.inMemory()) {
            embeddedDataSource.setDatabaseName("memory:" + configuration.getDbName());
        } else {
            embeddedDataSource.setDatabaseName(configuration.getDbName());
        }
        try (Connection connection = embeddedDataSource.getConnection()) {
            LOGGER.debug("Derby test connection has been successfully created.");
        } catch (SQLException ex) {
            throw new SystemException(ex);
        }
        embeddedDataSource.setCreateDatabase(null);
        dataSource = embeddedDataSource;
    } else {
        ClientDataSource clientDataSource = new ClientDataSource();
        clientDataSource.setServerName(configuration.getDbHost());
        clientDataSource.setPortNumber(configuration.getDbPort());
        clientDataSource.setUser(configuration.getUsername());
        clientDataSource.setPassword(configuration.getPassword());
        if (configuration.inMemory()) {
            clientDataSource.setDatabaseName("memory:" + configuration.getDbName());
        } else {
            clientDataSource.setDatabaseName(configuration.getDbName());
        }
        dataSource = clientDataSource;
    }
    if (LOGGER.isTraceEnabled()) {
        try {
            dataSource.setLogWriter(LOGGER_WRITER);
        } catch (SQLException sqlException) {
            throw new SystemException(sqlException);
        }
    }
    //TODO
    try (Connection conn = dataSource.getConnection();
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery("SELECT 1 FROM SYSIBM.SYSDUMMY1")) {
        rs.next();
    } catch (SQLException ex) {
        throw new SystemException(ex);
    }
    return dataSource;
}
Also used : SystemException(com.torodb.core.exceptions.SystemException) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ClientDataSource(org.apache.derby.jdbc.ClientDataSource) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) EmbeddedDataSource(org.apache.derby.jdbc.EmbeddedDataSource) EmbeddedDataSource(org.apache.derby.jdbc.EmbeddedDataSource) DataSource(javax.sql.DataSource) ClientDataSource(org.apache.derby.jdbc.ClientDataSource)

Example 3 with EmbeddedDataSource

use of org.apache.derby.jdbc.EmbeddedDataSource in project aries by apache.

the class DerbyActivator method createDataSource.

public DataSource createDataSource(Properties props) {
    EmbeddedDataSource embeddedDataSource = new EmbeddedDataSource();
    embeddedDataSource.setDataSourceName(props.getProperty(JDBC_DATASOURCE_NAME));
    embeddedDataSource.setDatabaseName(props.getProperty(JDBC_DATABASE_NAME));
    embeddedDataSource.setUser(props.getProperty(JDBC_USER));
    embeddedDataSource.setPassword(props.getProperty(JDBC_PASSWORD));
    return embeddedDataSource;
}
Also used : EmbeddedDataSource(org.apache.derby.jdbc.EmbeddedDataSource)

Aggregations

EmbeddedDataSource (org.apache.derby.jdbc.EmbeddedDataSource)3 SystemException (com.torodb.core.exceptions.SystemException)1 File (java.io.File)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 DataSource (javax.sql.DataSource)1 ClientDataSource (org.apache.derby.jdbc.ClientDataSource)1 DataSourceLoginService (org.eclipse.jetty.plus.security.DataSourceLoginService)1