public void createOrUpdate(Tdao tdao) { try { CreateOrUpdateStatus status = this.getDao().createOrUpdate(tdao); _logger.debug("CreateOrUpdate item:[{}],Create:{},Update:{},Lines Changed:{}", tdao, status.isCreated(), status.isUpdated(), status.getNumLinesChanged()); } catch (SQLException ex) { _logger.error("unable to CreateOrUpdate item:[{}]", tdao, ex); } }
@Override public void createOrUpdate(ResourcesGroup resourcesGroup) { try { CreateOrUpdateStatus status = this.getDao().createOrUpdate(resourcesGroup); _logger.debug("CreateOrUpdate ResourcesGroup:[{}],Create:{},Update:{},Lines Changed:{}", resourcesGroup, status.isCreated(), status.isUpdated(), status.getNumLinesChanged()); } catch (SQLException ex) { _logger.error("unable to CreateOrUpdate ResourcesGroup:[{}]", resourcesGroup, ex); } }
@Override public void createOrUpdate(ResourcesGroupMap resourcesGroupMap) { try { CreateOrUpdateStatus status = this.getDao().createOrUpdate(resourcesGroupMap); _logger.debug("CreateOrUpdate ResourcesGroupMap:[{}],Create:{},Update:{},Lines Changed:{}", resourcesGroupMap, status.isCreated(), status.isUpdated(), status.getNumLinesChanged()); } catch (SQLException ex) { _logger.error("unable to CreateOrUpdate ResourcesGroup:[{}]", resourcesGroupMap, ex); } }
@Test public void testCreateOrUpdateManualId() throws Exception { Dao<Child, Integer> childDao = createDao(Child.class, true); Dao<Parent, Object> parentDao = createDao(Parent.class, true); // this group doesn't exists in database Child child1 = new Child(); child1.id = 1; List<Parent> parents = new ArrayList<Parent>(); for (int i = 0; i < 5; i++) { Parent parent = new Parent(); parent.child = child1; parents.add(parent); } // this group doesn't exists in database Child child2 = new Child(); child2.id = 2; for (int i = 0; i < 5; i++) { Parent parent = new Parent(); parent.child = child2; parents.add(parent); } for (Parent parent : parents) { assertTrue(parentDao.createOrUpdate(parent).isCreated()); } assertEquals(0, childDao.countOf()); assertEquals(parents.size(), parentDao.countOf()); }
@Test public void testCreateOrUpdateMultiple2() throws Exception { Dao<Child, Integer> childDao = createDao(Child.class, true); Dao<Parent, Object> parentDao = createDao(Parent.class, true); Child child = new Child(); child.api_id = 1; // no create because of auto-create Parent parent1 = new Parent(); parent1.child = child; assertTrue(parentDao.createOrUpdate(parent1).isCreated()); Parent parent2 = new Parent(); parent2.child = child; assertTrue(parentDao.createOrUpdate(parent2).isCreated()); assertEquals(1, childDao.countOf()); List<Parent> results = parentDao.queryForAll(); assertNotNull(results); assertEquals(2, results.size()); Parent result = results.get(0); assertEquals(1, result.id); assertNotNull(result.child); assertEquals(child.id, result.child.id); result = results.get(1); assertEquals(2, result.id); assertNotNull(result.child); assertEquals(child.id, result.child.id); }
@Test public void testCreateOrUpdateMultipleLoop() throws Exception { Dao<Child, Integer> childDao = createDao(Child.class, true); Dao<Parent, Object> parentDao = createDao(Parent.class, true); Child child = new Child(); child.api_id = 1; // no create because of auto-create Parent[] parents = new Parent[10]; for (int i = 0; i < parents.length; i++) { parents[i] = new Parent(); parents[i].child = child; assertTrue(parentDao.createOrUpdate(parents[i]).isCreated()); } assertEquals(1, childDao.countOf()); assertEquals(10, parentDao.countOf()); for (int i = 0; i < parents.length; i++) { Parent result = parentDao.queryForId(parents[i].id); assertNotNull(result); assertNotNull(result.child); assertEquals(child.id, result.child.id); } }
@Test public void testCreateOrUpdateLoop() throws Exception { Dao<Question, Object> questionDao = createDao(Question.class, true); Dao<Answer, Object> answerDao = createDao(Answer.class, true); Answer answer = new Answer(); answer.val = 1234313123; assertEquals(1, answerDao.create(answer)); Question[] questions = new Question[10]; for (int i = 0; i < questions.length; i++) { // not failed questions[i] = new Question(); questions[i].name = "name_" + i; questions[i].bestAnswer = answer; assertTrue(questionDao.createOrUpdate(questions[i]).isCreated()); } for (int i = 0; i < questions.length; i++) { // not failed Question result = questionDao.queryForId(questions[i].id); assertNotNull(result); assertNotNull(result.bestAnswer); assertEquals(answer.id, result.bestAnswer.id); } }
@Test public void testCreateOrUpdateNullId() throws Exception { Dao<CreateOrUpdateObjectId, Integer> dao = createDao(CreateOrUpdateObjectId.class, true); CreateOrUpdateObjectId foo = new CreateOrUpdateObjectId(); String stuff = "21313"; foo.stuff = stuff; CreateOrUpdateStatus status = dao.createOrUpdate(foo); assertTrue(status.isCreated()); assertFalse(status.isUpdated()); assertEquals(1, status.getNumLinesChanged()); CreateOrUpdateObjectId result = dao.queryForId(foo.id); assertNotNull(result); assertEquals(stuff, result.stuff); String stuff2 = "pwojgfwe"; foo.stuff = stuff2; dao.createOrUpdate(foo); result = dao.queryForId(foo.id); assertNotNull(result); assertEquals(stuff2, result.stuff); }
@Test public void testCreateOrUpdate() throws Exception { Dao<NotQuiteFoo, Integer> dao = createDao(NotQuiteFoo.class, true); NotQuiteFoo foo1 = new NotQuiteFoo(); foo1.stuff = "wow"; CreateOrUpdateStatus status = dao.createOrUpdate(foo1); assertTrue(status.isCreated()); assertFalse(status.isUpdated()); assertEquals(1, status.getNumLinesChanged()); String stuff2 = "4134132"; foo1.stuff = stuff2; status = dao.createOrUpdate(foo1); assertFalse(status.isCreated()); assertTrue(status.isUpdated()); assertEquals(1, status.getNumLinesChanged()); NotQuiteFoo result = dao.queryForId(foo1.id); assertEquals(stuff2, result.stuff); }
@Test public void testCreateOrUpdateNullId() throws Exception { Dao<CreateOrUpdateObjectId, Integer> dao = createDao(CreateOrUpdateObjectId.class, true); CreateOrUpdateObjectId foo = new CreateOrUpdateObjectId(); String stuff = "21313"; foo.stuff = stuff; CreateOrUpdateStatus status = dao.createOrUpdate(foo); assertTrue(status.isCreated()); assertFalse(status.isUpdated()); assertEquals(1, status.getNumLinesChanged()); CreateOrUpdateObjectId result = dao.queryForId(foo.id); assertNotNull(result); assertEquals(stuff, result.stuff); String stuff2 = "pwojgfwe"; foo.stuff = stuff2; dao.createOrUpdate(foo); result = dao.queryForId(foo.id); assertNotNull(result); assertEquals(stuff2, result.stuff); }
@Test public void testCreateOrUpdateMultipleLoopManualId() throws Exception { Dao<Child, Integer> childDao = createDao(Child.class, true); Dao<Parent, Object> parentDao = createDao(Parent.class, true); // should have no entries assertEquals(0, childDao.countOf()); Parent[] parents = new Parent[10]; for (int i = 0; i < parents.length; i++) { parents[i] = new Parent(); Child child = new Child(); child.id = i + 1; parents[i].child = child; assertTrue(parentDao.createOrUpdate(parents[i]).isCreated()); } assertEquals(0, childDao.countOf()); assertEquals(10, parentDao.countOf()); }
@Test public void testCreateOrUpdate() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo1 = new Foo(); int equal1 = 21313; foo1.equal = equal1; CreateOrUpdateStatus status = dao.createOrUpdate(foo1); assertTrue(status.isCreated()); assertFalse(status.isUpdated()); assertEquals(1, status.getNumLinesChanged()); int equal2 = 4134132; foo1.equal = equal2; status = dao.createOrUpdate(foo1); assertFalse(status.isCreated()); assertTrue(status.isUpdated()); assertEquals(1, status.getNumLinesChanged()); Foo fooResult = dao.queryForId(foo1.id); assertEquals(equal2, fooResult.equal); }
@Override public void createOrUpdate(ResourcesGroupMap resourcesGroupMap) { try { CreateOrUpdateStatus status = this.getDao().createOrUpdate(resourcesGroupMap); _logger.debug("CreateOrUpdate ResourcesGroupMap:[{}],Create:{},Update:{},Lines Changed:{}", resourcesGroupMap, status.isCreated(), status.isUpdated(), status.getNumLinesChanged()); } catch (SQLException ex) { _logger.error("unable to CreateOrUpdate ResourcesGroup:[{}]", resourcesGroupMap, ex); throw new McDatabaseException(ex); } }
public void createOrUpdate(Tdao tdao) { try { CreateOrUpdateStatus status = this.getDao().createOrUpdate(tdao); _logger.debug("CreateOrUpdate item:[{}],Create:{},Update:{},Lines Changed:{}", tdao, status.isCreated(), status.isUpdated(), status.getNumLinesChanged()); } catch (SQLException ex) { _logger.error("unable to CreateOrUpdate item:[{}]", tdao, ex); throw new McDatabaseException(ex); } }
@Override public void createOrUpdate(UserSettings userSettings) { try { CreateOrUpdateStatus status = this.getDao().createOrUpdate(userSettings); _logger.debug("CreateOrUpdate UserSettings:[{}],Create:{},Update:{},Lines Changed:{}", userSettings, status.isCreated(), status.isUpdated(), status.getNumLinesChanged()); } catch (SQLException ex) { _logger.error("unable to CreateOrUpdate UserSettings:[{}]", userSettings, ex); } }
@Override public void createOrUpdate(Object object, boolean notify) { try { Dao.CreateOrUpdateStatus status = dao.createOrUpdate((T) object); if (notify) { notifyObservers((T) object, status.isCreated() ? CREATE_ACTION : UPDATE_ACTION); } } catch (SQLException e) { ErrorUtils.logError(TAG, "createOrUpdate(Object) - " + e.getMessage()); } }
@Test public void testCreateOrUpdateNull() throws Exception { Dao<Foo, String> dao = createDao(Foo.class, true); CreateOrUpdateStatus status = dao.createOrUpdate(null); assertFalse(status.isCreated()); assertFalse(status.isUpdated()); assertEquals(0, status.getNumLinesChanged()); }
@Override public void createOrUpdate(UserSettings userSettings) { try { CreateOrUpdateStatus status = this.getDao().createOrUpdate(userSettings); _logger.debug("CreateOrUpdate UserSettings:[{}],Create:{},Update:{},Lines Changed:{}", userSettings, status.isCreated(), status.isUpdated(), status.getNumLinesChanged()); } catch (SQLException ex) { _logger.error("unable to CreateOrUpdate UserSettings:[{}]", userSettings, ex); throw new McDatabaseException(ex); } }
@Override public void createOrUpdate(ResourcesGroup resourcesGroup) { try { CreateOrUpdateStatus status = this.getDao().createOrUpdate(resourcesGroup); _logger.debug("CreateOrUpdate ResourcesGroup:[{}],Create:{},Update:{},Lines Changed:{}", resourcesGroup, status.isCreated(), status.isUpdated(), status.getNumLinesChanged()); } catch (SQLException ex) { _logger.error("unable to CreateOrUpdate ResourcesGroup:[{}]", resourcesGroup, ex); throw new McDatabaseException(ex); } }
@Test public void testCreateOrUpdateNull() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); CreateOrUpdateStatus status = dao.createOrUpdate(null); assertFalse(status.isCreated()); assertFalse(status.isUpdated()); assertEquals(0, status.getNumLinesChanged()); }