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(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); } }
assertTrue(status.isUpdated());
@Override public void onDownloadFileUpdated(DownloadFileInfo downloadFileInfo, Type type) { if (downloadFileInfo != null && downloadFileInfo.getUrl() != null && downloadFileInfo.getUrl().equals (mCourseUrl)) { if (this.mDownloadFileInfo == null) { try { if (mCourseDbHelper == null) { return; } UpdateBuilder builder = mCourseDbHelper.getDao(CoursePreviewInfo.class).updateBuilder(); builder.where().eq(CoursePreviewInfo.COLUMN_NAME_OF_FIELD_COURSE_URL, downloadFileInfo.getUrl()); int result = builder.update(); if (result == 1) { this.mDownloadFileInfo = downloadFileInfo; } else { Dao<CoursePreviewInfo, Integer> dao = mCourseDbHelper.getDao(CoursePreviewInfo.class); CreateOrUpdateStatus status = dao.createOrUpdate(this); if (status.isCreated() || status.isUpdated()) { this.mDownloadFileInfo = downloadFileInfo; } } } catch (SQLException e) { e.printStackTrace(); } } } }
@Override public void onDownloadFileCreated(DownloadFileInfo downloadFileInfo) { if (downloadFileInfo != null && downloadFileInfo.getUrl() != null && downloadFileInfo.getUrl().equals (mCourseUrl)) { // add this CoursePreviewInfo in database download record // // the reason why to save this CoursePreviewInfo in course database is // that when the user enter the CourseDownloadFragment,the fragment need to show the course title to the // user,however the DownloadFileInfo in FileDownloader can not provide the course title,also the fragment // need to know how many course items need to show,so it is depends on the size of the course database, // because FileDownloader is just a tool to download, record and manage all the files which were // downloaded from the internet try { if (mCourseDbHelper == null) { return; } Dao<CoursePreviewInfo, Integer> dao = mCourseDbHelper.getDao(CoursePreviewInfo.class); CreateOrUpdateStatus status = dao.createOrUpdate(this); if (status.isCreated() || status.isUpdated()) { this.mDownloadFileInfo = downloadFileInfo; } } catch (SQLException e) { e.printStackTrace(); } } }
@Test public void testVersionFieldInsertOrUpdate() throws Exception { Dao<VersionField, Integer> dao = createDao(VersionField.class, true); VersionField foo1 = new VersionField(); assertEquals(1, dao.create(foo1)); assertEquals(1, foo1.id); assertEquals(0, foo1.version); CreateOrUpdateStatus status = dao.createOrUpdate(foo1); assertTrue(status.isUpdated()); assertEquals(1, status.getNumLinesChanged()); assertEquals(1, foo1.version); status = dao.createOrUpdate(foo1); assertTrue(status.isUpdated()); assertEquals(1, status.getNumLinesChanged()); assertEquals(2, foo1.version); VersionField result = dao.queryForId(foo1.id); // we update this one to a new version number assertEquals(1, dao.update(result)); assertEquals(3, result.version); // the old one doesn't change assertEquals(2, foo1.version); // but when we try to update the earlier foo, the version doesn't match assertEquals(0, dao.update(foo1)); }
/** * Create or update the tile scaling * * @param tileScaling * tile scaling * @return true upon success */ public boolean createOrUpdate(TileScaling tileScaling) { boolean success = false; tileScaling.setTableName(tableName); getOrCreateExtension(); try { if (!tileScalingDao.isTableExists()) { geoPackage.createTileScalingTable(); } CreateOrUpdateStatus status = tileScalingDao .createOrUpdate(tileScaling); success = status.isCreated() || status.isUpdated(); } catch (SQLException e) { throw new GeoPackageException( "Failed to create or update tile scaling for GeoPackage: " + geoPackage.getName() + ", Tile Table: " + tableName, e); } return success; }
@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 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); }
@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); }
@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(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 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()); }