Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.ConnectionSource


    iterator.next();
  }

  @Test(expected = IllegalStateException.class)
  public void testRemoveThrow() throws Exception {
    ConnectionSource cs = createMock(ConnectionSource.class);
    cs.releaseConnection(null);
    CompiledStatement stmt = createMock(CompiledStatement.class);
    DatabaseResults results = createMock(DatabaseResults.class);
    expect(results.first()).andReturn(true);
    expect(stmt.runQuery(null)).andReturn(results);
    @SuppressWarnings("unchecked")
View Full Code Here


    }
  }

  @Test(expected = IllegalStateException.class)
  public void testBadConnectionSource() throws Exception {
    ConnectionSource cs = createMock(ConnectionSource.class);
    new BaseDaoImpl<Foo, Integer>(cs, Foo.class) {
    };
  }
View Full Code Here

    }

    public static void load() {
        File databaseFile = ChestShop.loadFile("users.db");
        String uri = ConnectionManager.getURI(databaseFile);
        ConnectionSource connection;

        try {
            connection = new JdbcConnectionSource(uri);
            accounts = DaoManager.createDao(connection, Account.class);
View Full Code Here

    DatabaseTypeUtils.createDatabaseType("jdbc:");
  }

  @Test
  public void testCreateDbTypeDataSource() throws Exception {
    ConnectionSource dataSource = null;
    try {
      String dbUrl = "jdbc:h2:mem:ormlitetest";
      dataSource = new JdbcConnectionSource(dbUrl, new H2DatabaseType());
      dataSource.close();
    } finally {
      if (dataSource != null) {
        dataSource.getReadOnlyConnection().close();
      }
    }
  }
View Full Code Here

  }

  @Test
  public void testDoubleDbOpen() throws Exception {
    clearDatabases();
    ConnectionSource cs =
        new JdbcConnectionSource("jdbc:h2:file:" + DATABASE_DIR + "/" + DATABASE_NAME_PREFIX + ".1");
    TableUtils.createTable(cs, Foo.class);
    Dao<Foo, Integer> dao = DaoManager.createDao(cs, Foo.class);
    Foo foo1 = new Foo();
    foo1.val = 12312;
View Full Code Here

     */
    return getReadWriteConnection();
  }

  public DatabaseConnection getReadWriteConnection() throws SQLException {
    DatabaseConnection conn = getSavedConnection();
    if (conn != null) {
      return conn;
    }
    if (connection == null) {
      connection = new AndroidDatabaseConnection(helper.getWritableDatabase(), true);
View Full Code Here

    /*
     * The method is called by Android database helper's get-database calls when Android detects that we need to
     * create or update the database. So we have to use the database argument and save a connection to it on the
     * AndroidConnectionSource, otherwise it will go recursive if the subclass calls getConnectionSource().
     */
    DatabaseConnection conn = cs.getSpecialConnection();
    boolean clearSpecial = false;
    if (conn == null) {
      conn = new AndroidDatabaseConnection(db, true);
      try {
        cs.saveSpecialConnection(conn);
View Full Code Here

    /*
     * The method is called by Android database helper's get-database calls when Android detects that we need to
     * create or update the database. So we have to use the database argument and save a connection to it on the
     * AndroidConnectionSource, otherwise it will go recursive if the subclass calls getConnectionSource().
     */
    DatabaseConnection conn = cs.getSpecialConnection();
    boolean clearSpecial = false;
    if (conn == null) {
      conn = new AndroidDatabaseConnection(db, true);
      try {
        cs.saveSpecialConnection(conn);
View Full Code Here

      @SuppressWarnings("unchecked")
      D castDao = (D) dao;
      return castDao;
    }

    DatabaseTable databaseTable = clazz.getAnnotation(DatabaseTable.class);
    if (databaseTable == null || databaseTable.daoClass() == Void.class
        || databaseTable.daoClass() == BaseDaoImpl.class) {
      @SuppressWarnings("deprecation")
      Dao<T, ?> daoTmp = BaseDaoImpl.createDao(connectionSource, clazz);
      dao = daoTmp;
    } else {
      Class<?> daoClass = databaseTable.daoClass();
      Constructor<?> daoConstructor = null;
      Object[] arguments = null;
      Constructor<?>[] constructors = daoClass.getConstructors();
      // look first for the constructor with a class parameter in case it is a generic dao
      for (Constructor<?> constructor : constructors) {
View Full Code Here

      @SuppressWarnings("unchecked")
      D castDao = (D) dao;
      return castDao;
    }

    DatabaseTable databaseTable = tableConfig.getDataClass().getAnnotation(DatabaseTable.class);
    if (databaseTable == null || databaseTable.daoClass() == Void.class
        || databaseTable.daoClass() == BaseDaoImpl.class) {
      @SuppressWarnings("deprecation")
      Dao<T, ?> daoTmp = BaseDaoImpl.createDao(connectionSource, tableConfig);
      dao = daoTmp;
    } else {
      Class<?> daoClass = databaseTable.daoClass();
      Constructor<?> constructor;
      try {
        constructor = daoClass.getConstructor(ConnectionSource.class, DatabaseTableConfig.class);
      } catch (Exception e) {
        throw SqlExceptionUtil.create(
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.