public void setContentVersion(long version) { try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); RepositoryUtil.updateVersion(connectionSource, VERSION_ENTITY_NAME + "Content", version); } catch (SQLException ex) { ex.printStackTrace(); } }
@Override public Connection provide() { return connection.getInternalConnection(); } @Override
protected void closeConnectionSource() throws Exception { if (connectionSource != null) { connectionSource.close(); connectionSource = null; } }
@Test public void testReleaseAlreadyClosedUnknown() throws Exception { JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL); try { JdbcDatabaseConnection conn1 = new JdbcDatabaseConnection(DriverManager.getConnection(DEFAULT_DATABASE_URL)); conn1.close(); pooled.releaseConnection(conn1); } finally { pooled.close(); } }
public long getContentVersionFromDB() { try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); return RepositoryUtil.getDatabaseVersion(connectionSource, VERSION_ENTITY_NAME + "Content"); } catch (SQLException ex) { Logger.getLogger(CardRepository.class).error("Error getting content version from DB - ", ex); } return 0; }
@Test public void testReleaseUnknown() throws Exception { JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL); try { JdbcDatabaseConnection conn1 = new JdbcDatabaseConnection(DriverManager.getConnection(DEFAULT_DATABASE_URL)); pooled.releaseConnection(conn1); } finally { pooled.close(); } }
public void setContentVersion(long version) { try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); RepositoryUtil.updateVersion(connectionSource, VERSION_ENTITY_NAME + "Content", version); } catch (SQLException ex) { Logger.getLogger(CardRepository.class).error("Error getting content version - ", ex); } }
public long getDBVersionFromDB() { try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); return RepositoryUtil.getDatabaseVersion(connectionSource, VERSION_ENTITY_NAME); } catch (SQLException ex) { Logger.getLogger(CardRepository.class).error("Error getting DB version from DB - ", ex); } return 0; }
public long getContentVersionFromDB() { try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); return RepositoryUtil.getDatabaseVersion(connectionSource, VERSION_ENTITY_NAME + "Content"); } catch (SQLException ex) { ex.printStackTrace(); } return 0; }
public void openDB() { try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); cardDao = DaoManager.createDao(connectionSource, CardInfo.class); } catch (SQLException ex) { Logger.getLogger(CardRepository.class).error("Error opening card repository - ", ex); } } }
AuthorizedUserRepository() { File file = new File("db"); if (!file.exists()) { file.mkdirs(); } try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); TableUtils.createTableIfNotExists(connectionSource, AuthorizedUser.class); dao = DaoManager.createDao(connectionSource, AuthorizedUser.class); } catch (SQLException ex) { Logger.getLogger(AuthorizedUserRepository.class).error("Error creating / assigning authorized_user repository - ", ex); } }
UserStatsRepository() { File file = new File("db"); if (!file.exists()) { file.mkdirs(); } try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); boolean obsolete = RepositoryUtil.isDatabaseObsolete(connectionSource, VERSION_ENTITY_NAME, DB_VERSION); if (obsolete) { TableUtils.dropTable(connectionSource, UserStats.class, true); } TableUtils.createTableIfNotExists(connectionSource, UserStats.class); dao = DaoManager.createDao(connectionSource, UserStats.class); } catch (SQLException ex) { Logger.getLogger(UserStatsRepository.class).error("Error creating user_stats repository - ", ex); } }
TableRecordRepository() { File file = new File("db"); if (!file.exists()) { file.mkdirs(); } try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); boolean obsolete = RepositoryUtil.isDatabaseObsolete(connectionSource, VERSION_ENTITY_NAME, DB_VERSION); if (obsolete) { TableUtils.dropTable(connectionSource, TableRecord.class, true); } TableUtils.createTableIfNotExists(connectionSource, TableRecord.class); dao = DaoManager.createDao(connectionSource, TableRecord.class); } catch (SQLException ex) { Logger.getLogger(TableRecordRepository.class).error("Error creating table_record repository - ", ex); } }
private EntityManager() { File file = new File("db"); if (!file.exists()) { file.mkdirs(); } try { ConnectionSource logConnectionSource = new JdbcConnectionSource(PropertiesUtil.getDBLogUrl()); TableUtils.createTableIfNotExists(logConnectionSource, Log.class); logDao = DaoManager.createDao(logConnectionSource, Log.class); ConnectionSource feedbackConnectionSource = new JdbcConnectionSource(PropertiesUtil.getDBFeedbackUrl()); TableUtils.createTableIfNotExists(feedbackConnectionSource, Feedback.class); feedbackDao = DaoManager.createDao(feedbackConnectionSource, Feedback.class); } catch (SQLException ex) { ex.printStackTrace(); } }
CardRepository() { File file = new File("db"); if (!file.exists()) { file.mkdirs(); } try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); boolean isObsolete = RepositoryUtil.isDatabaseObsolete(connectionSource, VERSION_ENTITY_NAME, CARD_DB_VERSION); boolean isNewBuild = RepositoryUtil.isNewBuildRun(connectionSource, VERSION_ENTITY_NAME, CardRepository.class); // recreate db on new build if (isObsolete || isNewBuild) { //System.out.println("Local cards db is outdated, cleaning..."); TableUtils.dropTable(connectionSource, CardInfo.class, true); } TableUtils.createTableIfNotExists(connectionSource, CardInfo.class); cardDao = DaoManager.createDao(connectionSource, CardInfo.class); eventSource.fireRepositoryDbLoaded(); } catch (SQLException ex) { Logger.getLogger(CardRepository.class).error("Error creating card repository - ", ex); } }
ExpansionRepository() { File file = new File("db"); if (!file.exists()) { file.mkdirs(); } try { ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); boolean isObsolete = RepositoryUtil.isDatabaseObsolete(connectionSource, VERSION_ENTITY_NAME, EXPANSION_DB_VERSION); boolean isNewBuild = RepositoryUtil.isNewBuildRun(connectionSource, VERSION_ENTITY_NAME, ExpansionRepository.class); // recreate db on new build if (isObsolete || isNewBuild) { //System.out.println("Local sets db is outdated, cleaning..."); TableUtils.dropTable(connectionSource, ExpansionInfo.class, true); } TableUtils.createTableIfNotExists(connectionSource, ExpansionInfo.class); expansionDao = DaoManager.createDao(connectionSource, ExpansionInfo.class); instanceInitialized = true; eventSource.fireRepositoryDbLoaded(); } catch (SQLException ex) { ex.printStackTrace(); } }
// you can change the database type, hostname, and the database name String databaseUrl = "jdbc:mysql://host.name.j256.com/databaseName"; ConnectionSource connectionSource = new JdbcConnectionSource(databaseUrl); ...
protected ConnectionSource getConnectionSource() throws SQLException { String databaseUrl = "jdbc:h2:tcp://localhost/~/test"; return new JdbcConnectionSource(databaseUrl,"sa","sa"); }
connectionSource = new JdbcConnectionSource( "jdbc:h2:/data/data/helloandroidh2/databases/helloAndroidH2");