Removing unused HibernateVersion class, updating demo
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15593 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
a499ae2273
commit
3ad01d08f5
|
@ -19,9 +19,9 @@
|
|||
*
|
||||
* Red Hat Author(s): Adam Warski
|
||||
*/
|
||||
package org.jboss.envers.demo;
|
||||
package org.hibernate.envers.demo;
|
||||
|
||||
import org.jboss.envers.Versioned;
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Set;
|
||||
|
@ -35,16 +35,16 @@ public class Address {
|
|||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@Versioned
|
||||
@Audited
|
||||
private String streetName;
|
||||
|
||||
@Versioned
|
||||
@Audited
|
||||
private Integer houseNumber;
|
||||
|
||||
@Versioned
|
||||
@Audited
|
||||
private Integer flatNumber;
|
||||
|
||||
@Versioned
|
||||
@Audited
|
||||
@OneToMany(mappedBy = "address")
|
||||
private Set<Person> persons;
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
*
|
||||
* Red Hat Author(s): Adam Warski
|
||||
*/
|
||||
package org.jboss.envers.demo;
|
||||
package org.hibernate.envers.demo;
|
||||
|
||||
import org.jboss.envers.Versioned;
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
|
@ -34,13 +34,13 @@ public class Person {
|
|||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@Versioned
|
||||
@Audited
|
||||
private String name;
|
||||
|
||||
@Versioned
|
||||
@Audited
|
||||
private String surname;
|
||||
|
||||
@Versioned
|
||||
@Audited
|
||||
@ManyToOne
|
||||
private Address address;
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
*
|
||||
* Red Hat Author(s): Adam Warski
|
||||
*/
|
||||
package org.jboss.envers.demo;
|
||||
package org.hibernate.envers.demo;
|
||||
|
||||
import org.jboss.envers.VersionsReader;
|
||||
import org.jboss.envers.VersionsReaderFactory;
|
||||
import org.jboss.envers.DefaultRevisionEntity;
|
||||
import org.jboss.envers.query.VersionsRestrictions;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.AuditReader;
|
||||
import org.hibernate.envers.AuditReaderFactory;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
@ -83,11 +83,11 @@ public class TestConsole {
|
|||
}
|
||||
|
||||
private void printPersonHistory(StringBuilder sb, int personId) {
|
||||
VersionsReader reader = VersionsReaderFactory.get(entityManager);
|
||||
AuditReader reader = AuditReaderFactory.get(entityManager);
|
||||
|
||||
List personHistory = reader.createQuery()
|
||||
.forRevisionsOfEntity(Person.class, false, true)
|
||||
.add(VersionsRestrictions.idEq(personId))
|
||||
.add(AuditEntity.id().eq(personId))
|
||||
.getResultList();
|
||||
|
||||
if (personHistory.size() == 0) {
|
||||
|
@ -104,7 +104,7 @@ public class TestConsole {
|
|||
}
|
||||
|
||||
private void printPersonAtRevision(StringBuilder sb, int personId, int revision) {
|
||||
VersionsReader reader = VersionsReaderFactory.get(entityManager);
|
||||
AuditReader reader = AuditReaderFactory.get(entityManager);
|
||||
|
||||
Person p = reader.find(Person.class, personId, revision);
|
||||
if (p == null) {
|
||||
|
@ -220,11 +220,11 @@ public class TestConsole {
|
|||
}
|
||||
|
||||
private void printAddressHistory(StringBuilder sb, int addressId) {
|
||||
VersionsReader reader = VersionsReaderFactory.get(entityManager);
|
||||
AuditReader reader = AuditReaderFactory.get(entityManager);
|
||||
|
||||
List addressHistory = reader.createQuery()
|
||||
.forRevisionsOfEntity(Address.class, false, true)
|
||||
.add(VersionsRestrictions.idEq(addressId))
|
||||
.add(AuditEntity.id().eq(addressId))
|
||||
.getResultList();
|
||||
|
||||
if (addressHistory.size() == 0) {
|
||||
|
@ -241,7 +241,7 @@ public class TestConsole {
|
|||
}
|
||||
|
||||
private void printAddressAtRevision(StringBuilder sb, int addressId, int revision) {
|
||||
VersionsReader reader = VersionsReaderFactory.get(entityManager);
|
||||
AuditReader reader = AuditReaderFactory.get(entityManager);
|
||||
|
||||
Address a = reader.find(Address.class, addressId, revision);
|
||||
if (a == null) {
|
||||
|
|
|
@ -22,9 +22,19 @@
|
|||
<!--<property name="hibernate.show_sql" value="true"/>
|
||||
<property name="hibernate.format_sql" value="true"/>-->
|
||||
|
||||
<property name="hibernate.ejb.event.post-insert" value="org.hibernate.envers.event.AuditEventListener" />
|
||||
<property name="hibernate.ejb.event.post-update" value="org.hibernate.envers.event.AuditEventListener" />
|
||||
<property name="hibernate.ejb.event.post-delete" value="org.hibernate.envers.event.AuditEventListener" />
|
||||
<property name="hibernate.ejb.event.post-insert"
|
||||
value="org.hibernate.envers.event.AuditEventListener" />
|
||||
<property name="hibernate.ejb.event.post-update"
|
||||
value="org.hibernate.envers.event.AuditEventListener" />
|
||||
<property name="hibernate.ejb.event.post-delete"
|
||||
value="org.hibernate.envers.event.AuditEventListener" />
|
||||
<property name="hibernate.ejb.event.pre-collection-update"
|
||||
value="org.hibernate.envers.event.AuditEventListener" />
|
||||
<property name="hibernate.ejb.event.pre-collection-remove"
|
||||
value="org.hibernate.envers.event.AuditEventListener" />
|
||||
<property name="hibernate.ejb.event.post-collection-recreate"
|
||||
value="org.hibernate.envers.event.AuditEventListener" />
|
||||
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
|
@ -1,246 +0,0 @@
|
|||
/*
|
||||
* 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 java.util.Collection;
|
||||
|
||||
import org.hibernate.envers.query.criteria.AuditCriterion;
|
||||
import org.hibernate.envers.query.criteria.*;
|
||||
|
||||
import org.hibernate.criterion.MatchMode;
|
||||
|
||||
/**
|
||||
* TODO: ilike
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @see org.hibernate.criterion.Restrictions
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
public class AuditRestrictions {
|
||||
private AuditRestrictions() { }
|
||||
|
||||
/**
|
||||
* Apply an "equal" constraint to the identifier property.
|
||||
*/
|
||||
public static AuditCriterion idEq(Object value) {
|
||||
return new IdentifierEqAuditExpression(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "equal" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion eq(String propertyName, Object value) {
|
||||
return new SimpleAuditExpression(propertyName, value, "=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion ne(String propertyName, Object value) {
|
||||
return new SimpleAuditExpression(propertyName, value, "<>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "equal" constraint on an id of a related entity
|
||||
*/
|
||||
public static AuditCriterion relatedIdEq(String propertyName, Object id) {
|
||||
return new RelatedAuditExpression(propertyName, id, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion relatedIdNe(String propertyName, Object id) {
|
||||
return new RelatedAuditExpression(propertyName, id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "like" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion like(String propertyName, Object value) {
|
||||
return new SimpleAuditExpression(propertyName, value, " like ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "like" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion like(String propertyName, String value, MatchMode matchMode) {
|
||||
return new SimpleAuditExpression(propertyName, matchMode.toMatchString(value), " like " );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion gt(String propertyName, Object value) {
|
||||
return new SimpleAuditExpression(propertyName, value, ">");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion lt(String propertyName, Object value) {
|
||||
return new SimpleAuditExpression(propertyName, value, "<");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than or equal" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion le(String propertyName, Object value) {
|
||||
return new SimpleAuditExpression(propertyName, value, "<=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than or equal" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion ge(String propertyName, Object value) {
|
||||
return new SimpleAuditExpression(propertyName, value, ">=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "between" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion between(String propertyName, Object lo, Object hi) {
|
||||
return new BetweenAuditExpression(propertyName, lo, hi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "in" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion in(String propertyName, Object[] values) {
|
||||
return new InAuditExpression(propertyName, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "in" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion in(String propertyName, Collection values) {
|
||||
return new InAuditExpression(propertyName, values.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "is null" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion isNull(String propertyName) {
|
||||
return new NullAuditExpression(propertyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "equal" constraint to two properties
|
||||
*/
|
||||
public static AuditCriterion eqProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyName, otherPropertyName, "=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint to two properties
|
||||
*/
|
||||
public static AuditCriterion neProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyName, otherPropertyName, "<>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than" constraint to two properties
|
||||
*/
|
||||
public static AuditCriterion ltProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyName, otherPropertyName, "<");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than or equal" constraint to two properties
|
||||
*/
|
||||
public static AuditCriterion leProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyName, otherPropertyName, "<=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than" constraint to two properties
|
||||
*/
|
||||
public static AuditCriterion gtProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyName, otherPropertyName, ">");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than or equal" constraint to two properties
|
||||
*/
|
||||
public static AuditCriterion geProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyName, otherPropertyName, ">=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "is not null" constraint to the named property
|
||||
*/
|
||||
public static AuditCriterion isNotNull(String propertyName) {
|
||||
return new NotNullAuditExpression(propertyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the conjuction of two expressions
|
||||
*/
|
||||
public static AuditCriterion and(AuditCriterion lhs, AuditCriterion rhs) {
|
||||
return new LogicalAuditExpression(lhs, rhs, "and");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the disjuction of two expressions
|
||||
*/
|
||||
public static AuditCriterion or(AuditCriterion lhs, AuditCriterion rhs) {
|
||||
return new LogicalAuditExpression(lhs, rhs, "or");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the negation of an expression
|
||||
*/
|
||||
public static AuditCriterion not(AuditCriterion expression) {
|
||||
return new NotAuditExpression(expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Group expressions together in a single conjunction (A and B and C...)
|
||||
*/
|
||||
public static AuditConjunction conjunction() {
|
||||
return new AuditConjunction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Group expressions together in a single disjunction (A or B or C...)
|
||||
*/
|
||||
public static AuditDisjunction disjunction() {
|
||||
return new AuditDisjunction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "maximalize property" constraint.
|
||||
*/
|
||||
public static AggregatedFieldAuditExpression maximizeProperty(String propertyName) {
|
||||
return new AggregatedFieldAuditExpression(propertyName,
|
||||
AggregatedFieldAuditExpression.AggregatedMode.MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "minimize property" constraint.
|
||||
*/
|
||||
public static AggregatedFieldAuditExpression minimizeProperty(String propertyName) {
|
||||
return new AggregatedFieldAuditExpression(propertyName,
|
||||
AggregatedFieldAuditExpression.AggregatedMode.MIN);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* 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.tools;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class HibernateVersion {
|
||||
private static String version;
|
||||
|
||||
public static String get() {
|
||||
if (version == null) {
|
||||
try {
|
||||
version = (String) Environment.class.getField("VERSION").get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new MappingException(e);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new MappingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue