/**
   * Creates a new org labor with the primary key. Does not add the org labor to the database.
   *
   * @param orgLaborId the primary key for the new org labor
   * @return the new org labor
   */
  public OrgLabor create(long orgLaborId) {
    OrgLabor orgLabor = new OrgLaborImpl();

    orgLabor.setNew(true);
    orgLabor.setPrimaryKey(orgLaborId);

    return orgLabor;
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    OrgLabor newOrgLabor = addOrgLabor();

    OrgLabor existingOrgLabor = _persistence.fetchByPrimaryKey(newOrgLabor.getPrimaryKey());

    Assert.assertEquals(existingOrgLabor, newOrgLabor);
  }
  /**
   * Caches the org labor in the entity cache if it is enabled.
   *
   * @param orgLabor the org labor
   */
  public void cacheResult(OrgLabor orgLabor) {
    EntityCacheUtil.putResult(
        OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
        OrgLaborImpl.class,
        orgLabor.getPrimaryKey(),
        orgLabor);

    orgLabor.resetOriginalValues();
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    OrgLabor orgLabor = _persistence.create(pk);

    Assert.assertNotNull(orgLabor);

    Assert.assertEquals(orgLabor.getPrimaryKey(), pk);
  }
  @Override
  public void clearCache(List<OrgLabor> orgLabors) {
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

    for (OrgLabor orgLabor : orgLabors) {
      EntityCacheUtil.removeResult(
          OrgLaborModelImpl.ENTITY_CACHE_ENABLED, OrgLaborImpl.class, orgLabor.getPrimaryKey());
    }
  }
  @Test
  public void testRemove() throws Exception {
    OrgLabor newOrgLabor = addOrgLabor();

    _persistence.remove(newOrgLabor);

    OrgLabor existingOrgLabor = _persistence.fetchByPrimaryKey(newOrgLabor.getPrimaryKey());

    Assert.assertNull(existingOrgLabor);
  }
  @Override
  public OrgLabor updateImpl(com.liferay.portal.model.OrgLabor orgLabor) throws SystemException {
    orgLabor = toUnwrappedModel(orgLabor);

    boolean isNew = orgLabor.isNew();

    OrgLaborModelImpl orgLaborModelImpl = (OrgLaborModelImpl) orgLabor;

    Session session = null;

    try {
      session = openSession();

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

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

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (isNew || !OrgLaborModelImpl.COLUMN_BITMASK_ENABLED) {
      FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else {
      if ((orgLaborModelImpl.getColumnBitmask()
              & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID.getColumnBitmask())
          != 0) {
        Object[] args = new Object[] {Long.valueOf(orgLaborModelImpl.getOriginalOrganizationId())};

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID, args);
        FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID, args);

        args = new Object[] {Long.valueOf(orgLaborModelImpl.getOrganizationId())};

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID, args);
        FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID, args);
      }
    }

    EntityCacheUtil.putResult(
        OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
        OrgLaborImpl.class,
        orgLabor.getPrimaryKey(),
        orgLabor);

    return orgLabor;
  }
 /**
  * Caches the org labors in the entity cache if it is enabled.
  *
  * @param orgLabors the org labors
  */
 public void cacheResult(List<OrgLabor> orgLabors) {
   for (OrgLabor orgLabor : orgLabors) {
     if (EntityCacheUtil.getResult(
             OrgLaborModelImpl.ENTITY_CACHE_ENABLED, OrgLaborImpl.class, orgLabor.getPrimaryKey())
         == null) {
       cacheResult(orgLabor);
     } else {
       orgLabor.resetOriginalValues();
     }
   }
 }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    OrgLabor newOrgLabor = addOrgLabor();

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

    primaryKeys.add(newOrgLabor.getPrimaryKey());

    Map<Serializable, OrgLabor> orgLabors = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, orgLabors.size());
    Assert.assertEquals(newOrgLabor, orgLabors.get(newOrgLabor.getPrimaryKey()));
  }
  @Override
  protected OrgLabor removeImpl(OrgLabor orgLabor) throws SystemException {
    orgLabor = toUnwrappedModel(orgLabor);

    Session session = null;

    try {
      session = openSession();

      if (!session.contains(orgLabor)) {
        orgLabor = (OrgLabor) session.get(OrgLaborImpl.class, orgLabor.getPrimaryKeyObj());
      }

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

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

    return orgLabor;
  }
  /**
   * Adds the org labor to the database. Also notifies the appropriate model listeners.
   *
   * @param orgLabor the org labor
   * @return the org labor that was added
   */
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public OrgLabor addOrgLabor(OrgLabor orgLabor) {
    orgLabor.setNew(true);

    return orgLaborPersistence.update(orgLabor);
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    OrgLabor newOrgLabor = addOrgLabor();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(OrgLabor.class, _dynamicQueryClassLoader);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("orgLaborId", newOrgLabor.getOrgLaborId()));

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

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

    OrgLabor existingOrgLabor = result.get(0);

    Assert.assertEquals(existingOrgLabor, newOrgLabor);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    OrgLabor newOrgLabor = addOrgLabor();

    long pk = RandomTestUtil.nextLong();

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

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

    Map<Serializable, OrgLabor> orgLabors = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, orgLabors.size());
    Assert.assertEquals(newOrgLabor, orgLabors.get(newOrgLabor.getPrimaryKey()));
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    OrgLabor newOrgLabor = addOrgLabor();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(OrgLabor.class, _dynamicQueryClassLoader);

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

    Object newOrgLaborId = newOrgLabor.getOrgLaborId();

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

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

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

    Object existingOrgLaborId = result.get(0);

    Assert.assertEquals(existingOrgLaborId, newOrgLaborId);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    OrgLabor newOrgLabor1 = addOrgLabor();
    OrgLabor newOrgLabor2 = addOrgLabor();

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

    primaryKeys.add(newOrgLabor1.getPrimaryKey());
    primaryKeys.add(newOrgLabor2.getPrimaryKey());

    Map<Serializable, OrgLabor> orgLabors = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, orgLabors.size());
    Assert.assertEquals(newOrgLabor1, orgLabors.get(newOrgLabor1.getPrimaryKey()));
    Assert.assertEquals(newOrgLabor2, orgLabors.get(newOrgLabor2.getPrimaryKey()));
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    OrgLabor newOrgLabor = _persistence.create(pk);

    newOrgLabor.setMvccVersion(RandomTestUtil.nextLong());

    newOrgLabor.setCompanyId(RandomTestUtil.nextLong());

    newOrgLabor.setOrganizationId(RandomTestUtil.nextLong());

    newOrgLabor.setTypeId(RandomTestUtil.nextLong());

    newOrgLabor.setSunOpen(RandomTestUtil.nextInt());

    newOrgLabor.setSunClose(RandomTestUtil.nextInt());

    newOrgLabor.setMonOpen(RandomTestUtil.nextInt());

    newOrgLabor.setMonClose(RandomTestUtil.nextInt());

    newOrgLabor.setTueOpen(RandomTestUtil.nextInt());

    newOrgLabor.setTueClose(RandomTestUtil.nextInt());

    newOrgLabor.setWedOpen(RandomTestUtil.nextInt());

    newOrgLabor.setWedClose(RandomTestUtil.nextInt());

    newOrgLabor.setThuOpen(RandomTestUtil.nextInt());

    newOrgLabor.setThuClose(RandomTestUtil.nextInt());

    newOrgLabor.setFriOpen(RandomTestUtil.nextInt());

    newOrgLabor.setFriClose(RandomTestUtil.nextInt());

    newOrgLabor.setSatOpen(RandomTestUtil.nextInt());

    newOrgLabor.setSatClose(RandomTestUtil.nextInt());

    _orgLabors.add(_persistence.update(newOrgLabor));

    OrgLabor existingOrgLabor = _persistence.findByPrimaryKey(newOrgLabor.getPrimaryKey());

    Assert.assertEquals(existingOrgLabor.getMvccVersion(), newOrgLabor.getMvccVersion());
    Assert.assertEquals(existingOrgLabor.getOrgLaborId(), newOrgLabor.getOrgLaborId());
    Assert.assertEquals(existingOrgLabor.getCompanyId(), newOrgLabor.getCompanyId());
    Assert.assertEquals(existingOrgLabor.getOrganizationId(), newOrgLabor.getOrganizationId());
    Assert.assertEquals(existingOrgLabor.getTypeId(), newOrgLabor.getTypeId());
    Assert.assertEquals(existingOrgLabor.getSunOpen(), newOrgLabor.getSunOpen());
    Assert.assertEquals(existingOrgLabor.getSunClose(), newOrgLabor.getSunClose());
    Assert.assertEquals(existingOrgLabor.getMonOpen(), newOrgLabor.getMonOpen());
    Assert.assertEquals(existingOrgLabor.getMonClose(), newOrgLabor.getMonClose());
    Assert.assertEquals(existingOrgLabor.getTueOpen(), newOrgLabor.getTueOpen());
    Assert.assertEquals(existingOrgLabor.getTueClose(), newOrgLabor.getTueClose());
    Assert.assertEquals(existingOrgLabor.getWedOpen(), newOrgLabor.getWedOpen());
    Assert.assertEquals(existingOrgLabor.getWedClose(), newOrgLabor.getWedClose());
    Assert.assertEquals(existingOrgLabor.getThuOpen(), newOrgLabor.getThuOpen());
    Assert.assertEquals(existingOrgLabor.getThuClose(), newOrgLabor.getThuClose());
    Assert.assertEquals(existingOrgLabor.getFriOpen(), newOrgLabor.getFriOpen());
    Assert.assertEquals(existingOrgLabor.getFriClose(), newOrgLabor.getFriClose());
    Assert.assertEquals(existingOrgLabor.getSatOpen(), newOrgLabor.getSatOpen());
    Assert.assertEquals(existingOrgLabor.getSatClose(), newOrgLabor.getSatClose());
  }
  protected OrgLabor toUnwrappedModel(OrgLabor orgLabor) {
    if (orgLabor instanceof OrgLaborImpl) {
      return orgLabor;
    }

    OrgLaborImpl orgLaborImpl = new OrgLaborImpl();

    orgLaborImpl.setNew(orgLabor.isNew());
    orgLaborImpl.setPrimaryKey(orgLabor.getPrimaryKey());

    orgLaborImpl.setOrgLaborId(orgLabor.getOrgLaborId());
    orgLaborImpl.setOrganizationId(orgLabor.getOrganizationId());
    orgLaborImpl.setTypeId(orgLabor.getTypeId());
    orgLaborImpl.setSunOpen(orgLabor.getSunOpen());
    orgLaborImpl.setSunClose(orgLabor.getSunClose());
    orgLaborImpl.setMonOpen(orgLabor.getMonOpen());
    orgLaborImpl.setMonClose(orgLabor.getMonClose());
    orgLaborImpl.setTueOpen(orgLabor.getTueOpen());
    orgLaborImpl.setTueClose(orgLabor.getTueClose());
    orgLaborImpl.setWedOpen(orgLabor.getWedOpen());
    orgLaborImpl.setWedClose(orgLabor.getWedClose());
    orgLaborImpl.setThuOpen(orgLabor.getThuOpen());
    orgLaborImpl.setThuClose(orgLabor.getThuClose());
    orgLaborImpl.setFriOpen(orgLabor.getFriOpen());
    orgLaborImpl.setFriClose(orgLabor.getFriClose());
    orgLaborImpl.setSatOpen(orgLabor.getSatOpen());
    orgLaborImpl.setSatClose(orgLabor.getSatClose());

    return orgLaborImpl;
  }
  protected OrgLabor addOrgLabor() throws Exception {
    long pk = RandomTestUtil.nextLong();

    OrgLabor orgLabor = _persistence.create(pk);

    orgLabor.setMvccVersion(RandomTestUtil.nextLong());

    orgLabor.setCompanyId(RandomTestUtil.nextLong());

    orgLabor.setOrganizationId(RandomTestUtil.nextLong());

    orgLabor.setTypeId(RandomTestUtil.nextLong());

    orgLabor.setSunOpen(RandomTestUtil.nextInt());

    orgLabor.setSunClose(RandomTestUtil.nextInt());

    orgLabor.setMonOpen(RandomTestUtil.nextInt());

    orgLabor.setMonClose(RandomTestUtil.nextInt());

    orgLabor.setTueOpen(RandomTestUtil.nextInt());

    orgLabor.setTueClose(RandomTestUtil.nextInt());

    orgLabor.setWedOpen(RandomTestUtil.nextInt());

    orgLabor.setWedClose(RandomTestUtil.nextInt());

    orgLabor.setThuOpen(RandomTestUtil.nextInt());

    orgLabor.setThuClose(RandomTestUtil.nextInt());

    orgLabor.setFriOpen(RandomTestUtil.nextInt());

    orgLabor.setFriClose(RandomTestUtil.nextInt());

    orgLabor.setSatOpen(RandomTestUtil.nextInt());

    orgLabor.setSatClose(RandomTestUtil.nextInt());

    _orgLabors.add(_persistence.update(orgLabor));

    return orgLabor;
  }
  /**
   * Returns an ordered range of all the org labors where organizationId = &#63;.
   *
   * <p>Useful when paginating results. Returns a maximum of <code>end - start</code> instances.
   * <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result
   * set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start
   * </code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}
   * will return the full result set.
   *
   * @param organizationId the organization ID
   * @param start the lower bound of the range of org labors
   * @param end the upper bound of the range of org labors (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching org labors
   * @throws SystemException if a system exception occurred
   */
  public List<OrgLabor> findByOrganizationId(
      long organizationId, int start, int end, OrderByComparator orderByComparator)
      throws SystemException {
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
      finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID;
      finderArgs = new Object[] {organizationId};
    } else {
      finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ORGANIZATIONID;
      finderArgs = new Object[] {organizationId, start, end, orderByComparator};
    }

    List<OrgLabor> list = (List<OrgLabor>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
      for (OrgLabor orgLabor : list) {
        if ((organizationId != orgLabor.getOrganizationId())) {
          list = null;

          break;
        }
      }
    }

    if (list == null) {
      StringBundler query = null;

      if (orderByComparator != null) {
        query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 3));
      } else {
        query = new StringBundler(3);
      }

      query.append(_SQL_SELECT_ORGLABOR_WHERE);

      query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else {
        query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(organizationId);

        list = (List<OrgLabor>) QueryUtil.list(q, getDialect(), start, end);
      } catch (Exception e) {
        throw processException(e);
      } finally {
        if (list == null) {
          FinderCacheUtil.removeResult(finderPath, finderArgs);
        } else {
          cacheResult(list);

          FinderCacheUtil.putResult(finderPath, finderArgs, list);
        }

        closeSession(session);
      }
    }

    return list;
  }