@Test public void testUpdateExisting() throws Exception { long pk = ServiceTestUtil.nextLong(); Release newRelease = _persistence.create(pk); newRelease.setMvccVersion(ServiceTestUtil.nextLong()); newRelease.setCreateDate(ServiceTestUtil.nextDate()); newRelease.setModifiedDate(ServiceTestUtil.nextDate()); newRelease.setServletContextName(ServiceTestUtil.randomString()); newRelease.setBuildNumber(ServiceTestUtil.nextInt()); newRelease.setBuildDate(ServiceTestUtil.nextDate()); newRelease.setVerified(ServiceTestUtil.randomBoolean()); newRelease.setState(ServiceTestUtil.nextInt()); newRelease.setTestString(ServiceTestUtil.randomString()); _persistence.update(newRelease); Release existingRelease = _persistence.findByPrimaryKey(newRelease.getPrimaryKey()); Assert.assertEquals(existingRelease.getMvccVersion(), newRelease.getMvccVersion()); Assert.assertEquals(existingRelease.getReleaseId(), newRelease.getReleaseId()); Assert.assertEquals( Time.getShortTimestamp(existingRelease.getCreateDate()), Time.getShortTimestamp(newRelease.getCreateDate())); Assert.assertEquals( Time.getShortTimestamp(existingRelease.getModifiedDate()), Time.getShortTimestamp(newRelease.getModifiedDate())); Assert.assertEquals( existingRelease.getServletContextName(), newRelease.getServletContextName()); Assert.assertEquals(existingRelease.getBuildNumber(), newRelease.getBuildNumber()); Assert.assertEquals( Time.getShortTimestamp(existingRelease.getBuildDate()), Time.getShortTimestamp(newRelease.getBuildDate())); Assert.assertEquals(existingRelease.getVerified(), newRelease.getVerified()); Assert.assertEquals(existingRelease.getState(), newRelease.getState()); Assert.assertEquals(existingRelease.getTestString(), newRelease.getTestString()); }
protected void cacheUniqueFindersCache(Release release) { if (release.isNew()) { Object[] args = new Object[] {release.getServletContextName()}; FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME, args, Long.valueOf(1)); FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME, args, release); } else { ReleaseModelImpl releaseModelImpl = (ReleaseModelImpl) release; if ((releaseModelImpl.getColumnBitmask() & FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME.getColumnBitmask()) != 0) { Object[] args = new Object[] {release.getServletContextName()}; FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME, args, Long.valueOf(1)); FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME, args, release); } } }
/** * Caches the release in the entity cache if it is enabled. * * @param release the release */ public void cacheResult(Release release) { EntityCacheUtil.putResult( ReleaseModelImpl.ENTITY_CACHE_ENABLED, ReleaseImpl.class, release.getPrimaryKey(), release); FinderCacheUtil.putResult( FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME, new Object[] {release.getServletContextName()}, release); release.resetOriginalValues(); }
protected void clearUniqueFindersCache(Release release) { ReleaseModelImpl releaseModelImpl = (ReleaseModelImpl) release; Object[] args = new Object[] {release.getServletContextName()}; FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME, args); FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME, args); if ((releaseModelImpl.getColumnBitmask() & FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME.getColumnBitmask()) != 0) { args = new Object[] {releaseModelImpl.getOriginalServletContextName()}; FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME, args); FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME, args); } }
protected Release toUnwrappedModel(Release release) { if (release instanceof ReleaseImpl) { return release; } ReleaseImpl releaseImpl = new ReleaseImpl(); releaseImpl.setNew(release.isNew()); releaseImpl.setPrimaryKey(release.getPrimaryKey()); releaseImpl.setReleaseId(release.getReleaseId()); releaseImpl.setCreateDate(release.getCreateDate()); releaseImpl.setModifiedDate(release.getModifiedDate()); releaseImpl.setServletContextName(release.getServletContextName()); releaseImpl.setBuildNumber(release.getBuildNumber()); releaseImpl.setBuildDate(release.getBuildDate()); releaseImpl.setVerified(release.isVerified()); releaseImpl.setState(release.getState()); releaseImpl.setTestString(release.getTestString()); return releaseImpl; }
/** * Returns the release where servletContextName = ? or returns <code>null</code> if it could * not be found, optionally using the finder cache. * * @param servletContextName the servlet context name * @param retrieveFromCache whether to use the finder cache * @return the matching release, or <code>null</code> if a matching release could not be found * @throws SystemException if a system exception occurred */ public Release fetchByServletContextName(String servletContextName, boolean retrieveFromCache) throws SystemException { Object[] finderArgs = new Object[] {servletContextName}; Object result = null; if (retrieveFromCache) { result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME, finderArgs, this); } if (result instanceof Release) { Release release = (Release) result; if (!Validator.equals(servletContextName, release.getServletContextName())) { result = null; } } if (result == null) { StringBundler query = new StringBundler(3); query.append(_SQL_SELECT_RELEASE_WHERE); boolean bindServletContextName = false; if (servletContextName == null) { query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1); } else if (servletContextName.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3); } else { bindServletContextName = true; query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindServletContextName) { qPos.add(servletContextName.toLowerCase()); } List<Release> list = q.list(); if (list.isEmpty()) { FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME, finderArgs, list); } else { Release release = list.get(0); result = release; cacheResult(release); if ((release.getServletContextName() == null) || !release.getServletContextName().equals(servletContextName)) { FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME, finderArgs, release); } } } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME, finderArgs); throw processException(e); } finally { closeSession(session); } } if (result instanceof List<?>) { return null; } else { return (Release) result; } }