@Override
  public Counter updateImpl(com.liferay.counter.model.Counter counter) throws SystemException {
    counter = toUnwrappedModel(counter);

    boolean isNew = counter.isNew();

    Session session = null;

    try {
      session = openSession();

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

        counter.setNew(false);
      } else {
        session.merge(counter);
      }
    } 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(
        CounterModelImpl.ENTITY_CACHE_ENABLED, CounterImpl.class, counter.getPrimaryKey(), counter);

    return counter;
  }
  /**
   * Creates a new counter with the primary key. Does not add the counter to the database.
   *
   * @param name the primary key for the new counter
   * @return the new counter
   */
  public Counter create(String name) {
    Counter counter = new CounterImpl();

    counter.setNew(true);
    counter.setPrimaryKey(name);

    return counter;
  }