@Override
 @Test
 public void testLimitFormat() throws Exception {
   connectionSource.setDatabaseType(databaseType);
   BaseDaoImpl<StringId, String> dao =
       new BaseDaoImpl<StringId, String>(connectionSource, StringId.class) {};
   dao.initialize();
   QueryBuilder<StringId, String> qb = dao.queryBuilder();
   long limit = 1232;
   qb.limit(limit);
   String query = qb.prepareStatementString();
   assertTrue(
       query + " should start with stuff", query.startsWith("SELECT LIMIT 0 " + limit + " "));
 }
  private static <T extends OrmLiteSqliteOpenHelper> T loadHelper(
      Context context, Class<T> openHelperClass) {
    if (helper == null) {
      if (wasClosed) {
        // this can happen if you are calling get/release and then get again
        logger.info("helper was already closed and is being re-opened");
      }
      if (context == null) {
        throw new IllegalArgumentException("context argument is null");
      }
      Context appContext = context.getApplicationContext();
      helper = constructHelper(appContext, helperClass);
      logger.trace("zero instances, created helper {}", helper);
      /*
       * Filipe Leandro and I worked on this bug for like 10 hours straight. It's a doosey.
       *
       * Each ForeignCollection has internal DAO objects that are holding a ConnectionSource. Each Android
       * ConnectionSource is tied to a particular database connection. What Filipe was seeing was that when all of
       * his views we closed (onDestroy), but his application WAS NOT FULLY KILLED, the first View.onCreate()
       * method would open a new connection to the database. Fine. But because he application was still in memory,
       * the static BaseDaoImpl default cache had not been cleared and was containing cached objects with
       * ForeignCollections. The ForeignCollections still had references to the DAOs that had been opened with old
       * ConnectionSource objects and therefore the old database connection. Using those cached collections would
       * cause exceptions saying that you were trying to work with a database that had already been close.
       *
       * Now, whenever we create a new helper object, we must make sure that the internal object caches have been
       * fully cleared. This is a good lesson for anyone that is holding objects around after they have closed
       * connections to the database or re-created the DAOs on a different connection somehow.
       */
      BaseDaoImpl.clearAllInternalObjectCaches();
      /*
       * Might as well do this also since if the helper changes then the ConnectionSource will change so no one is
       * going to have a cache hit on the old DAOs anyway. All they are doing is holding memory.
       *
       * NOTE: we don't want to clear the config map.
       */
      DaoManager.clearDaoCache();
      instanceCount = 0;
    }

    instanceCount++;
    logger.trace("returning helper {}, instance count = {} ", helper, instanceCount);
    @SuppressWarnings("unchecked")
    T castHelper = (T) helper;
    return castHelper;
  }
Esempio n. 3
0
 /** Returns the DAO for ProfileElement class. It will create it or just give the cached value. */
 public Dao<ProfileElement, Integer> getProfileElementDAO() throws SQLException {
   if (profileElementDAO == null) {
     profileElementDAO = BaseDaoImpl.createDao(getConnectionSource(), ProfileElement.class);
   }
   return profileElementDAO;
 }
Esempio n. 4
0
 /** Returns the DAO for Condition class. It will create it or just give the cached value. */
 public Dao<Condition, Integer> getConditionDAO() throws SQLException {
   if (conditionDAO == null) {
     conditionDAO = BaseDaoImpl.createDao(getConnectionSource(), Condition.class);
   }
   return conditionDAO;
 }
Esempio n. 5
0
 /** Returns the DAO for TimeRule class. It will create it or just give the cached value. */
 public Dao<TimeRule, Integer> getTimeRuleDAO() throws SQLException {
   if (timeRuleDAO == null) {
     timeRuleDAO = BaseDaoImpl.createDao(getConnectionSource(), TimeRule.class);
   }
   return timeRuleDAO;
 }