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(); } }
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); } } }
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; }
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; }
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(); } }
// this loads the JDBC driver to access a sqlite db with jdbc // http://stackoverflow.com/questions/6740601/what-does-class-fornameorg-sqlite-jdbc-do Class.forName("org.sqlite.JDBC"); // this uses a specific driver to access sqlite db via jdbc String dbConnectionString = "jdbc:sqlite:/pathToTheDataBase/database.db"; ConnectionSource connectionSource = new JdbcConnectionSource(dbConnectionString); // create table using ORMLIte TableUtils.createTable(connectionSource, UserEntity.class); Dao<UserEntity,String> accountDao = DaoManager.createDao(connectionSource, UserEntity.class); ....
@Override protected void setDatabaseParams() throws SQLException { databaseUrl = "jdbc:mariadb:ormlite"; connectionSource = new JdbcConnectionSource(DEFAULT_DATABASE_URL); databaseType = new MariaDbDatabaseType(); }
@Override protected void setDatabaseParams() throws SQLException { databaseUrl = "jdbc:postgresql:ormlitepostgres"; connectionSource = new JdbcConnectionSource(DEFAULT_DATABASE_URL); databaseType = new PostgresDatabaseType(); }
@Override protected void setDatabaseParams() throws SQLException { databaseUrl = "jdbc:db2:ormlitedb2"; connectionSource = new JdbcConnectionSource(DEFAULT_DATABASE_URL); databaseType = new Db2DatabaseType(); }
@Test(expected = SQLException.class) public void testReleaseConnectionBeforeInitialize() throws Exception { JdbcConnectionSource sds = new JdbcConnectionSource(); sds.releaseConnection(null); sds.close(); }
@Test public void testSimpleDataSourceStringStringString() throws Exception { String username = "user"; String password = "_secret"; String url = "jdbc:h2:mem:ormlite-up;USER=" + username + ";PASSWORD=" + password; JdbcConnectionSource sds = new JdbcConnectionSource(url, username, password); assertNotNull(sds.getReadOnlyConnection(null)); sds.close(); }
@Test public void testSaveAndClear() throws Exception { JdbcConnectionSource sds = new JdbcConnectionSource("jdbc:h2:mem:baz"); DatabaseConnection conn1 = sds.getReadOnlyConnection(null); DatabaseConnection conn2 = sds.getReadOnlyConnection(null); assertSame(conn1, conn2); sds.saveSpecialConnection(conn1); sds.clearSpecialConnection(conn1); sds.releaseConnection(conn1); sds.close(); }
@Test public void testSetDatabaseType() throws Exception { JdbcConnectionSource sds = new JdbcConnectionSource(); sds.setUrl("jdbc:h2:mem:baz"); sds.setDatabaseType(new H2DatabaseType()); sds.initialize(); assertTrue(sds.getDatabaseType() instanceof H2DatabaseType); sds.close(); }