Package com.j256.ormlite.jdbc

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


  }

  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

    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

  @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

  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

      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

  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

  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

  public boolean updateNote(Note note) {
    Dao<Note, Integer> notesDao;
    ConnectionSource connectionSource = null;
    try {
      connectionSource = new JdbcConnectionSource(connectionString, userName, userPass);
      notesDao = DaoManager.createDao(connectionSource, Note.class);
      notesDao.update(note);
      connectionSource.close();
    } catch (SQLException ex) {
      System.err.println("Exception: " + ex.getMessage());
View Full Code Here

  private User getUserByToken(String token) {
    Dao<User, Integer> usersDao;
    ConnectionSource connectionSource;
    User user = null;
    try {
      connectionSource = new JdbcConnectionSource(connectionString, userName, userPass);
      usersDao = DaoManager.createDao(connectionSource, User.class);
      QueryBuilder<User, Integer> queryBuilder = usersDao.queryBuilder();
      queryBuilder.where().like(User.TOKEN_FIELD_NAME, token);
      user = usersDao.queryForFirst(queryBuilder.prepare());
      connectionSource.close();
View Full Code Here

TOP

Related Classes of com.j256.ormlite.jdbc.JdbcConnectionSource

Copyright © 2018 www.massapicom. 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.