Subversion Repositories general

Rev

Rev 1010 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package ak.hostadmiral.core.model;

import java.util.Date;
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.ModelSecurityException;

public abstract class GeneralModelObject
        implements ModelObject
{
        private Long    id;
        private Boolean enabled;
        private String  comment;
        private Date    modStamp;
        private User    modUser;

        protected GeneralModelObject()
        {
        }

        protected GeneralModelObject(GeneralModelObject origin)
        {
                this.id       = origin.id;
                this.enabled  = origin.enabled;
                this.comment  = origin.comment;
                this.modStamp = origin.modStamp;
                this.modUser  = origin.modUser;
        }

    /**
     * @return true if the object is not yet saved in DB
     */
    public boolean isNew()
    {
        return (id == null);
    }

        /**
         *
         * @hibernate.id generator-class="native"
         */
        public Long getId()
        {
                return id;
        }

        protected void setId(Long id)
        {
                this.id = id;
        }

        /**
         *
         * @hibernate.property
         */
        public Boolean getEnabled()
        {
                return enabled;
        }

        protected void setEnabled(Boolean enabled)
        {
                this.enabled = enabled;
        }

        public void setEnabled(User editor, Boolean enabled)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.enabled = enabled;
        }

        /**
         *
         * @hibernate.property
         */
        public String getComment()
        {
                return comment;
        }

        protected void setComment(String comment)
        {
                this.comment = comment;
        }

        public void setComment(User editor, String comment)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.comment = comment;
        }

        /**
         *
         * @hibernate.timestamp column="mod_stamp"
         */
        public Date getModStamp()
        {
                return modStamp;
        }

        protected void setModStamp(Date modStamp)
        {
                this.modStamp = modStamp;
        }

        /**
         *
         * @hibernate.many-to-one column="mod_user"
         */
        public User getModUser()
        {
                return modUser;
        }

        protected void setModUser(User modUser)
        {
                this.modUser = modUser;
        }

        public String toString()
        {
                return getClass().getName() + " [" + getId() + "]";
        }

        public boolean equals(Object o)
        {
                if(o == null)                 return false;
                if(!getClass().isInstance(o)) return false;

                ModelObject u = (ModelObject)o;
                return (getId() != null) && (u.getId() != null) && (getId().equals(u.getId()));
        }

        public int hashCode()
        {
                if(getId() == null)
                        return 0;
                else
                        return getId().hashCode();
        }
}