Examples of JdbcConnectionSource


Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

  public static void initializeDB() {
    LOGGER.info("Initialized database");
    System.setProperty(LocalLog.LOCAL_LOG_LEVEL_PROPERTY, "error");
    try {
      ConnectionSource connectionSource = new JdbcConnectionSource("jdbc:h2:file:" + dbFileName);
      TableUtils.createTableIfNotExists(connectionSource, Show.class);
      TableUtils.createTableIfNotExists(connectionSource, Season.class);
      TableUtils.createTableIfNotExists(connectionSource, Episode.class);
      TableUtils.createTableIfNotExists(connectionSource, Feed.class);
      TableUtils.createTableIfNotExists(connectionSource, Settings.class);
      TableUtils.createTableIfNotExists(connectionSource, Search.class);
      connectionSource.close();
    } catch (SQLException e) {
      LOGGER.severe("SQLException: " + e.toString());
      System.exit(1);
    }
  }
View Full Code Here

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

    }
  }

  public static void saveData() {
    try {
      ConnectionSource connectionSource = new JdbcConnectionSource("jdbc:h2:file:" + dbFileName);
      Dao<Show, Integer> showDao = DaoManager.createDao(connectionSource, Show.class);
      Dao<Season, Integer> seasonDao = DaoManager.createDao(connectionSource, Season.class);
      Dao<Episode, Integer> episodeDao = DaoManager.createDao(connectionSource, Episode.class);
      int numShows = 0;
      int numSeasons = 0;
      int numEpisodes = 0;
      ArrayList<Show> shows = ShowLibrary.getInstance().shows;
      for(Show show : shows) {
        showDao.createOrUpdate(show);
        numShows++;
        for(Season season : show.seasons) {
          seasonDao.createOrUpdate(season);
          numSeasons++;
          for(Episode episode : season.getEpisodes()) {
            episodeDao.createOrUpdate(episode);
            numEpisodes++;
          }
        }
      }
      for(Show dbShow : showDao.queryForAll()) {
        Show myShow = ShowLibrary.getInstance().getShow(dbShow.getTitle());
        if(myShow==null) {
          for(Season season : dbShow.seasons) {
            episodeDao.delete(season.getEpisodes());
          }
          seasonDao.delete(dbShow.seasons);
          showDao.delete(dbShow);
        }
      }
      Dao<Settings, Integer> settingsDao = DaoManager.createDao(connectionSource, Settings.class);
      Dao<Feed, Integer> feedDao = DaoManager.createDao(connectionSource, Feed.class);
      Dao<Search, Integer> searchDao = DaoManager.createDao(connectionSource, Search.class);
      Settings settings = Settings.getInstance();
      for(Feed feed : settings.getFeeds()) {
        feedDao.createOrUpdate(feed);
      }
      for(Search search : settings.getSearches()) {
        searchDao.createOrUpdate(search);
      }
      settingsDao.createOrUpdate(settings);
      LOGGER.fine("Stored " + numShows + " shows, " + numSeasons + " seasons, and " + numEpisodes + " episodes in database.");
      connectionSource.close();
    } catch (SQLException e) {
      LOGGER.severe("SQLException: " + e.toString());
      System.exit(1);
    }
  }
View Full Code Here

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

    }
  }

  public static void loadShows() {
    try {
      ConnectionSource connectionSource = new JdbcConnectionSource("jdbc:h2:file:" + dbFileName);
      Dao<Show, Integer> showDao = DaoManager.createDao(connectionSource, Show.class);
      QueryBuilder<Show, Integer> queryBuilder = showDao.queryBuilder().orderBy("title", true);
      PreparedQuery<Show> preparedQuery = queryBuilder.prepare();
      ShowLibrary.getInstance().shows.clear();
      ShowLibrary.getInstance().shows.addAll(showDao.query(preparedQuery));
      connectionSource.close();
    } catch (SQLException e) {
      LOGGER.severe("SQLException: " + e.toString());
      System.exit(1);
    }
    int numShows = 0;
View Full Code Here

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

  }

  public static Settings getSettings() {
    Settings settings = null;
    try {
      ConnectionSource connectionSource = new JdbcConnectionSource("jdbc:h2:file:" + dbFileName);
      Dao<Settings, Integer> settingsDao = DaoManager.createDao(connectionSource, Settings.class);
      QueryBuilder<Settings, Integer> queryBuilder = settingsDao.queryBuilder();
      queryBuilder.where().isNotNull("databaseId");
      PreparedQuery<Settings> preparedQuery = queryBuilder.prepare();
      settings = settingsDao.queryForFirst(preparedQuery);
      settingsDao.update(settings);
      connectionSource.close();
    } catch (SQLException e) {
      LOGGER.severe("SQLException: " + e.toString());
      System.exit(1);
    }
    LOGGER.fine("Loaded settings from database");
View Full Code Here

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

    return settings;
  }

  public static void clear() {
    try {
    ConnectionSource connectionSource = new JdbcConnectionSource("jdbc:h2:file:" + dbFileName);
    TableUtils.dropTable(connectionSource, Show.class, true);
    TableUtils.dropTable(connectionSource, Season.class, true);
    TableUtils.dropTable(connectionSource, Episode.class, true);
    TableUtils.dropTable(connectionSource, Settings.class, true);
    TableUtils.dropTable(connectionSource, Feed.class, true);
View Full Code Here

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

  @Test
  public void test() {
    Database.initializeDB();
    try {
      ConnectionSource connectionSource = new JdbcConnectionSource("jdbc:h2:file:" + Database.dbFileName);
      Dao<Show, Integer> showDao = DaoManager.createDao(connectionSource, Show.class);
      Dao<Season, Integer> seasonDao = DaoManager.createDao(connectionSource, Season.class);
      Dao<Episode, Integer> episodeDao = DaoManager.createDao(connectionSource, Episode.class);
      Dao<Feed, Integer> feedDao = DaoManager.createDao(connectionSource, Feed.class);
      Dao<Settings, Integer> settingsDao = DaoManager.createDao(connectionSource, Settings.class);
      Dao<Search, Integer> searchDao = DaoManager.createDao(connectionSource, Search.class);
     
      //TableUtils.dropTable(connectionSource, Show.class, true);
      //TableUtils.dropTable(connectionSource, Season.class, true);
      //TableUtils.dropTable(connectionSource, Episode.class, true);
      TableUtils.dropTable(connectionSource, Settings.class, true);
      TableUtils.dropTable(connectionSource, Feed.class, true);
      TableUtils.dropTable(connectionSource, Search.class, true);
     
      assertFalse(feedDao.isTableExists());
      assertFalse(showDao.isTableExists());
      assertFalse(seasonDao.isTableExists());
      assertFalse(episodeDao.isTableExists());
      assertFalse(settingsDao.isTableExists());
      assertFalse(searchDao.isTableExists());
      connectionSource.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

  public TeamNotepadModel(boolean ommitDBCreation){}

  private void setupDatabase() throws SQLException {
    ConnectionSource connectionSource = null;
    try {
      connectionSource = new JdbcConnectionSource(connectionString, userName, userPass);
      TableUtils.createTableIfNotExists(connectionSource, NotesSuite.class);
      TableUtils.createTableIfNotExists(connectionSource, User.class);
      TableUtils.createTableIfNotExists(connectionSource, Note.class);
    } catch (Exception ex) {
      System.err.println("Exception: " + ex.getMessage() + "\n");
View Full Code Here

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

      throw new Exception("Incorrect title");
    }
    Dao<NotesSuite, Integer> notesSuiteDao;
    ConnectionSource connectionSource = null;
    try {
      connectionSource = new JdbcConnectionSource(connectionString, userName, userPass);
      notesSuiteDao = DaoManager.createDao(connectionSource, NotesSuite.class);
      NotesSuite newNotesSuite = new NotesSuite(owner, title);
      notesSuiteDao.create(newNotesSuite);
      int id = newNotesSuite.getId();
      System.out.println("Created: " + id);
View Full Code Here

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

  public List<NotesSuite> getNotesSuites(User owner) {
    Dao<NotesSuite, Integer> notesSuitesDao;
    ConnectionSource connectionSource = null;
    List<NotesSuite> notesSuites = null;
    try {
      connectionSource = new JdbcConnectionSource(connectionString, userName, userPass);
      notesSuitesDao = DaoManager.createDao(connectionSource, NotesSuite.class);
      QueryBuilder<NotesSuite, Integer> queryBuilder = notesSuitesDao.queryBuilder();
      queryBuilder.where().eq(NotesSuite.OWNER_FIELD_NAME, owner);
      notesSuites = notesSuitesDao.query(queryBuilder.prepare());
      connectionSource.close();
View Full Code Here

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource

  public boolean createNote(Note note) {
    Dao<Note, Integer> notesDao;
    ConnectionSource connectionSource = null;
    try {
      connectionSource = new JdbcConnectionSource(connectionString, userName, userPass);
      notesDao = DaoManager.createDao(connectionSource, Note.class);
      notesDao.create(note);
      connectionSource.close();
    } catch (SQLException ex) {
      System.err.println("Exception: " + ex.getMessage());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.