@Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    VirtualHost newVirtualHost = addVirtualHost();

    _persistence.clearCache();

    VirtualHostModelImpl existingVirtualHostModelImpl =
        (VirtualHostModelImpl) _persistence.findByPrimaryKey(newVirtualHost.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingVirtualHostModelImpl.getHostname(),
            existingVirtualHostModelImpl.getOriginalHostname()));

    Assert.assertEquals(
        existingVirtualHostModelImpl.getCompanyId(),
        existingVirtualHostModelImpl.getOriginalCompanyId());
    Assert.assertEquals(
        existingVirtualHostModelImpl.getLayoutSetId(),
        existingVirtualHostModelImpl.getOriginalLayoutSetId());
  }
  @Test
  public void testFindByPrimaryKeyExisting() throws Exception {
    VirtualHost newVirtualHost = addVirtualHost();

    VirtualHost existingVirtualHost = _persistence.findByPrimaryKey(newVirtualHost.getPrimaryKey());

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

    VirtualHost virtualHost = _persistence.create(pk);

    Assert.assertNotNull(virtualHost);

    Assert.assertEquals(virtualHost.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    VirtualHost newVirtualHost = addVirtualHost();

    _persistence.remove(newVirtualHost);

    VirtualHost existingVirtualHost =
        _persistence.fetchByPrimaryKey(newVirtualHost.getPrimaryKey());

    Assert.assertNull(existingVirtualHost);
  }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    VirtualHost newVirtualHost = addVirtualHost();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newVirtualHost.getPrimaryKey());

    Map<Serializable, VirtualHost> virtualHosts = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, virtualHosts.size());
    Assert.assertEquals(newVirtualHost, virtualHosts.get(newVirtualHost.getPrimaryKey()));
  }
  protected VirtualHost addVirtualHost() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    VirtualHost virtualHost = _persistence.create(pk);

    virtualHost.setMvccVersion(ServiceTestUtil.nextLong());

    virtualHost.setCompanyId(ServiceTestUtil.nextLong());

    virtualHost.setLayoutSetId(ServiceTestUtil.nextLong());

    virtualHost.setHostname(ServiceTestUtil.randomString());

    _persistence.update(virtualHost);

    return virtualHost;
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    VirtualHost newVirtualHost = addVirtualHost();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newVirtualHost.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, VirtualHost> virtualHosts = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, virtualHosts.size());
    Assert.assertEquals(newVirtualHost, virtualHosts.get(newVirtualHost.getPrimaryKey()));
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    VirtualHost newVirtualHost = addVirtualHost();

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

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq("virtualHostId", newVirtualHost.getVirtualHostId()));

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

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

    VirtualHost existingVirtualHost = result.get(0);

    Assert.assertEquals(existingVirtualHost, newVirtualHost);
  }
  public int compareTo(VirtualHost virtualHost) {
    long primaryKey = virtualHost.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
示例#10
0
  @Override
  public String getVirtualHostname() {
    if (_virtualHostname != null) {
      return _virtualHostname;
    }

    try {
      VirtualHost virtualHost = VirtualHostLocalServiceUtil.fetchVirtualHost(getCompanyId(), 0);

      if (virtualHost == null) {
        _virtualHostname = StringPool.BLANK;
      } else {
        _virtualHostname = virtualHost.getHostname();
      }
    } catch (Exception e) {
      _virtualHostname = StringPool.BLANK;
    }

    return _virtualHostname;
  }
  public VirtualHost updateVirtualHost(long companyId, long layoutSetId, String hostname)
      throws SystemException {

    VirtualHost virtualHost = virtualHostPersistence.fetchByC_L(companyId, layoutSetId);

    if (virtualHost == null) {
      long virtualHostId = counterLocalService.increment();

      virtualHost = virtualHostPersistence.create(virtualHostId);

      virtualHost.setCompanyId(companyId);
      virtualHost.setLayoutSetId(layoutSetId);
    }

    virtualHost.setHostname(hostname);

    virtualHostPersistence.update(virtualHost, false);

    return virtualHost;
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    VirtualHost newVirtualHost = addVirtualHost();

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

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

    Object newVirtualHostId = newVirtualHost.getVirtualHostId();

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

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

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

    Object existingVirtualHostId = result.get(0);

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

    VirtualHost virtualHost = null;

    try {
      virtualHost = (VirtualHost) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = virtualHost.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
示例#14
0
  private long _getCompanyIdByVirtualHosts(HttpServletRequest request) {
    String host = PortalUtil.getHost(request);

    if (_log.isDebugEnabled()) {
      _log.debug("Host " + host);
    }

    if (Validator.isNull(host) || _isVirtualHostsIgnoreHost(host)) {
      return 0;
    }

    try {
      VirtualHost virtualHost = VirtualHostLocalServiceUtil.fetchVirtualHost(host);

      if (virtualHost == null) {
        return 0;
      }

      if (virtualHost.getLayoutSetId() != 0) {
        LayoutSet layoutSet = null;

        try {
          ShardUtil.pushCompanyService(virtualHost.getCompanyId());

          layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(virtualHost.getLayoutSetId());
        } finally {
          ShardUtil.popCompanyService();
        }

        if (_log.isDebugEnabled()) {
          _log.debug(
              "Company "
                  + virtualHost.getCompanyId()
                  + " is associated with layout set "
                  + virtualHost.getLayoutSetId());
        }

        request.setAttribute(WebKeys.VIRTUAL_HOST_LAYOUT_SET, layoutSet);
      }

      return virtualHost.getCompanyId();
    } catch (Exception e) {
      _log.error(e, e);
    }

    return 0;
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    VirtualHost newVirtualHost1 = addVirtualHost();
    VirtualHost newVirtualHost2 = addVirtualHost();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newVirtualHost1.getPrimaryKey());
    primaryKeys.add(newVirtualHost2.getPrimaryKey());

    Map<Serializable, VirtualHost> virtualHosts = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, virtualHosts.size());
    Assert.assertEquals(newVirtualHost1, virtualHosts.get(newVirtualHost1.getPrimaryKey()));
    Assert.assertEquals(newVirtualHost2, virtualHosts.get(newVirtualHost2.getPrimaryKey()));
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    VirtualHost newVirtualHost = _persistence.create(pk);

    newVirtualHost.setMvccVersion(ServiceTestUtil.nextLong());

    newVirtualHost.setCompanyId(ServiceTestUtil.nextLong());

    newVirtualHost.setLayoutSetId(ServiceTestUtil.nextLong());

    newVirtualHost.setHostname(ServiceTestUtil.randomString());

    _persistence.update(newVirtualHost);

    VirtualHost existingVirtualHost = _persistence.findByPrimaryKey(newVirtualHost.getPrimaryKey());

    Assert.assertEquals(existingVirtualHost.getMvccVersion(), newVirtualHost.getMvccVersion());
    Assert.assertEquals(existingVirtualHost.getVirtualHostId(), newVirtualHost.getVirtualHostId());
    Assert.assertEquals(existingVirtualHost.getCompanyId(), newVirtualHost.getCompanyId());
    Assert.assertEquals(existingVirtualHost.getLayoutSetId(), newVirtualHost.getLayoutSetId());
    Assert.assertEquals(existingVirtualHost.getHostname(), newVirtualHost.getHostname());
  }