public boolean onContextItemSelected(MenuItem item) {

    AdapterView.AdapterContextMenuInfo info =
        (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();

    Interes interes = interesesAdapter.getItem(info.position);

    switch (menuItemIndex) {
      case R.id.ItemMenuBorrar:
        OrmLiteSqliteOpenHelper helper = null;
        try {
          helper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
          Dao<Interes, Integer> interesesDao = helper.getDao(Interes.class);
          interesesDao.delete(interes);
          interesesAdapter.remove(interes);
        } catch (Exception e) {
          Log.e(TAG, "Error al listar los intereses", e);
          GuiUtils.mostrarToast(this, R.string.operacion_error, null);
        } finally {
          try {
            OpenHelperManager.releaseHelper();
          } catch (Exception e2) {
          }
        }

        return true;
      case R.id.ItemMenuEditar:
        mostrarDatosInteres(interes);
        return true;
      default:
        return super.onContextItemSelected(item);
    }
  }
示例#2
0
  public static void saveToDatabase(Context context, final List<Account> items) {
    final DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);

    try {
      final Dao<Account, String> dao = helper.getAccountDao();
      dao.callBatchTasks(
          new Callable<Void>() {

            public Void call() throws Exception {
              // Delete all
              int removed = dao.delete(dao.deleteBuilder().prepare());
              if (Flags.DEBUG) {
                Log.d(LOG_TAG, "Deleted " + removed + " from database");
              }

              for (Account item : items) {
                dao.create(item);
              }
              if (Flags.DEBUG) {
                Log.d(LOG_TAG, "Inserted " + items.size() + " into database");
              }
              return null;
            }
          });
    } catch (Exception e) {
      if (Flags.DEBUG) {
        e.printStackTrace();
      }
    } finally {
      OpenHelperManager.releaseHelper();
    }
  }
  @Test
  public void addOneSideEntity_ClearCacheQueryForAllThenGetEntity_EntityGottenIsNowCached()
      throws Exception {
    RelationEntities.LazyOneSide oneSide = new RelationEntities.LazyOneSide("One");
    oneSideDao.create(oneSide);

    RelationEntities.LazyManySide manySide1 = new RelationEntities.LazyManySide("Many 1");
    RelationEntities.LazyManySide manySide2 = new RelationEntities.LazyManySide("Many 2");
    RelationEntities.LazyManySide manySide3 = new RelationEntities.LazyManySide("Many 3");
    RelationEntities.LazyManySide manySide4 = new RelationEntities.LazyManySide("Many 4");
    RelationEntities.LazyManySide manySide5 = new RelationEntities.LazyManySide("Many 5");

    oneSide.getManySides().add(manySide1);
    oneSide.getManySides().add(manySide2);
    oneSide.getManySides().add(manySide3);
    oneSide.getManySides().add(manySide4);
    oneSide.getManySides().add(manySide5);

    oneSideDao.clearObjectCache();
    manySideDao.clearObjectCache();

    RelationEntities.LazyOneSide persistedOneSide = oneSideDao.queryForId(oneSide.getId());
    OpenLazyLoadingEntitiesCollection persistedManySides =
        (OpenLazyLoadingEntitiesCollection) persistedOneSide.getManySides();
    RelationEntities.LazyManySide anyEntity = persistedOneSide.getManySides().get(0);

    Assert.assertEquals(1, persistedManySides.getCachedEntities().size());
    Assert.assertTrue(persistedManySides.getCachedEntities().containsValue(anyEntity));
  }
  @Test
  public void addOneSideEntity_TestIfCachingIsWorking() throws Exception {
    RelationEntities.LazyOneSide oneSide = new RelationEntities.LazyOneSide("One");
    oneSideDao.create(oneSide);

    RelationEntities.LazyManySide manySide1 = new RelationEntities.LazyManySide("Many 1");
    RelationEntities.LazyManySide manySide2 = new RelationEntities.LazyManySide("Many 2");
    RelationEntities.LazyManySide manySide3 = new RelationEntities.LazyManySide("Many 3");

    oneSide.getManySides().add(manySide1);
    oneSide.getManySides().add(manySide2);
    oneSide.getManySides().add(manySide3);

    int iteration = 0;
    while (iteration < 5) { // test if also after 5 iterations objects are the same
      RelationEntities.LazyOneSide persistedOneSide = oneSideDao.queryForId(oneSide.getId());
      Assert.assertSame(oneSide, persistedOneSide);

      Assert.assertSame(oneSide.getManySides().get(0), manySideDao.queryForId(manySide1.getId()));
      Assert.assertSame(oneSide.getManySides().get(1), manySideDao.queryForId(manySide2.getId()));
      Assert.assertSame(oneSide.getManySides().get(2), manySideDao.queryForId(manySide3.getId()));

      iteration++;
    }
  }
 public void updateCompany(CompanyDTO dto) throws Exception {
   Company company = getCompany(dto.id);
   validate(dto);
   List<String> beneficiaryIds =
       company
           .getBeneficiaries()
           .stream()
           .map(beneficiary -> beneficiary.getId().toString())
           .collect(Collectors.toList());
   for (BeneficiaryDTO beneDTO : dto.beneficiaries) {
     Beneficiary bene = new Beneficiary(beneDTO.name, company);
     Integer id = beneDTO.id;
     if (id != null) {
       bene.setId(id);
       String idString = id.toString();
       if (!beneDao.idExists(idString)) {
         throw new RequestException("beneficiary with id %s does not exist", id);
       }
       beneDao.update(bene);
       beneficiaryIds.remove(idString);
     } else {
       beneDao.create(bene);
     }
   }
   if (beneficiaryIds.size() > 0) {
     beneDao.deleteIds(beneficiaryIds);
   }
   company = JsonUtil.fromJson(dto.toJson(), Company.class);
   dao.update(company);
 }
示例#6
0
    @Override
    protected List<String> doInBackground(Void... params) {
      List<String> SpotNames = new ArrayList<String>();

      try {

        // if(act != null)
        // {
        Log.d(LOG_TAG, "Getting DB");
        Dao<SurfDataPointBase, Integer> surfDataPointBaseDao =
            getHelper().getSurfDataPointBaseDao();
        // Log.d(LOG_TAG, "Got instance of DB inside fragment.");

        List<SurfDataPointBase> pointList = surfDataPointBaseDao.queryForAll();

        Log.d(LOG_TAG, "Adding Spot Names");
        for (SurfDataPointBase s : pointList) {
          if (!SpotNames.contains(s.getSpotName())) {
            Log.d(LOG_TAG, "Adding " + s.getSpotName() + " to the spot name box.");
            SpotNames.add(s.getSpotName());
          }
        }
        // }

      } catch (SQLException e) {
        Log.d(LOG_TAG, "Sql Exception", e);
        e.printStackTrace();
      }

      return SpotNames;
    }
示例#7
0
  @Override
  public List<Lecture> save(List<Lecture> lectures) {
    try {
      Dao<Lecture, Integer> lDao = getDao();
      Dao<Speaker, Integer> sDao = getSpeakerDao();
      Dao<LectureSpeaker, Integer> lsDao = getLectureSpeakerDao();
      Dao<Category, Integer> cDao = getCategoryDao();
      Dao<Place, Integer> pDao = getPlaceDao();

      for (Lecture lecture : lectures) {
        pDao.createIfNotExists(lecture.getPlace());
        cDao.createIfNotExists(lecture.getCategory());

        lecture.setUserFavorite(false);
        lDao.createIfNotExists(lecture);
        for (Speaker s1 : lecture.getSpeakers()) {
          Speaker s2 = sDao.createIfNotExists(s1);
          lsDao.create(new LectureSpeaker(lecture, s2));
        }
      }
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
    return lectures;
  }
  @Test
  public void testUtf8() throws Exception {
    Dao<Foo, Integer> dao = createDao(Foo.class, true);

    Foo foo = new Foo();
    foo.stringField = "اعصاب";
    assertEquals(1, dao.create(foo));

    QueryBuilder<Foo, Integer> qb = dao.queryBuilder();

    List<Foo> results =
        qb.where().like(Foo.STRING_COLUMN_NAME, '%' + foo.stringField + '%').query();
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals(foo.id, results.get(0).id);
    assertEquals(foo.stringField, results.get(0).stringField);

    qb.reset();
    results =
        qb.where().like(Foo.STRING_COLUMN_NAME, new SelectArg('%' + foo.stringField + '%')).query();
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals(foo.id, results.get(0).id);
    assertEquals(foo.stringField, results.get(0).stringField);
  }
示例#9
0
  public List<Remind> getStoredData(int filter) {
    try {
      switch (filter) {
        case DatabaseHelper.FILTER_ALL_REMINDS:
          return SortUtil.sort(remindDao.queryForAll(), PreferenceUtil.getUsedSortMode());

        case DatabaseHelper.FILTER_WAITING_REMINDS:
          return SortUtil.sort(
              remindDao
                  .queryBuilder()
                  .where()
                  .eq(DatabaseHelper.COLUMN_STATUS, RemindUtil.STATUS_WAIT)
                  .query(),
              PreferenceUtil.getUsedSortMode());

        case DatabaseHelper.FILTER_DONE_REMINDS:
          return SortUtil.sort(
              remindDao
                  .queryBuilder()
                  .where()
                  .eq(DatabaseHelper.COLUMN_STATUS, RemindUtil.STATUS_DONE)
                  .query(),
              PreferenceUtil.getUsedSortMode());
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return null;
  }
 @Test
 public void testOrderByRawArg() throws Exception {
   Dao<Foo, Integer> dao = createDao(Foo.class, true);
   Foo foo1 = new Foo();
   foo1.val = 1;
   assertEquals(1, dao.create(foo1));
   Foo foo2 = new Foo();
   foo2.val = 2;
   assertEquals(1, dao.create(foo2));
   List<Foo> results =
       dao.queryBuilder()
           .orderByRaw(
               "(" + Foo.VAL_COLUMN_NAME + " = ? ) DESC", new SelectArg(SqlType.INTEGER, 2))
           .query();
   assertEquals(2, results.size());
   assertEquals(foo2.id, results.get(0).id);
   assertEquals(foo1.id, results.get(1).id);
   results =
       dao.queryBuilder()
           .orderByRaw("(" + Foo.VAL_COLUMN_NAME + " = ? )", new SelectArg(SqlType.INTEGER, 2))
           .query();
   assertEquals(2, results.size());
   assertEquals(foo1.id, results.get(0).id);
   assertEquals(foo2.id, results.get(1).id);
 }
  @DefaultHandler
  public Resolution defaultResolution() throws AjaxException {
    log.info("FiltersDataAction");
    try {
      conn = EntityManager.getConnection();
      Dao<Filter, String> dao = DaoManager.createDao(conn, Filter.class);

      String string =
          new ObjectMapper()
              .configure(Feature.DEFAULT_VIEW_INCLUSION, false)
              .writerWithView(JsonViews.Filters.class)
              .writeValueAsString(dao.queryForEq("views_id", getView().getId()));

      log.info(string);
      return new StreamingResolution("text/json", string);
    } catch (Exception e) {
      e.printStackTrace();
      getContext()
          .getValidationErrors()
          .add("entity", new SimpleError("unknown exception [" + e.getMessage() + "]"));
      throw new AjaxException(this, "filters", "data error");
    } finally {
      try {
        conn.close();
      } catch (SQLException e) {
      }
    }
  }
示例#12
0
  @Test
  public void testTableCreationAndPersist() throws SQLException, ClassNotFoundException {
    Class.forName("org.h2.Driver");
    String databaseUrl = "jdbc:h2:res\\test\\db\\ormLiteDb";
    ConnectionSource cs = new JdbcConnectionSource(databaseUrl);

    TableUtils.createTableIfNotExists(cs, Event.class);
    TableUtils.clearTable(cs, Event.class);

    int count = 10;
    String namePrefix = "Testinimi";
    Dao<Event, Integer> eventDao = DaoManager.createDao(cs, Event.class);

    for (int i = 0; i < count; i++) {
      Event event = new Event();
      event.setTitle(namePrefix + i);
      eventDao.create(event);
    }

    assertTrue(eventDao.countOf() == count);
    for (Iterator<Event> it = eventDao.iterator(); it.hasNext(); ) {
      Event event = it.next();
      assertTrue(event.getTitle().startsWith(namePrefix));
    }
    ;

    cs.close();
  }
  @Test
  public void
      addManySideEntities_ClearCacheAndQueryForAll_TestIfPersistedEntitiesMatchAddedOnesButDoNotEqual()
          throws Exception {
    RelationEntities.LazyOneSide oneSide1 = new RelationEntities.LazyOneSide("One 1");
    oneSideDao.create(oneSide1);

    RelationEntities.LazyOneSide oneSide2 = new RelationEntities.LazyOneSide("One 2");
    oneSideDao.create(oneSide2);

    RelationEntities.LazyManySide manySide1 = new RelationEntities.LazyManySide("Many 1");
    RelationEntities.LazyManySide manySide2 = new RelationEntities.LazyManySide("Many 2");
    RelationEntities.LazyManySide manySide3 = new RelationEntities.LazyManySide("Many 3");
    RelationEntities.LazyManySide manySide4 = new RelationEntities.LazyManySide("Many 4");
    RelationEntities.LazyManySide manySide5 = new RelationEntities.LazyManySide("Many 5");
    RelationEntities.LazyManySide manySide6 = new RelationEntities.LazyManySide("Many 6");

    oneSide1.getManySides().add(manySide1);
    oneSide1.getManySides().add(manySide2);
    oneSide1.getManySides().add(manySide3);

    oneSide2.getManySides().add(manySide4);
    oneSide2.getManySides().add(manySide5);
    oneSide2.getManySides().add(manySide6);

    oneSideDao.clearObjectCache();
    manySideDao.clearObjectCache();
    List<RelationEntities.LazyOneSide> persistedEntities = oneSideDao.queryForAll();

    Assert.assertEquals(2, persistedEntities.size());

    RelationEntities.LazyOneSide persistedOneSide1 = persistedEntities.get(0);
    RelationEntities.LazyOneSide persistedOneSide2 = persistedEntities.get(1);

    // assert ids are the same
    Assert.assertEquals(oneSide1.getId(), persistedOneSide1.getId());
    Assert.assertEquals(oneSide2.getId(), persistedOneSide2.getId());
    // but instances don't equal (otherwise they would have been just taken from cache)
    Assert.assertNotSame(oneSide1, persistedOneSide1);
    Assert.assertNotSame(oneSide2, persistedOneSide2);

    Assert.assertEquals(3, persistedOneSide1.getManySides().size());
    Assert.assertEquals(3, persistedOneSide2.getManySides().size());

    Assert.assertEquals(manySide1.getId(), persistedOneSide1.getManySides().get(0).getId());
    Assert.assertEquals(manySide2.getId(), persistedOneSide1.getManySides().get(1).getId());
    Assert.assertEquals(manySide3.getId(), persistedOneSide1.getManySides().get(2).getId());

    Assert.assertEquals(manySide4.getId(), persistedOneSide2.getManySides().get(0).getId());
    Assert.assertEquals(manySide5.getId(), persistedOneSide2.getManySides().get(1).getId());
    Assert.assertEquals(manySide6.getId(), persistedOneSide2.getManySides().get(2).getId());

    Assert.assertNotSame(manySide1, persistedOneSide1.getManySides().get(0));
    Assert.assertNotSame(manySide2, persistedOneSide1.getManySides().get(1));
    Assert.assertNotSame(manySide3, persistedOneSide1.getManySides().get(2));

    Assert.assertNotSame(manySide4, persistedOneSide2.getManySides().get(0));
    Assert.assertNotSame(manySide5, persistedOneSide2.getManySides().get(1));
    Assert.assertNotSame(manySide6, persistedOneSide2.getManySides().get(2));
  }
  public static void updateRowFromTable2(Context context, ObservationInstance sp) {
    Dao<ObservationInstance, Integer> dao;
    try {
      dao = DatabaseHelper.getInstance(context).getSaveParamsDao();
      UpdateBuilder<ObservationInstance, Integer> query = dao.updateBuilder();
      // query.updateColumnValue("group_id", sp.getGroupId());
      query.updateColumnValue("group", sp.getGroup());
      query.updateColumnValue("habitat_id", sp.getHabitatId());
      query.updateColumnValue("fromDate", sp.getFromDate());
      query.updateColumnValue("placeName", sp.getPlaceName());
      query.updateColumnValue("areas", sp.getAreas());
      query.updateColumnValue("maxVotedReco", sp.getMaxVotedReco());
      // query.updateColumnValue("recoName", sp.getRecoName());

      query.updateColumnValue("resource", sp.getResource());
      // query.updateColumnValue("image_type", sp.getImageType());
      query.updateColumnValue("status", sp.getStatus());
      query.updateColumnValue("message", sp.getMessage());
      query.updateColumnValue("notes", sp.getNotes());
      query.updateColumnValue("userGroupsList", sp.getUserGroupsList());
      if (sp.getId() == -1)
        query.where().eq("server_id", sp.getServer_id()).and().eq("id", sp.getId());
      else query.where().eq("id", sp.getId());
      int count = query.update();
      Log.d("ObservationParamTable", "Updated " + count + " orders");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public void addClientUser(TwitterSession twitterSession, CreateCompletedListener addedListener) {
   ConnectionSource connectionSource = null;
   try {
     DataBaseHelper helper = new DataBaseHelper(Global.getInstance().getApplicationContext());
     connectionSource = helper.getConnectionSource();
     TableUtils.createTableIfNotExists(connectionSource, ClientUserTable.class);
     Dao<ClientUserTable, String> dao = helper.getDao(ClientUserTable.class);
     ClientUserTable table1 = dao.queryForId("" + twitterSession.getUserId());
     if (table1 == null) {
       ClientUserTable table = new ClientUserTable(twitterSession);
       dao.createOrUpdate(table);
       new ClientUser(
           clientUsers.size(),
           twitterSession,
           clientUser -> {
             clientUsers.add(clientUser);
             addedListener.completed(clientUser);
           },
           TwitterException::printStackTrace);
     } else {
       addedListener.completed(null);
     }
   } catch (SQLException e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   } finally {
     if (connectionSource != null) {
       try {
         connectionSource.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
     }
   }
 }
示例#16
0
  @Override
  protected void onResume() {
    super.onResume();
    // 先数据库

    // 读取盒子信息
    Dao<BoxDBBean, Integer> daoBoxDBBean = null;
    List<BoxDBBean> list = null;
    try {
      daoBoxDBBean = DBTool.getDBHelper().getBoxDBBeanDao();
      list = daoBoxDBBean.queryForAll();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    initView(list);

    // 后网络
    GetBoxListBean bean = new GetBoxListBean();
    bean.setUser_id(userid);
    String sendDat = JSON.toJSONString(bean);
    HttpTranse Http = new HttpTranse();
    Http.TranseWithServer(
        this,
        "http://" + CookMasterApp.ServerIP + "/index.php/box_manager/get_list",
        sendDat,
        responseHandler);
  }
示例#17
0
  public static List<TodoItem> markOverdueItems() {
    List<TodoItem> items = new ArrayList<>();
    List<TodoItem> overdueItems = new ArrayList<>();

    final Dao<TodoItem, Integer> todoDao;
    try {
      todoDao = TodoApp.get().getDbHelper().getTodoDao();

      QueryBuilder<TodoItem, Integer> todoQb = todoDao.queryBuilder();
      PreparedQuery<TodoItem> preparedQuery =
          todoQb.where().eq(TodoEntry.COLUMN_STATE, TodoState.Undone).prepare();
      items = todoDao.query(preparedQuery);

      Date currentDate = new Date();
      for (TodoItem item : items) {
        if (item.getDue().before(currentDate)) {
          item.setState(TodoState.Overdue);
          createOrUpdateItem(item);
          overdueItems.add(item);
        }
      }

    } catch (SQLException e) {
      e.printStackTrace();
    }
    return overdueItems;
  }
 @Test
 public void testReservedWords() throws Exception {
   Dao<Reserved, Integer> dao = createDao(Reserved.class, true);
   QueryBuilder<Reserved, Integer> sb = dao.queryBuilder();
   sb.where().eq(Reserved.FIELD_NAME_GROUP, "something");
   sb.query();
 }
  private void updateCatagory() {

    final Dao<CatagoryModel, Integer> catagoryDoa;

    try {
      catagoryDoa = getHelper().getCatagoryDao();

      UpdateBuilder<CatagoryModel, Integer> updateBuilder = catagoryDoa.updateBuilder();
      updateBuilder.updateColumnValue("catagoryName", catagoryEditText.getText().toString());

      updateBuilder
          .where()
          .eq("categoryId", Integer.valueOf(catagoryModel.getCategoryId()))
          .and()
          .eq("catagoryName", catagoryModel.getCatagoryName());
      ;
      updateBuilder.update();

      Snackbar snackbar =
          Snackbar.make(view, "Catagory updated sucessfully!!", Snackbar.LENGTH_LONG);

      snackbar.show();

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
示例#20
0
  @Test
  public void testInsertLotsOfEvents() throws ClassNotFoundException, SQLException {
    Class.forName("org.h2.Driver");
    String databaseUrl = "jdbc:h2:res\\test\\db\\orm-event-test";
    ConnectionSource cs = new JdbcConnectionSource(databaseUrl);

    initDatabase(cs);

    Dao<Event, Integer> eventDao = DaoManager.createDao(cs, Event.class);
    Dao<EventArtist, Integer> eventArtistDao = DaoManager.createDao(cs, EventArtist.class);

    List<Event> events = getEvents();
    Set<String> artists = new HashSet<String>();

    for (Event event : events) {
      eventDao.create(event);
      /*
      for (Artist artist : event.getArtists()) {
          artistDao.createIfNotExists(artist);
          eventArtistDao.create(new EventArtist(event, artist));
          artists.add(artist.getName());
      }
      */
    }

    assertTrue(eventDao.countOf() == events.size());
    assertTrue(eventArtistDao.countOf() >= artists.size());
  }
示例#21
0
  public DownloadListOfTipSegResult downloadTipSeg() {

    ImageServices _service = new ImageServices();
    SoapServices service = new SoapServices(this.context);
    DownloadListOfTipSegResult result = service.getTipSeg();

    if (result.isSuccess()) {
      try {
        if (result.getData().size() > 0) {
          Dao<TipSeg, Integer> asDao = getHelper().getTipSegDao();
          TableUtils.clearTable(asDao.getConnectionSource(), TipSeg.class);

          for (TipSeg as : result.getData()) {
            // _service.saveImage(this.context, as.getImagen(),
            // _service.downloadImage(as.getImagen()));
            asDao.create(as);
          }
        } else {
          result.setErrorMessage("No hay tipos de seguros registrados.");
          result.setUpdateMessage(result.getErrorMessage());
          result.setSuccess(false);
        }

        return result;
      } catch (SQLException e) {
        e.printStackTrace();
        result.setData(null);
        result.setErrorMessage(e.getMessage());
        result.setSuccess(false);
        return result;
      }
    }
    return result;
  }
  @Test
  public void
      addOneSideEntity_ClearCacheQueryForAll_LazyCollectionRetrievedIdsButEntitiesNotCachedYet()
          throws Exception {
    RelationEntities.LazyOneSide oneSide = new RelationEntities.LazyOneSide("One");
    oneSideDao.create(oneSide);

    RelationEntities.LazyManySide manySide1 = new RelationEntities.LazyManySide("Many 1");
    RelationEntities.LazyManySide manySide2 = new RelationEntities.LazyManySide("Many 2");
    RelationEntities.LazyManySide manySide3 = new RelationEntities.LazyManySide("Many 3");
    RelationEntities.LazyManySide manySide4 = new RelationEntities.LazyManySide("Many 4");
    RelationEntities.LazyManySide manySide5 = new RelationEntities.LazyManySide("Many 5");

    oneSide.getManySides().add(manySide1);
    oneSide.getManySides().add(manySide2);
    oneSide.getManySides().add(manySide3);
    oneSide.getManySides().add(manySide4);
    oneSide.getManySides().add(manySide5);

    oneSideDao.clearObjectCache();
    manySideDao.clearObjectCache();

    RelationEntities.LazyOneSide persistedOneSide = oneSideDao.queryForId(oneSide.getId());
    OpenLazyLoadingEntitiesCollection persistedManySides =
        (OpenLazyLoadingEntitiesCollection) persistedOneSide.getManySides();

    Assert.assertEquals(
        oneSide.getManySides().size(), persistedManySides.getRetrievedIndices().size());
    Assert.assertEquals(0, persistedManySides.getCachedEntities().size());
  }
 @Test
 public void testBooleanObj() throws Exception {
   Class<LocalBooleanChar> clazz = LocalBooleanChar.class;
   Dao<LocalBooleanChar, Object> dao = createDao(clazz, true);
   boolean val = true;
   String valStr = Boolean.toString(val);
   LocalBooleanChar foo = new LocalBooleanChar();
   foo.bool = val;
   assertEquals(1, dao.create(foo));
   testType(
       dao,
       foo,
       clazz,
       val,
       '1',
       '1',
       valStr,
       DataType.BOOLEAN_CHAR,
       BOOLEAN_COLUMN,
       false,
       false,
       false,
       true,
       false,
       false,
       true,
       false);
 }
示例#24
0
 public void update(Lecture lecture) {
   try {
     Dao<Lecture, Integer> dao = getDao();
     dao.update(lecture);
   } catch (SQLException e) {
     throw new RuntimeException(e);
   }
 }
示例#25
0
 private <T, ID> void saveList(List<T> list, Class<T> clazz) throws SQLException {
   Dao<T, ID> dao = createDao(clazz);
   T data = null;
   for (int location = 0; location < list.size(); location++) {
     data = list.get(location);
     dao.createOrUpdate(data);
   }
 }
示例#26
0
 public static void deleteItem(TodoItem item) {
   try {
     final Dao<TodoItem, Integer> todoDao = TodoApp.get().getDbHelper().getTodoDao();
     todoDao.delete(item);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
示例#27
0
 public void cleanTipSeg() {
   try {
     Dao<TipSeg, Integer> asDao = getHelper().getTipSegDao();
     TableUtils.clearTable(asDao.getConnectionSource(), TipSeg.class);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
示例#28
0
 public Lecture getReference(int id) {
   try {
     Dao<Lecture, Integer> dao = getDao();
     return dao.queryForId(id);
   } catch (SQLException e) {
     throw new RuntimeException(e);
   }
 }
示例#29
0
  public void show() throws SQLException {
    Dao<Account, String> accountDao = connect();
    List<Account> list = accountDao.queryForAll();

    for (Account ball : list) System.out.println(ball.getText() + " " + ball.getPrioritet());

    connectionSource.close();
  }
 @Test(expected = SQLException.class)
 public void testQueryRawColumnsNotQuery() throws Exception {
   Dao<Foo, String> dao = createDao(Foo.class, true);
   QueryBuilder<Foo, String> qb = dao.queryBuilder();
   qb.selectRaw("COUNT(*)");
   // we can't get Foo objects with the COUNT(*)
   dao.query(qb.prepare());
 }