public static void shutdownDefaultDataSource(DataSource dataSource) { final EmbeddedDataSource ds = (EmbeddedDataSource) dataSource; ds.setCreateDatabase("shutdown"); ds.setShutdownDatabase("shutdown"); try { ds.getConnection(); } catch (SQLException expectedAndIgnored) { } }
public static DataSource createDataSource(String homeDir, String dbName) throws IOException { // Setup the Derby datasource. System.setProperty("derby.system.home", homeDir); System.setProperty("derby.storage.fileSyncTransactionLog", "true"); System.setProperty("derby.storage.pageCacheSize", "100"); final EmbeddedDataSource ds = new EmbeddedDataSource(); ds.setDatabaseName(dbName); ds.setCreateDatabase("create"); return ds; }
@Override DataSource createDataSource() { EmbeddedDataSource dataSource = new EmbeddedDataSource(); dataSource.setUser(""); dataSource.setPassword(""); dataSource.setDatabaseName("dbtest"); dataSource.setCreateDatabase("create"); dataSource.setConnectionAttributes("upgrade=true"); return dataSource; } };
@Override public void destroy() throws Exception { logger.info("Attempting Derby database shut down on: " + dataSource); if (!isShutdown && dataSource != null && dataSource instanceof EmbeddedDataSource) { EmbeddedDataSource ds = (EmbeddedDataSource) dataSource; try { ds.setShutdownDatabase("shutdown"); ds.getConnection(); } catch (SQLException except) { if (except.getSQLState().equals("08006")) { // SQLState derby throws when shutting down the database logger.info("Derby database is now shut down."); isShutdown = true; } else { logger.error("Problem shutting down Derby " + except.getMessage()); } } } }
@Override public void shutdown(DataSource dataSource, String databaseName) { try { new EmbeddedDriver().connect( String.format(URL_TEMPLATE, databaseName, "drop=true"), new Properties()); } catch (SQLException ex) { // Error code that indicates successful shutdown if (!"08006".equals(ex.getSQLState())) { LogFactory.getLog(getClass()).warn("Could not shut down embedded Derby database", ex); } } }
/** * The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a * directory called "jpaserver_derby_files". * * A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource. */ @Bean(destroyMethod = "close") public DataSource dataSource() { String url = "jdbc:derby:directory:target/jpaserver_derby_files;create=true"; if (isNotBlank(ContextHolder.getDatabaseUrl())) { url = ContextHolder.getDatabaseUrl(); } BasicDataSource retVal = new BasicDataSource(); retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver()); retVal.setUrl(url); retVal.setUsername(""); retVal.setPassword(""); return retVal; }
@Override public Connection connect(String url, Properties info) throws SQLException { url = url.replace("sderby", "derby"); return new StatementVerifyingDerby.StatementVerifyingConnection(super.connect(url, info)); }
/** * Return the user name used to establish the connection. * * @return the user name used to establish the connection */ public String getUserName() { return xaDataSource.getUser(); }
/** * Set whether the database should be created if it does not already exist. * * @param create TRUE if the database should be created */ public void setCreateDatabase(Boolean create) { xaDataSource.setCreateDatabase(create ? "create" : null); }
/** * Set the user password credential establish the connection. * This value is used if no connection information is supplied by the application * when attempting to create a connection. * * @param password the password credential used to establish the connection; may be null */ public void setPassword(String password) { xaDataSource.setPassword(password); }
@Override public boolean acceptsURL(String url) throws SQLException { url = url.replace("sderby", "derby"); return super.acceptsURL(url); }
/** * Set the user password credential establish the connection. * This value is used if no connection information is supplied by the application * when attempting to create a connection. * * @param password the password credential used to establish the connection; may be null */ public void setPassword(String password) { connectionPoolDataSource.setPassword(password); }
/** * Set the user name used establish the connection. * This value is used if no connection information is supplied by the application * when attempting to create a connection. * * @param user the user name used to establish the connection; may be null */ public void setUserName(String user) { connectionPoolDataSource.setUser(user); }
/** * Set the name of the server to connect to. * * @param serverName the name of the server to connect to */ public void setServerName(String serverName) { connectionPoolDataSource.setServerName(serverName); }
@Override protected DataSource createInstance() throws Exception { File directory = new File(dataDirectory); System.setProperty("derby.system.home", directory.getCanonicalPath()); System.setProperty("derby.storage.fileSyncTransactionLog", "true"); System.setProperty("derby.storage.pageCacheSize", "100"); final EmbeddedDataSource ds = new EmbeddedDataSource(); ds.setDatabaseName("build/derbydb"); ds.setCreateDatabase("create"); return ds; }
public static void shutdownDefaultDataSource(DataSource dataSource) { final EmbeddedDataSource ds = (EmbeddedDataSource) dataSource; ds.setCreateDatabase("shutdown"); ds.setShutdownDatabase("shutdown"); try { ds.getConnection(); } catch (SQLException expectedAndIgnored) { } }
@Override public Connection connect(java.lang.String url, java.util.Properties info) throws SQLException { TestObjectStoreInitRetry.misbehave(); url = url.replace("fderby","derby"); return new FakeDerby.Connection(super.connect(url, info)); }
@Override public boolean acceptsURL(String url) throws SQLException { url = url.replace("fderby","derby"); return super.acceptsURL(url); }
@Override protected DataSource createInstance() throws Exception { File directory = new File(dataDirectory); System.setProperty("derby.system.home", directory.getCanonicalPath()); System.setProperty("derby.storage.fileSyncTransactionLog", "true"); System.setProperty("derby.storage.pageCacheSize", "100"); final EmbeddedDataSource ds = new EmbeddedDataSource(); ds.setDatabaseName("build/derbydb"); ds.setCreateDatabase("create"); logger.info("Created instance of " + ds.toString()); return ds; }
public static void shutdownDefaultDataSource(DataSource dataSource) { final EmbeddedDataSource ds = (EmbeddedDataSource) dataSource; ds.setCreateDatabase("shutdown"); ds.setShutdownDatabase("shutdown"); try { ds.getConnection(); } catch (SQLException expectedAndIgnored) { } }