alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (AuditEntity.java)

This example Hibernate source code file (AuditEntity.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

auditconjunction, auditcriterion, auditcriterion, auditdisjunction, auditentity, auditid, auditid, auditproperty, auditproperty, auditrelatedid, entitypropertyname, logicalauditexpression, logicalauditexpression, revisionpropertypropertyname

The Hibernate AuditEntity.java source code

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Middleware LLC.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.hibernate.envers.query;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.query.criteria.AuditConjunction;
import org.hibernate.envers.query.criteria.AuditCriterion;
import org.hibernate.envers.query.criteria.AuditDisjunction;
import org.hibernate.envers.query.criteria.AuditId;
import org.hibernate.envers.query.criteria.AuditProperty;
import org.hibernate.envers.query.criteria.AuditRelatedId;
import org.hibernate.envers.query.criteria.LogicalAuditExpression;
import org.hibernate.envers.query.criteria.NotAuditExpression;
import org.hibernate.envers.query.property.EntityPropertyName;
import org.hibernate.envers.query.property.RevisionNumberPropertyName;
import org.hibernate.envers.query.property.RevisionPropertyPropertyName;
import org.hibernate.envers.query.property.RevisionTypePropertyName;

/**
 * TODO: ilike
 * @author Adam Warski (adam at warski dot org)
 * @see org.hibernate.criterion.Restrictions
 */
@SuppressWarnings({"JavaDoc"})
public class AuditEntity {
    private AuditEntity() { }

    public static AuditId id() {
        return new AuditId();
    }

    /**
     * Create restrictions, projections and specify order for a property of an audited entity.
     * @param propertyName Name of the property.
     */
    public static AuditProperty<Object> property(String propertyName) {
        return new AuditProperty<Object>(new EntityPropertyName(propertyName));
    }

   /**
     * Create restrictions, projections and specify order for the revision number, corresponding to an
     * audited entity.
     */
    public static AuditProperty<Number> revisionNumber() {
        return new AuditProperty<Number>(new RevisionNumberPropertyName());
    }

    /**
     * Create restrictions, projections and specify order for a property of the revision entity,
     * corresponding to an audited entity.
     * @param propertyName Name of the property.
     */
    public static AuditProperty<Object> revisionProperty(String propertyName) {
        return new AuditProperty<Object>(new RevisionPropertyPropertyName(propertyName));
    }

    /**
     * Create restrictions, projections and specify order for the revision type, corresponding to an
     * audited entity.
     */
    public static AuditProperty<RevisionType> revisionType() {
        return new AuditProperty<RevisionType>(new RevisionTypePropertyName());
    }

    /**
	 * Create restrictions on an id of a related entity.
     * @param propertyName Name of the property, which is the relation.
	 */
	public static AuditRelatedId relatedId(String propertyName) {
		return new AuditRelatedId(new EntityPropertyName(propertyName));
	}

    /**
	 * Return the conjuction of two criterions.
	 */
	public static AuditCriterion and(AuditCriterion lhs, AuditCriterion rhs) {
		return new LogicalAuditExpression(lhs, rhs, "and");
	}

    /**
	 * Return the disjuction of two criterions.
	 */
	public static AuditCriterion or(AuditCriterion lhs, AuditCriterion rhs) {
		return new LogicalAuditExpression(lhs, rhs, "or");
	}

    /**
	 * Return the negation of a criterion.
	 */
	public static AuditCriterion not(AuditCriterion expression) {
		return new NotAuditExpression(expression);
	}

	/**
	 * Group criterions together in a single conjunction (A and B and C...).
	 */
	public static AuditConjunction conjunction() {
		return new AuditConjunction();
	}

	/**
	 * Group criterions together in a single disjunction (A or B or C...).
	 */
	public static AuditDisjunction disjunction() {
		return new AuditDisjunction();
	}
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate AuditEntity.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.