protected Account toUnwrappedModel(Account account) {
    if (account instanceof AccountImpl) {
      return account;
    }

    AccountImpl accountImpl = new AccountImpl();

    accountImpl.setNew(account.isNew());
    accountImpl.setPrimaryKey(account.getPrimaryKey());

    accountImpl.setAccountId(account.getAccountId());
    accountImpl.setCompanyId(account.getCompanyId());
    accountImpl.setUserId(account.getUserId());
    accountImpl.setUserName(account.getUserName());
    accountImpl.setCreateDate(account.getCreateDate());
    accountImpl.setModifiedDate(account.getModifiedDate());
    accountImpl.setParentAccountId(account.getParentAccountId());
    accountImpl.setName(account.getName());
    accountImpl.setLegalName(account.getLegalName());
    accountImpl.setLegalId(account.getLegalId());
    accountImpl.setLegalType(account.getLegalType());
    accountImpl.setSicCode(account.getSicCode());
    accountImpl.setTickerSymbol(account.getTickerSymbol());
    accountImpl.setIndustry(account.getIndustry());
    accountImpl.setType(account.getType());
    accountImpl.setSize(account.getSize());

    return accountImpl;
  }
  @Override
  public Account updateImpl(com.liferay.portal.model.Account account) throws SystemException {
    account = toUnwrappedModel(account);

    boolean isNew = account.isNew();

    Session session = null;

    try {
      session = openSession();

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

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

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (isNew) {
      FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    EntityCacheUtil.putResult(
        AccountModelImpl.ENTITY_CACHE_ENABLED, AccountImpl.class, account.getPrimaryKey(), account);

    return account;
  }
  /**
   * Clears the cache for the account.
   *
   * <p>The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link
   * com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
   */
  @Override
  public void clearCache(Account account) {
    EntityCacheUtil.removeResult(
        AccountModelImpl.ENTITY_CACHE_ENABLED, AccountImpl.class, account.getPrimaryKey());

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
  }
  public int compareTo(Account account) {
    long primaryKey = account.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
 /**
  * Caches the accounts in the entity cache if it is enabled.
  *
  * @param accounts the accounts
  */
 public void cacheResult(List<Account> accounts) {
   for (Account account : accounts) {
     if (EntityCacheUtil.getResult(
             AccountModelImpl.ENTITY_CACHE_ENABLED, AccountImpl.class, account.getPrimaryKey())
         == null) {
       cacheResult(account);
     } else {
       account.resetOriginalValues();
     }
   }
 }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    Account account = null;

    try {
      account = (Account) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = account.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  /**
   * Caches the account in the entity cache if it is enabled.
   *
   * @param account the account
   */
  public void cacheResult(Account account) {
    EntityCacheUtil.putResult(
        AccountModelImpl.ENTITY_CACHE_ENABLED, AccountImpl.class, account.getPrimaryKey(), account);

    account.resetOriginalValues();
  }