Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.ConnectionSource


    verify(connectionSource, conn, stmt);
  }

  @Test
  public void testComboIndex() throws Exception {
    final ConnectionSource connectionSource = createMock(ConnectionSource.class);
    expect(connectionSource.getDatabaseType()).andReturn(databaseType).anyTimes();
    DatabaseConnection conn = createMock(DatabaseConnection.class);
    expect(connectionSource.getReadWriteConnection()).andReturn(conn);
    final CompiledStatement stmt = createMock(CompiledStatement.class);
    expect(conn.compileStatement(isA(String.class), isA(StatementType.class), isA(FieldType[].class))).andAnswer(
        new IAnswer<CompiledStatement>() {
          private int stmtC = 0;
          public CompiledStatement answer() throws Throwable {
            Object[] args = EasyMock.getCurrentArguments();
            assertNotNull(args);
            assertEquals(3, args.length);
            if (stmtC == 0) {
              assertEquals("CREATE TABLE `comboindex` (`stuff` VARCHAR(255) , `junk` BIGINT ) ", args[0]);
            } else if (stmtC == 1) {
              assertEquals("CREATE INDEX `" + ComboIndex.INDEX_NAME
                  + "` ON `comboindex` ( `stuff`, `junk` )", args[0]);
            } else {
              fail("Should only be called twice");
            }
            stmtC++;
            assertEquals(StatementType.EXECUTE, args[1]);
            assertEquals(0, ((FieldType[]) args[2]).length);
            return stmt;
          }
        })
        .anyTimes();
    expect(stmt.runUpdate()).andReturn(0).anyTimes();
    connectionSource.releaseConnection(conn);
    expectLastCall().anyTimes();
    stmt.close();
    expectLastCall().anyTimes();
    replay(connectionSource, conn, stmt);
    TableUtils.createTable(connectionSource, ComboIndex.class);
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");
      ex.printStackTrace();
    } finally {
      if (connectionSource != null) {
        connectionSource.close();
      }
    }
  }
View Full Code Here

  public void createNotesSuite(User owner, String title) throws Exception {
    if (!isNotesSuiteTitleValid(title)) {
      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);
    } catch (SQLException ex) {
      System.err.println("Exception: " + ex.getMessage());
      ex.printStackTrace();
    } finally {
      if (connectionSource != null) {
        connectionSource.close();
      }
    }
  }
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();
    } catch (SQLException ex) {
      System.err.println("Exception: " + ex.getMessage());
      ex.printStackTrace();
    }
    return notesSuites;
View Full Code Here

    return notesSuites;
  }

  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());
      ex.printStackTrace();
      return false;
    }
View Full Code Here

    return true;
  }

  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());
      ex.printStackTrace();
      return false;
    }
View Full Code Here

    return new String(Files.readAllBytes(Paths.get(authFilePath)), StandardCharsets.UTF_8);
  }

  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();
    } catch (SQLException ex) {
      System.err.println("Exception: " + ex.getMessage());
      ex.printStackTrace();
    }
    return user;
View Full Code Here

  }

  private void generateAndSaveUserToken(User user) {
    if (user != null) {
      Dao<User, Integer> usersDao;
      ConnectionSource connectionSource;
      try {
        connectionSource = new JdbcConnectionSource(connectionString, userName, userPass);
        usersDao = DaoManager.createDao(connectionSource, User.class);
        String token = generateUserAuthToken();
        user.setToken(token);
        usersDao.update(user);
        saveUserAuthFile(token);
        connectionSource.close();
      } catch (SQLException ex) {
        System.err.println("Exception: " + ex.getMessage());
        ex.printStackTrace();
      } catch (Exception ex) {
        System.err.println("Exception: " + ex.getMessage());
View Full Code Here

    return (title.length() > 4 && title.length() < 129);
  }

  User loginUser(String login, String password, boolean rememberUser) {
    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.LOGIN_FIELD_NAME, login).and().like(User.PASSWORD_FIELD_NAME, password);
      user = usersDao.queryForFirst(queryBuilder.prepare());
      connectionSource.close();
    } catch (SQLException ex) {
      System.err.println("Exception: " + ex.getMessage());
      ex.printStackTrace();
    }
    if (rememberUser) {
View Full Code Here

TOP

Related Classes of com.j256.ormlite.support.ConnectionSource

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.