protected Release addRelease() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    Release release = _persistence.create(pk);

    release.setMvccVersion(ServiceTestUtil.nextLong());

    release.setCreateDate(ServiceTestUtil.nextDate());

    release.setModifiedDate(ServiceTestUtil.nextDate());

    release.setServletContextName(ServiceTestUtil.randomString());

    release.setBuildNumber(ServiceTestUtil.nextInt());

    release.setBuildDate(ServiceTestUtil.nextDate());

    release.setVerified(ServiceTestUtil.randomBoolean());

    release.setState(ServiceTestUtil.nextInt());

    release.setTestString(ServiceTestUtil.randomString());

    _persistence.update(release);

    return release;
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    Release newRelease = addRelease();

    Release existingRelease = _persistence.fetchByPrimaryKey(newRelease.getPrimaryKey());

    Assert.assertEquals(existingRelease, newRelease);
  }
Esempio n. 3
0
  /**
   * Creates a new release with the primary key. Does not add the release to the database.
   *
   * @param releaseId the primary key for the new release
   * @return the new release
   */
  public Release create(long releaseId) {
    Release release = new ReleaseImpl();

    release.setNew(true);
    release.setPrimaryKey(releaseId);

    return release;
  }
  @Test
  public void shouldInjectReleaseLocalService() {
    Assert.assertNotNull(_releaseLocalService);

    Release releasePortal = _releaseLocalService.fetchRelease("portal");

    Assert.assertEquals(7000, releasePortal.getBuildNumber());
  }
  @Test
  public void testCreate() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    Release release = _persistence.create(pk);

    Assert.assertNotNull(release);

    Assert.assertEquals(release.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    Release newRelease = addRelease();

    _persistence.remove(newRelease);

    Release existingRelease = _persistence.fetchByPrimaryKey(newRelease.getPrimaryKey());

    Assert.assertNull(existingRelease);
  }
Esempio n. 7
0
 /**
  * Caches the releases in the entity cache if it is enabled.
  *
  * @param releases the releases
  */
 public void cacheResult(List<Release> releases) {
   for (Release release : releases) {
     if (EntityCacheUtil.getResult(
             ReleaseModelImpl.ENTITY_CACHE_ENABLED, ReleaseImpl.class, release.getPrimaryKey())
         == null) {
       cacheResult(release);
     } else {
       release.resetOriginalValues();
     }
   }
 }
Esempio n. 8
0
  /**
   * 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();
  }
Esempio n. 9
0
  @Override
  public void clearCache(List<Release> releases) {
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

    for (Release release : releases) {
      EntityCacheUtil.removeResult(
          ReleaseModelImpl.ENTITY_CACHE_ENABLED, ReleaseImpl.class, release.getPrimaryKey());

      clearUniqueFindersCache(release);
    }
  }
Esempio n. 10
0
  @Override
  protected Release removeImpl(Release release) throws SystemException {
    release = toUnwrappedModel(release);

    Session session = null;

    try {
      session = openSession();

      if (!session.contains(release)) {
        release = (Release) session.get(ReleaseImpl.class, release.getPrimaryKeyObj());
      }

      if (release != null) {
        session.delete(release);
      }
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    if (release != null) {
      clearCache(release);
    }

    return release;
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    Release newRelease = addRelease();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Release.class, Release.class.getClassLoader());

    dynamicQuery.add(RestrictionsFactoryUtil.eq("releaseId", newRelease.getReleaseId()));

    List<Release> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Release existingRelease = result.get(0);

    Assert.assertEquals(existingRelease, newRelease);
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    Release newRelease = addRelease();

    _persistence.clearCache();

    ReleaseModelImpl existingReleaseModelImpl =
        (ReleaseModelImpl) _persistence.findByPrimaryKey(newRelease.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingReleaseModelImpl.getServletContextName(),
            existingReleaseModelImpl.getOriginalServletContextName()));
  }
Esempio n. 13
0
  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);
      }
    }
  }
  public int compareTo(Release release) {
    long primaryKey = release.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    Release newRelease = addRelease();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Release.class, Release.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("releaseId"));

    Object newReleaseId = newRelease.getReleaseId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("releaseId", new Object[] {newReleaseId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingReleaseId = result.get(0);

    Assert.assertEquals(existingReleaseId, newReleaseId);
  }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    Release release = null;

    try {
      release = (Release) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = release.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
Esempio n. 17
0
  @Override
  public Release updateImpl(com.liferay.portal.model.Release release) throws SystemException {
    release = toUnwrappedModel(release);

    boolean isNew = release.isNew();

    Session session = null;

    try {
      session = openSession();

      if (release.isNew()) {
        session.save(release);

        release.setNew(false);
      } else {
        session.merge(release);
      }
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (isNew || !ReleaseModelImpl.COLUMN_BITMASK_ENABLED) {
      FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    EntityCacheUtil.putResult(
        ReleaseModelImpl.ENTITY_CACHE_ENABLED, ReleaseImpl.class, release.getPrimaryKey(), release);

    clearUniqueFindersCache(release);
    cacheUniqueFindersCache(release);

    return release;
  }
Esempio n. 18
0
  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);
    }
  }
  @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());
  }
Esempio n. 20
0
  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;
  }
Esempio n. 21
0
  public static void verify() throws Exception {

    // Check release

    Release release = null;

    try {
      release =
          ReleaseLocalServiceUtil.getRelease(
              ReleaseConstants.DEFAULT_SERVLET_CONTEXT_NAME, ReleaseInfo.getParentBuildNumber());
    } catch (PortalException pe) {
      release =
          ReleaseLocalServiceUtil.addRelease(
              ReleaseConstants.DEFAULT_SERVLET_CONTEXT_NAME, ReleaseInfo.getParentBuildNumber());
    }

    _checkReleaseState();

    // Update indexes

    if (PropsValues.DATABASE_INDEXES_UPDATE_ON_STARTUP) {
      StartupHelperUtil.setDropIndexes(true);

      StartupHelperUtil.updateIndexes();
    } else if (StartupHelperUtil.isUpgraded()) {
      StartupHelperUtil.updateIndexes();
    }

    // Verify

    if (PropsValues.VERIFY_DATABASE_TRANSACTIONS_DISABLED) {
      _disableTransactions();
    }

    try {
      StartupHelperUtil.verifyProcess(release.isVerified());
    } catch (Exception e) {
      _updateReleaseState(ReleaseConstants.STATE_VERIFY_FAILURE);

      throw e;
    } finally {
      if (PropsValues.VERIFY_DATABASE_TRANSACTIONS_DISABLED) {
        _enableTransactions();
      }
    }

    // Update indexes

    if (PropsValues.DATABASE_INDEXES_UPDATE_ON_STARTUP || StartupHelperUtil.isUpgraded()) {

      StartupHelperUtil.updateIndexes(false);
    }

    // Update release

    boolean verified = StartupHelperUtil.isVerified();

    if (release.isVerified()) {
      verified = true;
    }

    ReleaseLocalServiceUtil.updateRelease(
        release.getReleaseId(),
        ReleaseInfo.getParentBuildNumber(),
        ReleaseInfo.getBuildDate(),
        verified);

    // Enable database caching after verify

    CacheRegistryUtil.setActive(true);
  }
Esempio n. 22
0
  /**
   * Returns the release where servletContextName = &#63; 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;
    }
  }