View Javadoc

    1   /* Copyright 2004, 2005 Acegi Technology Pty Limited
    2    *
    3    * Licensed under the Apache License, Version 2.0 (the "License");
    4    * you may not use this file except in compliance with the License.
    5    * You may obtain a copy of the License at
    6    *
    7    *     http://www.apache.org/licenses/LICENSE-2.0
    8    *
    9    * Unless required by applicable law or agreed to in writing, software
    10   * distributed under the License is distributed on an "AS IS" BASIS,
    11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12   * See the License for the specific language governing permissions and
    13   * limitations under the License.
    14   */
    15
    16  package org.acegisecurity.domain.impl;
    17
    18  import org.acegisecurity.domain.PersistableEntity;
    19
    20  /***
    21   * An abstract implementation of {@link
    22   * org.acegisecurity.domain.PersistableEntity}.
    23   *
    24   * @author Ben Alex
    25   * @version $Id: AbstractPersistableEntity.java,v 1.5 2005/11/17 00:55:49 benalex Exp $
    26   *
    27   *
    28   */
    29  public abstract class AbstractPersistableEntity extends BusinessObject
    30      implements PersistableEntity {
    31      //~ Static fields/initializers =============================================
    32
    33      public static final int STARTING_VERSION = 0;
    34
    35      //~ Instance fields ========================================================
    36
    37      private int version = STARTING_VERSION;
    38
    39      //~ Methods ================================================================
    40
    41      /***
    42       * Indicates whether this persistable entity has been persisted yet.
    43       * Determine based on whether the {@link #getInternalId()} returns
    44       * <code>null</code> or a non-<code>null</code> value.
    45       *
    46       * @return <code>true</code> if the instance has not been persisted,
    47       *         <code>false</code> otherwise
    48       */
    49      public boolean isNew() {
    50          return (getInternalId() == null);
    51      }
    52
    53      /***
    54       * Returns the version number, which should be managed by the persistence
    55       * layer.
    56       *
    57       * <p>
    58       * Initially all <code>PersistableEntity</code>s will commence with the
    59       * version number defined by {@link #STARTING_VERSION}.
    60       * </p>
    61       *
    62       * @return the version
    63       */
    64      public int getVersion() {
    65          return version;
    66      }
    67
    68      /***
    69       * Sets the version numbers.
    70       *
    71       * @param version the new version number to use
    72       */
    73      public void setVersion(int version) {
    74          this.version = version;
    75      }
    76  }