diff --git a/envers/src/main/java/org/hibernate/envers/AuditReader.java b/envers/src/main/java/org/hibernate/envers/AuditReader.java index 46d187e24d..28049dafe6 100644 --- a/envers/src/main/java/org/hibernate/envers/AuditReader.java +++ b/envers/src/main/java/org/hibernate/envers/AuditReader.java @@ -28,7 +28,7 @@ import java.util.List; import org.hibernate.envers.exception.NotVersionedException; import org.hibernate.envers.exception.RevisionDoesNotExistException; -import org.hibernate.envers.query.VersionsQueryCreator; +import org.hibernate.envers.query.AuditQueryCreator; /** * @author Adam Warski (adam at warski dot org) @@ -106,5 +106,5 @@ public interface AuditReader { * created and later executed. Shouldn't be used after the associated Session or EntityManager * is closed. */ - VersionsQueryCreator createQuery(); + AuditQueryCreator createQuery(); } diff --git a/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java b/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java index a08751fd2b..abe6ccd504 100644 --- a/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java +++ b/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java @@ -26,8 +26,8 @@ package org.hibernate.envers; import javax.persistence.EntityManager; import org.hibernate.envers.event.VersionsEventListener; -import org.hibernate.envers.exception.VersionsException; -import org.hibernate.envers.reader.VersionsReaderImpl; +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.reader.AuditReaderImpl; import static org.hibernate.envers.tools.ArraysTools.arrayIncludesInstanceOf; import org.hibernate.Session; @@ -48,9 +48,9 @@ public class AuditReaderFactory { * @param session An open session. * @return A versions reader associated with the given sesison. It shouldn't be used * after the session is closed. - * @throws VersionsException When the given required listeners aren't installed. + * @throws org.hibernate.envers.exception.AuditException When the given required listeners aren't installed. */ - public static AuditReader get(Session session) throws VersionsException { + public static AuditReader get(Session session) throws AuditException { SessionImplementor sessionImpl = (SessionImplementor) session; EventListeners listeners = sessionImpl.getListeners(); @@ -59,13 +59,13 @@ public class AuditReaderFactory { if (listener instanceof VersionsEventListener) { if (arrayIncludesInstanceOf(listeners.getPostUpdateEventListeners(), VersionsEventListener.class) && arrayIncludesInstanceOf(listeners.getPostDeleteEventListeners(), VersionsEventListener.class)) { - return new VersionsReaderImpl(((VersionsEventListener) listener).getVerCfg(), session, + return new AuditReaderImpl(((VersionsEventListener) listener).getVerCfg(), session, sessionImpl); } } } - throw new VersionsException("You need install the org.hibernate.envers.event.VersionsEventListener " + + throw new AuditException("You need install the org.hibernate.envers.event.VersionsEventListener " + "class as post insert, update and delete event listener."); } @@ -74,10 +74,10 @@ public class AuditReaderFactory { * @param entityManager An open entity manager. * @return A versions reader associated with the given entity manager. It shouldn't be used * after the entity manager is closed. - * @throws VersionsException When the given entity manager is not based on Hibernate, or if the required + * @throws org.hibernate.envers.exception.AuditException When the given entity manager is not based on Hibernate, or if the required * listeners aren't installed. */ - public static AuditReader get(EntityManager entityManager) throws VersionsException { + public static AuditReader get(EntityManager entityManager) throws AuditException { if (entityManager.getDelegate() instanceof Session) { return get((Session) entityManager.getDelegate()); } @@ -88,6 +88,6 @@ public class AuditReaderFactory { } } - throw new VersionsException("Hibernate EntityManager not present!"); + throw new AuditException("Hibernate EntityManager not present!"); } } diff --git a/envers/src/main/java/org/hibernate/envers/ant/AnnotationConfigurationTaskWithEnvers.java b/envers/src/main/java/org/hibernate/envers/ant/AnnotationConfigurationTaskWithEnvers.java index e8bc6b2e3c..67ce026602 100644 --- a/envers/src/main/java/org/hibernate/envers/ant/AnnotationConfigurationTaskWithEnvers.java +++ b/envers/src/main/java/org/hibernate/envers/ant/AnnotationConfigurationTaskWithEnvers.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.ant; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.cfg.Configuration; import org.hibernate.tool.ant.AnnotationConfigurationTask; @@ -33,7 +33,7 @@ import org.hibernate.tool.ant.AnnotationConfigurationTask; */ public class AnnotationConfigurationTaskWithEnvers extends AnnotationConfigurationTask { protected void doConfiguration(Configuration configuration) { - VersionsConfiguration.getFor(configuration); + AuditConfiguration.getFor(configuration); super.doConfiguration(configuration); } diff --git a/envers/src/main/java/org/hibernate/envers/ant/ConfigurationTaskWithEnvers.java b/envers/src/main/java/org/hibernate/envers/ant/ConfigurationTaskWithEnvers.java index 8f96ca8714..0ea1fa8112 100644 --- a/envers/src/main/java/org/hibernate/envers/ant/ConfigurationTaskWithEnvers.java +++ b/envers/src/main/java/org/hibernate/envers/ant/ConfigurationTaskWithEnvers.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.ant; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.cfg.Configuration; import org.hibernate.tool.ant.ConfigurationTask; @@ -33,7 +33,7 @@ import org.hibernate.tool.ant.ConfigurationTask; */ public class ConfigurationTaskWithEnvers extends ConfigurationTask { protected void doConfiguration(Configuration configuration) { - VersionsConfiguration.getFor(configuration); + AuditConfiguration.getFor(configuration); super.doConfiguration(configuration); } diff --git a/envers/src/main/java/org/hibernate/envers/ant/JPAConfigurationTaskWithEnvers.java b/envers/src/main/java/org/hibernate/envers/ant/JPAConfigurationTaskWithEnvers.java index bc1624c638..703b2619a7 100644 --- a/envers/src/main/java/org/hibernate/envers/ant/JPAConfigurationTaskWithEnvers.java +++ b/envers/src/main/java/org/hibernate/envers/ant/JPAConfigurationTaskWithEnvers.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.ant; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.cfg.Configuration; import org.hibernate.tool.ant.JPAConfigurationTask; @@ -33,7 +33,7 @@ import org.hibernate.tool.ant.JPAConfigurationTask; */ public class JPAConfigurationTaskWithEnvers extends JPAConfigurationTask { protected void doConfiguration(Configuration configuration) { - VersionsConfiguration.getFor(configuration); + AuditConfiguration.getFor(configuration); super.doConfiguration(configuration); } diff --git a/envers/src/main/java/org/hibernate/envers/configuration/AuditConfiguration.java b/envers/src/main/java/org/hibernate/envers/configuration/AuditConfiguration.java new file mode 100644 index 0000000000..9847f141f6 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/configuration/AuditConfiguration.java @@ -0,0 +1,106 @@ +/* + * 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.configuration; + +import java.util.Map; +import java.util.Properties; +import java.util.WeakHashMap; + +import org.hibernate.envers.entities.EntitiesConfigurations; +import org.hibernate.envers.revisioninfo.RevisionInfoNumberReader; +import org.hibernate.envers.revisioninfo.RevisionInfoQueryCreator; +import org.hibernate.envers.synchronization.AuditSyncManager; +import org.hibernate.envers.tools.reflection.YReflectionManager; + +import org.hibernate.cfg.Configuration; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class AuditConfiguration { + private final GlobalConfiguration globalCfg; + private final AuditEntitiesConfiguration verEntCfg; + private final AuditSyncManager versionsSyncManager; + private final EntitiesConfigurations entCfg; + private final RevisionInfoQueryCreator revisionInfoQueryCreator; + private final RevisionInfoNumberReader revisionInfoNumberReader; + + public AuditEntitiesConfiguration getVerEntCfg() { + return verEntCfg; + } + + public AuditSyncManager getSyncManager() { + return versionsSyncManager; + } + + public GlobalConfiguration getGlobalCfg() { + return globalCfg; + } + + public EntitiesConfigurations getEntCfg() { + return entCfg; + } + + public RevisionInfoQueryCreator getRevisionInfoQueryCreator() { + return revisionInfoQueryCreator; + } + + public RevisionInfoNumberReader getRevisionInfoNumberReader() { + return revisionInfoNumberReader; + } + + @SuppressWarnings({"unchecked"}) + public AuditConfiguration(Configuration cfg) { + Properties properties = cfg.getProperties(); + + YReflectionManager reflectionManager = YReflectionManager.get(cfg); + RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration(); + RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager); + verEntCfg = new AuditEntitiesConfiguration(properties, revInfoCfgResult.getRevisionInfoEntityName()); + globalCfg = new GlobalConfiguration(properties); + versionsSyncManager = new AuditSyncManager(revInfoCfgResult.getRevisionInfoGenerator()); + revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator(); + revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader(); + entCfg = new EntitiesConfigurator().configure(cfg, reflectionManager, globalCfg, verEntCfg, + revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping()); + } + + // + + private static Map cfgs + = new WeakHashMap(); + + public synchronized static AuditConfiguration getFor(Configuration cfg) { + AuditConfiguration verCfg = cfgs.get(cfg); + + if (verCfg == null) { + verCfg = new AuditConfiguration(cfg); + cfgs.put(cfg, verCfg); + + cfg.buildMappings(); + } + + return verCfg; + } +} diff --git a/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java b/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java new file mode 100644 index 0000000000..7b298e6d7d --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java @@ -0,0 +1,112 @@ +/* + * 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.configuration; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * Configuration of versions entities - names of fields, entities and tables created to store versioning information. + * @author Adam Warski (adam at warski dot org) + */ +public class AuditEntitiesConfiguration { + private final String versionsTablePrefix; + private final String versionsTableSuffix; + + private final String originalIdPropName; + + private final String revisionPropName; + private final String revisionPropPath; + + private final String revisionTypePropName; + private final String revisionTypePropType; + + private final String revisionInfoEntityName; + + private final Map customVersionsTablesNames; + + public AuditEntitiesConfiguration(Properties properties, String revisionInfoEntityName) { + this.revisionInfoEntityName = revisionInfoEntityName; + + versionsTablePrefix = properties.getProperty("org.hibernate.envers.versionsTablePrefix", ""); + versionsTableSuffix = properties.getProperty("org.hibernate.envers.versionsTableSuffix", "_versions"); + + originalIdPropName = "originalId"; + + revisionPropName = properties.getProperty("org.hibernate.envers.revisionFieldName", "_revision"); + + revisionTypePropName = properties.getProperty("org.hibernate.envers.revisionTypeFieldName", "_revision_type"); + revisionTypePropType = "byte"; + + customVersionsTablesNames = new HashMap(); + + revisionPropPath = originalIdPropName + "." + revisionPropName + ".id"; + } + + public String getOriginalIdPropName() { + return originalIdPropName; + } + + public String getRevisionPropName() { + return revisionPropName; + } + + public String getRevisionPropPath() { + return revisionPropPath; + } + + public String getRevisionTypePropName() { + return revisionTypePropName; + } + + public String getRevisionTypePropType() { + return revisionTypePropType; + } + + public String getRevisionInfoEntityName() { + return revisionInfoEntityName; + } + + // + + public void addCustomVersionsTableName(String entityName, String tableName) { + customVersionsTablesNames.put(entityName, tableName); + } + + // + + public String getVersionsEntityName(String entityName) { + return versionsTablePrefix + entityName + versionsTableSuffix; + } + + public String getVersionsTableName(String entityName, String tableName) { + String customHistoryTableName = customVersionsTablesNames.get(entityName); + if (customHistoryTableName == null) { + return versionsTablePrefix + tableName + versionsTableSuffix; + } + + return customHistoryTableName; + } +} diff --git a/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java b/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java index 41a5ad772c..b6bed3fdfd 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java @@ -40,7 +40,7 @@ import org.dom4j.io.XMLWriter; import org.hibernate.envers.configuration.metadata.AnnotationsMetadataReader; import org.hibernate.envers.configuration.metadata.EntityXmlMappingData; import org.hibernate.envers.configuration.metadata.PersistentClassVersioningData; -import org.hibernate.envers.configuration.metadata.VersionsMetadataGenerator; +import org.hibernate.envers.configuration.metadata.AuditMetadataGenerator; import org.hibernate.envers.entities.EntitiesConfigurations; import org.hibernate.envers.tools.StringTools; import org.hibernate.envers.tools.graph.GraphTopologicalSort; @@ -55,9 +55,9 @@ import org.hibernate.mapping.PersistentClass; */ public class EntitiesConfigurator { public EntitiesConfigurations configure(Configuration cfg, YReflectionManager reflectionManager, - GlobalConfiguration globalCfg, VersionsEntitiesConfiguration verEntCfg, + GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) { - VersionsMetadataGenerator versionsMetaGen = new VersionsMetadataGenerator(cfg, globalCfg, verEntCfg, + AuditMetadataGenerator versionsMetaGen = new AuditMetadataGenerator(cfg, globalCfg, verEntCfg, revisionInfoRelationMapping); DOMWriter writer = new DOMWriter(); diff --git a/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java b/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java new file mode 100644 index 0000000000..a64677bbeb --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java @@ -0,0 +1,385 @@ +/* + * 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.configuration.metadata; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.dom4j.Element; +import org.hibernate.envers.ModificationStore; +import org.hibernate.envers.AuditJoinTable; +import org.hibernate.envers.configuration.GlobalConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; +import org.hibernate.envers.entities.EntityConfiguration; +import org.hibernate.envers.entities.IdMappingData; +import org.hibernate.envers.entities.mapper.CompositeMapperBuilder; +import org.hibernate.envers.entities.mapper.ExtendedPropertyMapper; +import org.hibernate.envers.entities.mapper.MultiPropertyMapper; +import org.hibernate.envers.entities.mapper.SubclassPropertyMapper; +import org.hibernate.envers.entity.VersionsInheritanceEntityPersister; +import org.hibernate.envers.tools.StringTools; +import org.hibernate.envers.tools.log.YLog; +import org.hibernate.envers.tools.log.YLogManager; + +import org.hibernate.MappingException; +import org.hibernate.cfg.Configuration; +import org.hibernate.mapping.Collection; +import org.hibernate.mapping.Join; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Value; +import org.hibernate.type.CollectionType; +import org.hibernate.type.ManyToOneType; +import org.hibernate.type.OneToOneType; +import org.hibernate.type.Type; + +/** + * @author Adam Warski (adam at warski dot org) + * @author Sebastian Komander + */ +public final class AuditMetadataGenerator { + private final Configuration cfg; + private final GlobalConfiguration globalCfg; + private final AuditEntitiesConfiguration verEntCfg; + private final Element revisionInfoRelationMapping; + + private final BasicMetadataGenerator basicMetadataGenerator; + private final IdMetadataGenerator idMetadataGenerator; + private final ToOneRelationMetadataGenerator toOneRelationMetadataGenerator; + + private final Map entitiesConfigurations; + + // Map entity name -> (join descriptor -> element describing the "versioned" join) + private final Map> entitiesJoins; + + private YLog log = YLogManager.getLogManager().getLog(AuditMetadataGenerator.class); + + public AuditMetadataGenerator(Configuration cfg, GlobalConfiguration globalCfg, + AuditEntitiesConfiguration verEntCfg, + Element revisionInfoRelationMapping) { + this.cfg = cfg; + this.globalCfg = globalCfg; + this.verEntCfg = verEntCfg; + this.revisionInfoRelationMapping = revisionInfoRelationMapping; + + this.basicMetadataGenerator = new BasicMetadataGenerator(); + this.idMetadataGenerator = new IdMetadataGenerator(this); + this.toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator(this); + + entitiesConfigurations = new HashMap(); + entitiesJoins = new HashMap>(); + } + + void addRevisionInfoRelation(Element any_mapping) { + Element rev_mapping = (Element) revisionInfoRelationMapping.clone(); + rev_mapping.addAttribute("name", verEntCfg.getRevisionPropName()); + MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null); + + any_mapping.add(rev_mapping); + } + + void addRevisionType(Element any_mapping) { + Element revTypeProperty = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionTypePropName(), + verEntCfg.getRevisionTypePropType(), true, false); + revTypeProperty.addAttribute("type", "org.hibernate.envers.entities.RevisionTypeType"); + } + + private ModificationStore getStoreForProperty(Property property, PropertyStoreInfo propertyStoreInfo, + List unversionedProperties) { + /* + * Checks if a property is versioned, which is when: + * - the property isn't unversioned + * - the whole entity is versioned, then the default store is not null + * - there is a store defined for this entity, which is when this property is annotated + */ + + if (unversionedProperties.contains(property.getName())) { + return null; + } + + ModificationStore store = propertyStoreInfo.propertyStores.get(property.getName()); + + if (store == null) { + return propertyStoreInfo.defaultStore; + } + + return store; + } + + @SuppressWarnings({"unchecked"}) + void addValue(Element parent, String name, Value value, CompositeMapperBuilder currentMapper, + ModificationStore store, String entityName, EntityXmlMappingData xmlMappingData, + AuditJoinTable joinTable, String mapKey, boolean insertable, boolean firstPass) { + Type type = value.getType(); + + // only first pass + if (firstPass) { + if (basicMetadataGenerator.addBasic(parent, name, value, currentMapper, store, entityName, insertable, + false)) { + // The property was mapped by the basic generator. + return; + } + } + + if (type instanceof ManyToOneType) { + // only second pass + if (!firstPass) { + toOneRelationMetadataGenerator.addToOne(parent, name, value, currentMapper, entityName); + } + } else if (type instanceof OneToOneType) { + // only second pass + if (!firstPass) { + toOneRelationMetadataGenerator.addOneToOneNotOwning(name, value, currentMapper, entityName); + } + } else if (type instanceof CollectionType) { + // only second pass + if (!firstPass) { + CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(this, + name, (Collection) value, currentMapper, entityName, xmlMappingData, joinTable, mapKey); + collectionMetadataGenerator.addCollection(); + } + } else { + if (firstPass) { + // If we got here in the first pass, it means the basic mapper didn't map it, and none of the + // above branches either. + throwUnsupportedTypeException(type, entityName, name); + } + } + } + + @SuppressWarnings({"unchecked"}) + private void addProperties(Element parent, Iterator properties, CompositeMapperBuilder currentMapper, + PersistentClassVersioningData versioningData, String entityName, EntityXmlMappingData xmlMappingData, + boolean firstPass) { + while (properties.hasNext()) { + Property property = properties.next(); + if (!"_identifierMapper".equals(property.getName())) { + ModificationStore store = getStoreForProperty(property, versioningData.propertyStoreInfo, + versioningData.unversionedProperties); + + if (store != null) { + addValue(parent, property.getName(), property.getValue(), currentMapper, store, entityName, + xmlMappingData, versioningData.versionsJoinTables.get(property.getName()), + versioningData.mapKeys.get(property.getName()), property.isInsertable(), firstPass); + } + } + } + } + + @SuppressWarnings({"unchecked"}) + private void createJoins(PersistentClass pc, Element parent, PersistentClassVersioningData versioningData) { + Iterator joins = pc.getJoinIterator(); + + Map joinElements = new HashMap(); + entitiesJoins.put(pc.getEntityName(), joinElements); + + while (joins.hasNext()) { + Join join = joins.next(); + + // Determining the table name. If there is no entry in the dictionary, just constructing the table name + // as if it was an entity (by appending/prepending configured strings). + String originalTableName = join.getTable().getName(); + String versionedTableName = versioningData.secondaryTableDictionary.get(originalTableName); + if (versionedTableName == null) { + versionedTableName = verEntCfg.getVersionsEntityName(originalTableName); + } + + String schema = versioningData.versionsTable.schema(); + if (StringTools.isEmpty(schema)) { + schema = join.getTable().getSchema(); + } + + String catalog = versioningData.versionsTable.catalog(); + if (StringTools.isEmpty(catalog)) { + catalog = join.getTable().getCatalog(); + } + + Element joinElement = MetadataTools.createJoin(parent, versionedTableName, schema, catalog); + joinElements.put(join, joinElement); + + Element joinKey = joinElement.addElement("key"); + MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator()); + MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(), null); + } + } + + @SuppressWarnings({"unchecked"}) + private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, PersistentClassVersioningData versioningData, + String entityName, EntityXmlMappingData xmlMappingData,boolean firstPass) { + Iterator joins = pc.getJoinIterator(); + + while (joins.hasNext()) { + Join join = joins.next(); + Element joinElement = entitiesJoins.get(entityName).get(join); + + addProperties(joinElement, join.getPropertyIterator(), currentMapper, versioningData, entityName, + xmlMappingData, firstPass); + } + } + + private void addPersisterHack(Element class_mapping) { + class_mapping.addAttribute("persister", VersionsInheritanceEntityPersister.class.getName() ); + } + + @SuppressWarnings({"unchecked"}) + public void generateFirstPass(PersistentClass pc, PersistentClassVersioningData versioningData, + EntityXmlMappingData xmlMappingData) { + String schema = versioningData.versionsTable.schema(); + if (StringTools.isEmpty(schema)) { + schema = pc.getTable().getSchema(); + } + + String catalog = versioningData.versionsTable.catalog(); + if (StringTools.isEmpty(catalog)) { + catalog = pc.getTable().getCatalog(); + } + + String entityName = pc.getEntityName(); + String versionsEntityName = verEntCfg.getVersionsEntityName(entityName); + String versionsTableName = verEntCfg.getVersionsTableName(entityName, pc.getTable().getName()); + + // Generating a mapping for the id + IdMappingData idMapper = idMetadataGenerator.addId(pc); + + Element class_mapping; + ExtendedPropertyMapper propertyMapper; + + InheritanceType inheritanceType = InheritanceType.get(pc); + String parentEntityName = null; + + switch (inheritanceType) { + case NONE: + class_mapping = MetadataTools.createEntity(xmlMappingData.getMainXmlMapping(), versionsEntityName, versionsTableName, + schema, catalog, pc.getDiscriminatorValue()); + propertyMapper = new MultiPropertyMapper(); + + // Checking if there is a discriminator column + if (pc.getDiscriminator() != null) { + Element discriminator_element = class_mapping.addElement("discriminator"); + MetadataTools.addColumns(discriminator_element, pc.getDiscriminator().getColumnIterator()); + discriminator_element.addAttribute("type", pc.getDiscriminator().getType().getName()); + + // If so, there is some inheritance scheme -> using the persister hack. + addPersisterHack(class_mapping); + } + + // Adding the id mapping + class_mapping.add((Element) idMapper.getXmlMapping().clone()); + + // Adding the "revision type" property + addRevisionType(class_mapping); + + break; + case SINGLE: + String extendsEntityName = verEntCfg.getVersionsEntityName(pc.getSuperclass().getEntityName()); + class_mapping = MetadataTools.createSubclassEntity(xmlMappingData.getMainXmlMapping(), versionsEntityName, + versionsTableName, schema, catalog, extendsEntityName, pc.getDiscriminatorValue()); + + addPersisterHack(class_mapping); + + // The id and revision type is already mapped in the parent + + // Getting the property mapper of the parent - when mapping properties, they need to be included + parentEntityName = pc.getSuperclass().getEntityName(); + ExtendedPropertyMapper parentPropertyMapper = entitiesConfigurations.get(parentEntityName).getPropertyMapper(); + propertyMapper = new SubclassPropertyMapper(new MultiPropertyMapper(), parentPropertyMapper); + + break; + case JOINED: + throw new MappingException("Joined inheritance strategy not supported for versioning!"); + case TABLE_PER_CLASS: + throw new MappingException("Table-per-class inheritance strategy not supported for versioning!"); + default: + throw new AssertionError("Impossible enum value."); + } + + // Mapping unjoined properties + addProperties(class_mapping, (Iterator) pc.getUnjoinedPropertyIterator(), propertyMapper, + versioningData, pc.getEntityName(), xmlMappingData, + true); + + // Creating and mapping joins (first pass) + createJoins(pc, class_mapping, versioningData); + addJoins(pc, propertyMapper, versioningData, pc.getEntityName(), xmlMappingData, true); + + // Storing the generated configuration + EntityConfiguration entityCfg = new EntityConfiguration(versionsEntityName, idMapper, + propertyMapper, parentEntityName); + entitiesConfigurations.put(pc.getEntityName(), entityCfg); + } + + @SuppressWarnings({"unchecked"}) + public void generateSecondPass(PersistentClass pc, PersistentClassVersioningData versioningData, + EntityXmlMappingData xmlMappingData) { + String entityName = pc.getEntityName(); + + CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper(); + + // Mapping unjoined properties + Element parent = xmlMappingData.getMainXmlMapping().getRootElement().element("class"); + if (parent == null) { + parent = xmlMappingData.getMainXmlMapping().getRootElement().element("subclass"); + } + + addProperties(parent, (Iterator) pc.getUnjoinedPropertyIterator(), + propertyMapper, versioningData, entityName, xmlMappingData, false); + + // Mapping joins (second pass) + addJoins(pc, propertyMapper, versioningData, entityName, xmlMappingData, false); + } + + public Map getEntitiesConfigurations() { + return entitiesConfigurations; + } + + // Getters for generators and configuration + + BasicMetadataGenerator getBasicMetadataGenerator() { + return basicMetadataGenerator; + } + + Configuration getCfg() { + return cfg; + } + + GlobalConfiguration getGlobalCfg() { + return globalCfg; + } + + AuditEntitiesConfiguration getVerEntCfg() { + return verEntCfg; + } + + void throwUnsupportedTypeException(Type type, String entityName, String propertyName) { + String message = "Type not supported for versioning: " + type.getClass().getName() + + ", on entity " + entityName + ", property '" + propertyName + "'."; + if (globalCfg.isWarnOnUnsupportedTypes()) { + log.warn(message); + } else { + throw new MappingException(message); + } + } +} diff --git a/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java b/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java index 43cfb8112f..dce2a6ef7d 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java @@ -85,7 +85,7 @@ import org.hibernate.type.Type; * @author Adam Warski (adam at warski dot org) */ public final class CollectionMetadataGenerator { - private final VersionsMetadataGenerator mainGenerator; + private final AuditMetadataGenerator mainGenerator; private final String propertyName; private final Collection propertyValue; private final CompositeMapperBuilder currentMapper; @@ -113,7 +113,7 @@ public final class CollectionMetadataGenerator { * @param mapKey The value of the name() property of the MapKey annotation on this property. Null, if this * property isn't annotated with this annotation. */ - public CollectionMetadataGenerator(VersionsMetadataGenerator mainGenerator, String propertyName, + public CollectionMetadataGenerator(AuditMetadataGenerator mainGenerator, String propertyName, Collection propertyValue, CompositeMapperBuilder currentMapper, String referencingEntityName, EntityXmlMappingData xmlMappingData, AuditJoinTable joinTable, String mapKey) { diff --git a/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java b/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java index 7ec0d35fa7..e6adbad8d5 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java @@ -47,9 +47,9 @@ import org.hibernate.type.Type; * @author Adam Warski (adam at warski dot org) */ public final class IdMetadataGenerator { - private final VersionsMetadataGenerator mainGenerator; + private final AuditMetadataGenerator mainGenerator; - IdMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) { + IdMetadataGenerator(AuditMetadataGenerator versionsMetadataGenerator) { mainGenerator = versionsMetadataGenerator; } diff --git a/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java b/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java index 7bf9881494..e9a4a9f031 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java @@ -27,7 +27,7 @@ import java.util.ArrayList; import java.util.List; import org.hibernate.envers.configuration.GlobalConfiguration; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.entities.mapper.relation.MiddleIdData; import org.hibernate.envers.entities.mapper.relation.query.OneEntityQueryGenerator; @@ -42,12 +42,12 @@ import org.hibernate.envers.entities.mapper.relation.query.TwoEntityQueryGenerat */ public final class QueryGeneratorBuilder { private final GlobalConfiguration globalCfg; - private final VersionsEntitiesConfiguration verEntCfg; + private final AuditEntitiesConfiguration verEntCfg; private final MiddleIdData referencingIdData; private final String versionsMiddleEntityName; private final List idDatas; - QueryGeneratorBuilder(GlobalConfiguration globalCfg, VersionsEntitiesConfiguration verEntCfg, + QueryGeneratorBuilder(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData, String versionsMiddleEntityName) { this.globalCfg = globalCfg; this.verEntCfg = verEntCfg; diff --git a/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java b/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java index 2e05bc025f..f96eda77c1 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java @@ -41,9 +41,9 @@ import org.hibernate.mapping.Value; * @author Adam Warski (adam at warski dot org) */ public final class ToOneRelationMetadataGenerator { - private final VersionsMetadataGenerator mainGenerator; + private final AuditMetadataGenerator mainGenerator; - ToOneRelationMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) { + ToOneRelationMetadataGenerator(AuditMetadataGenerator versionsMetadataGenerator) { mainGenerator = versionsMetadataGenerator; } diff --git a/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java b/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java index c985c25657..344092fa4e 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java +++ b/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java @@ -27,20 +27,20 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.mapper.id.IdMapper; -import org.hibernate.envers.exception.VersionsException; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.reflection.ReflectionTools; /** * @author Adam Warski (adam at warski dot org) */ public class EntityInstantiator { - private final VersionsConfiguration verCfg; - private final VersionsReaderImplementor versionsReader; + private final AuditConfiguration verCfg; + private final AuditReaderImplementor versionsReader; - public EntityInstantiator(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader) { + public EntityInstantiator(AuditConfiguration verCfg, AuditReaderImplementor versionsReader) { this.verCfg = verCfg; this.versionsReader = versionsReader; } @@ -82,7 +82,7 @@ public class EntityInstantiator { Class cls = ReflectionTools.loadClass(entityName); ret = cls.newInstance(); } catch (Exception e) { - throw new VersionsException(e); + throw new AuditException(e); } // Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/MapPropertyMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/MapPropertyMapper.java index 42df8cafe7..eb98a37f7d 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/MapPropertyMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/MapPropertyMapper.java @@ -29,9 +29,9 @@ import java.util.List; import java.util.Map; import org.hibernate.envers.ModificationStore; -import org.hibernate.envers.configuration.VersionsConfiguration; -import org.hibernate.envers.exception.VersionsException; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.reflection.ReflectionTools; import org.hibernate.collection.PersistentCollection; @@ -70,7 +70,7 @@ public class MapPropertyMapper implements PropertyMapper, CompositeMapperBuilder return delegate.mapToMapFromEntity(newData, newObj, oldObj); } - public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) { + public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) { if (data == null || obj == null) { return; } @@ -83,7 +83,7 @@ public class MapPropertyMapper implements PropertyMapper, CompositeMapperBuilder setter.set(obj, subObj, null); delegate.mapToEntityFromMap(verCfg, subObj, (Map) data.get(propertyName), primaryKey, versionsReader, revision); } catch (Exception e) { - throw new VersionsException(e); + throw new AuditException(e); } } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java index 41c8330ccb..49e0ea0612 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java @@ -29,8 +29,8 @@ import java.util.List; import java.util.Map; import org.hibernate.envers.ModificationStore; -import org.hibernate.envers.configuration.VersionsConfiguration; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.reflection.ReflectionTools; import org.hibernate.MappingException; @@ -105,7 +105,7 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper { return ret; } - public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) { + public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) { for (String propertyName : properties.keySet()) { properties.get(propertyName).mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/PropertyMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/PropertyMapper.java index 31568d1231..95efd07fab 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/PropertyMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/PropertyMapper.java @@ -27,8 +27,8 @@ import java.io.Serializable; import java.util.List; import java.util.Map; -import org.hibernate.envers.configuration.VersionsConfiguration; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.collection.PersistentCollection; @@ -54,8 +54,8 @@ public interface PropertyMapper { * @param versionsReader VersionsReader for reading relations * @param revision Revision at which the object is read, for reading relations */ - void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, - VersionsReaderImplementor versionsReader, Number revision); + void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision); /** * Maps collection changes diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java index 15ca77b58b..a99c2d2e74 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java @@ -28,9 +28,9 @@ import java.util.List; import java.util.Map; import org.hibernate.envers.ModificationStore; -import org.hibernate.envers.configuration.VersionsConfiguration; -import org.hibernate.envers.exception.VersionsException; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.Tools; import org.hibernate.envers.tools.reflection.ReflectionTools; @@ -48,7 +48,7 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder public void add(String propertyName, ModificationStore modStore) { if (this.propertyName != null) { - throw new VersionsException("Only one property can be added!"); + throw new AuditException("Only one property can be added!"); } this.propertyName = propertyName; @@ -60,7 +60,7 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder return !Tools.objectsEqual(newObj, oldObj); } - public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) { + public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) { if (data == null || obj == null) { return; } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java index c7414b0447..03fb360703 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java @@ -28,8 +28,8 @@ import java.util.List; import java.util.Map; import org.hibernate.envers.ModificationStore; -import org.hibernate.envers.configuration.VersionsConfiguration; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.collection.PersistentCollection; @@ -61,7 +61,7 @@ public class SubclassPropertyMapper implements ExtendedPropertyMapper { return parentDiffs || mainDiffs; } - public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) { + public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) { parentMapper.mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); main.mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/id/AbstractCompositeIdMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/id/AbstractCompositeIdMapper.java index 3252dd8c0a..f8b8228ea3 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/id/AbstractCompositeIdMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/id/AbstractCompositeIdMapper.java @@ -27,7 +27,7 @@ import java.util.LinkedHashMap; import java.util.Map; import org.hibernate.envers.ModificationStore; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; /** * @author Adam Warski (adam at warski dot org) @@ -51,7 +51,7 @@ public abstract class AbstractCompositeIdMapper extends AbstractIdMapper impleme try { ret = Thread.currentThread().getContextClassLoader().loadClass(compositeIdClass).newInstance(); } catch (Exception e) { - throw new VersionsException(e); + throw new AuditException(e); } for (SingleIdMapper mapper : ids.values()) { diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/id/EmbeddedIdMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/id/EmbeddedIdMapper.java index e076961153..cc341c58a1 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/id/EmbeddedIdMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/id/EmbeddedIdMapper.java @@ -28,7 +28,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.tools.reflection.ReflectionTools; import org.hibernate.property.Getter; @@ -78,7 +78,7 @@ public class EmbeddedIdMapper extends AbstractCompositeIdMapper implements Simpl idMapper.mapToEntityFromMap(subObj, data); } } catch (Exception e) { - throw new VersionsException(e); + throw new AuditException(e); } } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/id/MultipleIdMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/id/MultipleIdMapper.java index 6fbffbdd4b..fe08a5d20e 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/id/MultipleIdMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/id/MultipleIdMapper.java @@ -28,7 +28,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; /** * @author Adam Warski (adam at warski dot org) @@ -73,7 +73,7 @@ public class MultipleIdMapper extends AbstractCompositeIdMapper implements Simpl try { ret = Thread.currentThread().getContextClassLoader().loadClass(compositeIdClass).newInstance(); } catch (Exception e) { - throw new VersionsException(e); + throw new AuditException(e); } for (SingleIdMapper mapper : ids.values()) { diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/id/SingleIdMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/id/SingleIdMapper.java index 798d7d0e02..65d536c509 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/id/SingleIdMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/id/SingleIdMapper.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Map; import org.hibernate.envers.ModificationStore; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.tools.reflection.ReflectionTools; import org.hibernate.property.Getter; @@ -56,7 +56,7 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu public void add(String propertyName, ModificationStore modStore) { if (this.propertyName != null) { - throw new VersionsException("Only one property can be added!"); + throw new AuditException("Only one property can be added!"); } this.propertyName = propertyName; diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/AbstractCollectionMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/AbstractCollectionMapper.java index 44a0acc577..e8ee60917c 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/AbstractCollectionMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/AbstractCollectionMapper.java @@ -35,12 +35,12 @@ import java.util.Map; import java.util.Set; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData; import org.hibernate.envers.entities.mapper.PropertyMapper; import org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor; -import org.hibernate.envers.exception.VersionsException; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.reflection.ReflectionTools; import org.hibernate.collection.PersistentCollection; @@ -63,7 +63,7 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { try { proxyConstructor = proxyClass.getConstructor(Initializor.class); } catch (NoSuchMethodException e) { - throw new VersionsException(e); + throw new AuditException(e); } } @@ -131,22 +131,22 @@ public abstract class AbstractCollectionMapper implements PropertyMapper { return false; } - protected abstract Initializor getInitializor(VersionsConfiguration verCfg, - VersionsReaderImplementor versionsReader, Object primaryKey, + protected abstract Initializor getInitializor(AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, Object primaryKey, Number revision); - public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, - VersionsReaderImplementor versionsReader, Number revision) { + public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision) { Setter setter = ReflectionTools.getSetter(obj.getClass(), commonCollectionMapperData.getCollectionReferencingPropertyName()); try { setter.set(obj, proxyConstructor.newInstance(getInitializor(verCfg, versionsReader, primaryKey, revision)), null); } catch (InstantiationException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/BasicCollectionMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/BasicCollectionMapper.java index 8227ce7749..46a92ae0f6 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/BasicCollectionMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/BasicCollectionMapper.java @@ -27,11 +27,11 @@ import java.io.Serializable; import java.util.Collection; import java.util.Map; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.mapper.PropertyMapper; import org.hibernate.envers.entities.mapper.relation.lazy.initializor.BasicCollectionInitializor; import org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.collection.PersistentCollection; @@ -48,7 +48,7 @@ public final class BasicCollectionMapper extends AbstractC this.elementComponentData = elementComponentData; } - protected Initializor getInitializor(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader, + protected Initializor getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, Object primaryKey, Number revision) { return new BasicCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), primaryKey, revision, collectionClass, elementComponentData); diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/CommonCollectionMapperData.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/CommonCollectionMapperData.java index 8526fc1a2c..a9b725dad2 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/CommonCollectionMapperData.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/CommonCollectionMapperData.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.entities.mapper.relation; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.mapper.relation.query.RelationQueryGenerator; /** @@ -31,13 +31,13 @@ import org.hibernate.envers.entities.mapper.relation.query.RelationQueryGenerato * @author Adam Warski (adam at warski dot org) */ public final class CommonCollectionMapperData { - private final VersionsEntitiesConfiguration verEntCfg; + private final AuditEntitiesConfiguration verEntCfg; private final String versionsMiddleEntityName; private final String collectionReferencingPropertyName; private final MiddleIdData referencingIdData; private final RelationQueryGenerator queryGenerator; - public CommonCollectionMapperData(VersionsEntitiesConfiguration verEntCfg, String versionsMiddleEntityName, + public CommonCollectionMapperData(AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName, String collectionReferencingPropertyName, MiddleIdData referencingIdData, RelationQueryGenerator queryGenerator) { this.verEntCfg = verEntCfg; @@ -47,7 +47,7 @@ public final class CommonCollectionMapperData { this.queryGenerator = queryGenerator; } - public VersionsEntitiesConfiguration getVerEntCfg() { + public AuditEntitiesConfiguration getVerEntCfg() { return verEntCfg; } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ListCollectionMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ListCollectionMapper.java index 5be4b94c1c..fcbb497293 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ListCollectionMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ListCollectionMapper.java @@ -28,12 +28,12 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.mapper.PropertyMapper; import org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor; import org.hibernate.envers.entities.mapper.relation.lazy.initializor.ListCollectionInitializor; import org.hibernate.envers.entities.mapper.relation.lazy.proxy.ListProxy; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.Pair; import org.hibernate.envers.tools.Tools; @@ -53,7 +53,7 @@ public final class ListCollectionMapper extends AbstractCollectionMapper i this.indexComponentData = indexComponentData; } - protected Initializor getInitializor(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader, + protected Initializor getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, Object primaryKey, Number revision) { return new ListCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), primaryKey, revision, elementComponentData, indexComponentData); diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MapCollectionMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MapCollectionMapper.java index ccdc995387..9a527d1090 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MapCollectionMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MapCollectionMapper.java @@ -27,11 +27,11 @@ import java.io.Serializable; import java.util.Collection; import java.util.Map; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.mapper.PropertyMapper; import org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor; import org.hibernate.envers.entities.mapper.relation.lazy.initializor.MapCollectionInitializor; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.collection.PersistentCollection; @@ -50,7 +50,7 @@ public final class MapCollectionMapper extends AbstractCollection this.indexComponentData = indexComponentData; } - protected Initializor getInitializor(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader, + protected Initializor getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, Object primaryKey, Number revision) { return new MapCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(), primaryKey, revision, collectionClass, elementComponentData, indexComponentData); diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java index f2a46f2d7c..aa46d134ff 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.entities.mapper.relation; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.IdMappingData; import org.hibernate.envers.entities.mapper.id.IdMapper; @@ -50,7 +50,7 @@ public final class MiddleIdData { */ private final String versionsEntityName; - public MiddleIdData(VersionsEntitiesConfiguration verEntCfg, IdMappingData mappingData, String prefix, + public MiddleIdData(AuditEntitiesConfiguration verEntCfg, IdMappingData mappingData, String prefix, String entityName) { this.originalMapper = mappingData.getIdMapper(); this.prefixedMapper = mappingData.getIdMapper().prefixMappedProperties(prefix); diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java index fa2db044ac..519f306aea 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java @@ -28,12 +28,12 @@ import java.util.List; import java.util.Map; import javax.persistence.NoResultException; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData; import org.hibernate.envers.entities.mapper.PropertyMapper; -import org.hibernate.envers.exception.VersionsException; -import org.hibernate.envers.query.VersionsRestrictions; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.query.AuditRestrictions; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.reflection.ReflectionTools; import org.hibernate.NonUniqueResultException; @@ -58,7 +58,7 @@ public class OneToOneNotOwningMapper implements PropertyMapper { return false; } - public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) { + public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) { if (obj == null) { return; } @@ -69,11 +69,11 @@ public class OneToOneNotOwningMapper implements PropertyMapper { try { value = versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision) - .add(VersionsRestrictions.relatedIdEq(owningReferencePropertyName, primaryKey)).getSingleResult(); + .add(AuditRestrictions.relatedIdEq(owningReferencePropertyName, primaryKey)).getSingleResult(); } catch (NoResultException e) { value = null; } catch (NonUniqueResultException e) { - throw new VersionsException("Many versions results for one-to-one relationship: (" + owningEntityName + + throw new AuditException("Many versions results for one-to-one relationship: (" + owningEntityName + ", " + owningReferencePropertyName + ")"); } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java index 49e92a4d21..4753829214 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java @@ -28,12 +28,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData; import org.hibernate.envers.entities.mapper.PropertyMapper; import org.hibernate.envers.entities.mapper.id.IdMapper; import org.hibernate.envers.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.Tools; import org.hibernate.envers.tools.reflection.ReflectionTools; @@ -63,8 +63,8 @@ public class ToOneIdMapper implements PropertyMapper { return !Tools.objectsEqual(newObj, oldObj); } - public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, - VersionsReaderImplementor versionsReader, Number revision) { + public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, + AuditReaderImplementor versionsReader, Number revision) { if (obj == null) { return; } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java index 2983594c74..0879001125 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java @@ -25,7 +25,7 @@ package org.hibernate.envers.entities.mapper.relation.component; import java.util.Map; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.EntityInstantiator; import org.hibernate.envers.entities.mapper.id.IdMapper; import org.hibernate.envers.tools.query.Parameters; @@ -37,10 +37,10 @@ import org.hibernate.envers.tools.query.Parameters; * @author Adam Warski (adam at warski dot org) */ public final class MiddleMapKeyIdComponentMapper implements MiddleComponentMapper { - private final VersionsEntitiesConfiguration verEntCfg; + private final AuditEntitiesConfiguration verEntCfg; private final IdMapper relatedIdMapper; - public MiddleMapKeyIdComponentMapper(VersionsEntitiesConfiguration verEntCfg, IdMapper relatedIdMapper) { + public MiddleMapKeyIdComponentMapper(AuditEntitiesConfiguration verEntCfg, IdMapper relatedIdMapper) { this.verEntCfg = verEntCfg; this.relatedIdMapper = relatedIdMapper; } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java index 001913f123..8ee29ae74e 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java @@ -25,7 +25,7 @@ package org.hibernate.envers.entities.mapper.relation.component; import java.util.Map; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.EntityInstantiator; import org.hibernate.envers.tools.query.Parameters; @@ -34,9 +34,9 @@ import org.hibernate.envers.tools.query.Parameters; */ public final class MiddleSimpleComponentMapper implements MiddleComponentMapper { private final String propertyName; - private final VersionsEntitiesConfiguration verEntCfg; + private final AuditEntitiesConfiguration verEntCfg; - public MiddleSimpleComponentMapper(VersionsEntitiesConfiguration verEntCfg, String propertyName) { + public MiddleSimpleComponentMapper(AuditEntitiesConfiguration verEntCfg, String propertyName) { this.propertyName = propertyName; this.verEntCfg = verEntCfg; } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java index ec9eb23c1d..5a88ab41e9 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.entities.mapper.relation.lazy; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.HibernateException; @@ -31,12 +31,12 @@ import org.hibernate.HibernateException; * @author Adam Warski (adam at warski dot org) */ public class ToOneDelegateSessionImplementor extends AbstractDelegateSessionImplementor { - private final VersionsReaderImplementor versionsReader; + private final AuditReaderImplementor versionsReader; private final Class entityClass; private final Object entityId; private final Number revision; - public ToOneDelegateSessionImplementor(VersionsReaderImplementor versionsReader, + public ToOneDelegateSessionImplementor(AuditReaderImplementor versionsReader, Class entityClass, Object entityId, Number revision) { super(versionsReader.getSessionImplementor()); this.versionsReader = versionsReader; diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java index 4dab5f0384..c6a12d0018 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java @@ -25,25 +25,25 @@ package org.hibernate.envers.entities.mapper.relation.lazy.initializor; import java.util.List; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.EntityInstantiator; import org.hibernate.envers.entities.mapper.relation.query.RelationQueryGenerator; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; /** * Initializes a persistent collection. * @author Adam Warski (adam at warski dot org) */ public abstract class AbstractCollectionInitializor implements Initializor { - private final VersionsReaderImplementor versionsReader; + private final AuditReaderImplementor versionsReader; private final RelationQueryGenerator queryGenerator; private final Object primaryKey; protected final Number revision; protected final EntityInstantiator entityInstantiator; - public AbstractCollectionInitializor(VersionsConfiguration verCfg, - VersionsReaderImplementor versionsReader, + public AbstractCollectionInitializor(AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, RelationQueryGenerator queryGenerator, Object primaryKey, Number revision) { this.versionsReader = versionsReader; diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java index 20059da979..d12245dc39 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java @@ -26,10 +26,10 @@ package org.hibernate.envers.entities.mapper.relation.lazy.initializor; import java.util.List; import java.util.Map; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.entities.mapper.relation.query.RelationQueryGenerator; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; /** * Initializes a map. @@ -39,8 +39,8 @@ public class ArrayCollectionInitializor extends AbstractCollectionInitializor extends AbstractCo private final Class collectionClass; private final MiddleComponentData elementComponentData; - public BasicCollectionInitializor(VersionsConfiguration verCfg, - VersionsReaderImplementor versionsReader, + public BasicCollectionInitializor(AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, RelationQueryGenerator queryGenerator, Object primaryKey, Number revision, Class collectionClass, @@ -57,9 +57,9 @@ public class BasicCollectionInitializor extends AbstractCo try { return collectionClass.newInstance(); } catch (InstantiationException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java index d2efeba905..51196e3884 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java @@ -27,10 +27,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.entities.mapper.relation.query.RelationQueryGenerator; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; /** * Initializes a map. @@ -40,8 +40,8 @@ public class ListCollectionInitializor extends AbstractCollectionInitializor extends AbstractCollectionI private final MiddleComponentData elementComponentData; private final MiddleComponentData indexComponentData; - public MapCollectionInitializor(VersionsConfiguration verCfg, - VersionsReaderImplementor versionsReader, + public MapCollectionInitializor(AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, RelationQueryGenerator queryGenerator, Object primaryKey, Number revision, Class collectionClass, @@ -59,9 +59,9 @@ public class MapCollectionInitializor extends AbstractCollectionI try { return collectionClass.newInstance(); } catch (InstantiationException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java index bc37b37c67..22e1630dfd 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java @@ -26,11 +26,11 @@ package org.hibernate.envers.entities.mapper.relation.query; import java.util.Collections; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.mapper.id.QueryParameterData; import org.hibernate.envers.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.entities.mapper.relation.MiddleIdData; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; @@ -44,7 +44,7 @@ public final class OneEntityQueryGenerator implements RelationQueryGenerator { private final String queryString; private final MiddleIdData referencingIdData; - public OneEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg, + public OneEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName, MiddleIdData referencingIdData, MiddleComponentData... componentDatas) { @@ -95,7 +95,7 @@ public final class OneEntityQueryGenerator implements RelationQueryGenerator { queryString = sb.toString(); } - public Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision) { + public Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision) { Query query = versionsReader.getSession().createQuery(queryString); query.setParameter("revision", revision); query.setParameter("delrevisiontype", RevisionType.DEL); diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java index aa012a936e..a76444a027 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java @@ -27,11 +27,11 @@ import java.util.Collections; import org.hibernate.envers.RevisionType; import org.hibernate.envers.configuration.GlobalConfiguration; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.mapper.id.IdMapper; import org.hibernate.envers.entities.mapper.id.QueryParameterData; import org.hibernate.envers.entities.mapper.relation.MiddleIdData; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; @@ -45,7 +45,7 @@ public final class OneVersionsEntityQueryGenerator implements RelationQueryGener private final String queryString; private final MiddleIdData referencingIdData; - public OneVersionsEntityQueryGenerator(GlobalConfiguration globalCfg, VersionsEntitiesConfiguration verEntCfg, + public OneVersionsEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData, String referencedEntityName, IdMapper referencedIdMapper) { this.referencingIdData = referencingIdData; @@ -97,7 +97,7 @@ public final class OneVersionsEntityQueryGenerator implements RelationQueryGener queryString = sb.toString(); } - public Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision) { + public Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision) { Query query = versionsReader.getSession().createQuery(queryString); query.setParameter("revision", revision); query.setParameter("delrevisiontype", RevisionType.DEL); diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java index 1af79b5d11..b27b2bcd55 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.entities.mapper.relation.query; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.Query; @@ -34,5 +34,5 @@ import org.hibernate.Query; * @author Adam Warski (adam at warski dot org) */ public interface RelationQueryGenerator { - Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision); + Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision); } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java index d2fb3e3a53..28cef7e9a6 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java @@ -27,11 +27,11 @@ import java.util.Collections; import org.hibernate.envers.RevisionType; import org.hibernate.envers.configuration.GlobalConfiguration; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.mapper.id.QueryParameterData; import org.hibernate.envers.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.entities.mapper.relation.MiddleIdData; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; @@ -46,7 +46,7 @@ public final class ThreeEntityQueryGenerator implements RelationQueryGenerator { private final MiddleIdData referencingIdData; public ThreeEntityQueryGenerator(GlobalConfiguration globalCfg, - VersionsEntitiesConfiguration verEntCfg, + AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName, MiddleIdData referencingIdData, MiddleIdData referencedIdData, @@ -123,7 +123,7 @@ public final class ThreeEntityQueryGenerator implements RelationQueryGenerator { queryString = sb.toString(); } - public Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision) { + public Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision) { Query query = versionsReader.getSession().createQuery(queryString); query.setParameter("revision", revision); query.setParameter("delrevisiontype", RevisionType.DEL); diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java index f2ab5309c8..aa338a18b1 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java @@ -27,11 +27,11 @@ import java.util.Collections; import org.hibernate.envers.RevisionType; import org.hibernate.envers.configuration.GlobalConfiguration; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.mapper.id.QueryParameterData; import org.hibernate.envers.entities.mapper.relation.MiddleComponentData; import org.hibernate.envers.entities.mapper.relation.MiddleIdData; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; @@ -46,7 +46,7 @@ public final class TwoEntityQueryGenerator implements RelationQueryGenerator { private final MiddleIdData referencingIdData; public TwoEntityQueryGenerator(GlobalConfiguration globalCfg, - VersionsEntitiesConfiguration verEntCfg, + AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName, MiddleIdData referencingIdData, MiddleIdData referencedIdData, @@ -106,7 +106,7 @@ public final class TwoEntityQueryGenerator implements RelationQueryGenerator { queryString = sb.toString(); } - public Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision) { + public Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision) { Query query = versionsReader.getSession().createQuery(queryString); query.setParameter("revision", revision); query.setParameter("delrevisiontype", RevisionType.DEL); diff --git a/envers/src/main/java/org/hibernate/envers/event/VersionsEventListener.java b/envers/src/main/java/org/hibernate/envers/event/VersionsEventListener.java index 6aeba4844c..978d533e8e 100644 --- a/envers/src/main/java/org/hibernate/envers/event/VersionsEventListener.java +++ b/envers/src/main/java/org/hibernate/envers/event/VersionsEventListener.java @@ -25,12 +25,12 @@ package org.hibernate.envers.event; import java.io.Serializable; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.RelationDescription; import org.hibernate.envers.entities.RelationType; import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData; import org.hibernate.envers.entities.mapper.id.IdMapper; -import org.hibernate.envers.synchronization.VersionsSync; +import org.hibernate.envers.synchronization.AuditSync; import org.hibernate.envers.synchronization.work.AddWorkUnit; import org.hibernate.envers.synchronization.work.CollectionChangeWorkUnit; import org.hibernate.envers.synchronization.work.DelWorkUnit; @@ -63,9 +63,9 @@ import org.hibernate.persister.entity.EntityPersister; public class VersionsEventListener implements PostInsertEventListener, PostUpdateEventListener, PostDeleteEventListener, PreCollectionUpdateEventListener, PreCollectionRemoveEventListener, PostCollectionRecreateEventListener, Initializable { - private VersionsConfiguration verCfg; + private AuditConfiguration verCfg; - private void generateBidirectionalCollectionChangeWorkUnits(VersionsSync verSync, EntityPersister entityPersister, + private void generateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, EntityPersister entityPersister, String entityName, Object[] newState, Object[] oldState) { // Checking if this is enabled in configuration ... if (!verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) { @@ -108,7 +108,7 @@ public class VersionsEventListener implements PostInsertEventListener, PostUpdat String entityName = event.getPersister().getEntityName(); if (verCfg.getEntCfg().isVersioned(entityName)) { - VersionsSync verSync = verCfg.getSyncManager().get(event.getSession()); + AuditSync verSync = verCfg.getSyncManager().get(event.getSession()); verSync.addWorkUnit(new AddWorkUnit(event.getPersister().getEntityName(), verCfg, event.getId(), event.getPersister(), event.getState())); @@ -121,7 +121,7 @@ public class VersionsEventListener implements PostInsertEventListener, PostUpdat String entityName = event.getPersister().getEntityName(); if (verCfg.getEntCfg().isVersioned(entityName)) { - VersionsSync verSync = verCfg.getSyncManager().get(event.getSession()); + AuditSync verSync = verCfg.getSyncManager().get(event.getSession()); verSync.addWorkUnit(new ModWorkUnit(event.getPersister().getEntityName(), verCfg, event.getId(), event.getPersister(), event.getState(), event.getOldState())); @@ -134,7 +134,7 @@ public class VersionsEventListener implements PostInsertEventListener, PostUpdat String entityName = event.getPersister().getEntityName(); if (verCfg.getEntCfg().isVersioned(entityName)) { - VersionsSync verSync = verCfg.getSyncManager().get(event.getSession()); + AuditSync verSync = verCfg.getSyncManager().get(event.getSession()); verSync.addWorkUnit(new DelWorkUnit(event.getPersister().getEntityName(), verCfg, event.getId())); @@ -142,7 +142,7 @@ public class VersionsEventListener implements PostInsertEventListener, PostUpdat } } - private void generateBidirectionalCollectionChangeWorkUnits(VersionsSync verSync, AbstractCollectionEvent event, + private void generateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, AbstractCollectionEvent event, PersistentCollectionChangeWorkUnit workUnit) { // Checking if this is enabled in configuration ... if (!verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) { @@ -173,7 +173,7 @@ public class VersionsEventListener implements PostInsertEventListener, PostUpdat String entityName = event.getAffectedOwnerEntityName(); if (verCfg.getEntCfg().isVersioned(entityName)) { - VersionsSync verSync = verCfg.getSyncManager().get(event.getSession()); + AuditSync verSync = verCfg.getSyncManager().get(event.getSession()); PersistentCollectionChangeWorkUnit workUnit = new PersistentCollectionChangeWorkUnit(entityName, verCfg, newColl, collectionEntry.getRole(), oldColl, event.getAffectedOwnerIdOrNull()); @@ -209,10 +209,10 @@ public class VersionsEventListener implements PostInsertEventListener, PostUpdat @SuppressWarnings({"unchecked"}) public void initialize(Configuration cfg) { - verCfg = VersionsConfiguration.getFor(cfg); + verCfg = AuditConfiguration.getFor(cfg); } - public VersionsConfiguration getVerCfg() { + public AuditConfiguration getVerCfg() { return verCfg; } } diff --git a/envers/src/main/java/org/hibernate/envers/exception/AuditException.java b/envers/src/main/java/org/hibernate/envers/exception/AuditException.java new file mode 100644 index 0000000000..f6a5c8ecb5 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/exception/AuditException.java @@ -0,0 +1,43 @@ +/* + * 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.exception; + +import org.hibernate.HibernateException; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class AuditException extends HibernateException { + public AuditException(String message) { + super(message); + } + + public AuditException(String message, Throwable cause) { + super(message, cause); + } + + public AuditException(Throwable cause) { + super(cause); + } +} diff --git a/envers/src/main/java/org/hibernate/envers/exception/NotVersionedException.java b/envers/src/main/java/org/hibernate/envers/exception/NotVersionedException.java index d855b6d462..4f5101d11a 100644 --- a/envers/src/main/java/org/hibernate/envers/exception/NotVersionedException.java +++ b/envers/src/main/java/org/hibernate/envers/exception/NotVersionedException.java @@ -26,7 +26,7 @@ package org.hibernate.envers.exception; /** * @author Adam Warski (adam at warski dot org) */ -public class NotVersionedException extends VersionsException { +public class NotVersionedException extends AuditException { private final String entityName; public NotVersionedException(String entityName, String message) { diff --git a/envers/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java b/envers/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java index dbd54f526b..b85ff1c544 100644 --- a/envers/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java +++ b/envers/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java @@ -28,7 +28,7 @@ import java.util.Date; /** * @author Adam Warski (adam at warski dot org) */ -public class RevisionDoesNotExistException extends VersionsException { +public class RevisionDoesNotExistException extends AuditException { private Number revision; private Date date; diff --git a/envers/src/main/java/org/hibernate/envers/query/AuditQuery.java b/envers/src/main/java/org/hibernate/envers/query/AuditQuery.java new file mode 100644 index 0000000000..f5d867499b --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/query/AuditQuery.java @@ -0,0 +1,75 @@ +/* + * 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.List; +import javax.persistence.NoResultException; +import javax.persistence.NonUniqueResultException; + +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.query.criteria.AuditCriterion; +import org.hibernate.envers.query.order.AuditOrder; +import org.hibernate.envers.query.projection.AuditProjection; + +import org.hibernate.CacheMode; +import org.hibernate.FlushMode; +import org.hibernate.LockMode; + +/** + * @author Adam Warski (adam at warski dot org) + * @see org.hibernate.Criteria + */ +public interface AuditQuery { + List getResultList() throws AuditException; + + Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException; + + AuditQuery add(AuditCriterion criterion); + + AuditQuery addProjection(String function, String propertyName); + + AuditQuery addProjection(AuditProjection projection); + + AuditQuery addOrder(String propertyName, boolean asc); + + AuditQuery addOrder(AuditOrder order); + + AuditQuery setMaxResults(int maxResults); + + AuditQuery setFirstResult(int firstResult); + + AuditQuery setCacheable(boolean cacheable); + + AuditQuery setCacheRegion(String cacheRegion); + + AuditQuery setComment(String comment); + + AuditQuery setFlushMode(FlushMode flushMode); + + AuditQuery setCacheMode(CacheMode cacheMode); + + AuditQuery setTimeout(int timeout); + + AuditQuery setLockMode(LockMode lockMode); +} diff --git a/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java b/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java new file mode 100644 index 0000000000..2674d43715 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java @@ -0,0 +1,83 @@ +/* + * 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.configuration.AuditConfiguration; +import org.hibernate.envers.query.impl.EntitiesAtRevisionQuery; +import org.hibernate.envers.query.impl.RevisionsOfEntityQuery; +import org.hibernate.envers.reader.AuditReaderImplementor; +import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull; +import static org.hibernate.envers.tools.ArgumentsTools.checkPositive; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class AuditQueryCreator { + private final AuditConfiguration verCfg; + private final AuditReaderImplementor versionsReaderImplementor; + + public AuditQueryCreator(AuditConfiguration verCfg, AuditReaderImplementor versionsReaderImplementor) { + this.verCfg = verCfg; + this.versionsReaderImplementor = versionsReaderImplementor; + } + + /** + * Creates a query, which will return entities satisfying some conditions (specified later), + * at a given revision. + * @param c Class of the entities for which to query. + * @param revision Revision number at which to execute the query. + * @return A query for entities at a given revision, to which conditions can be added and which + * can then be executed. The result of the query will be a list of entities (beans), unless a + * projection is added. + */ + public AuditQuery forEntitiesAtRevision(Class c, Number revision) { + checkNotNull(revision, "Entity revision"); + checkPositive(revision, "Entity revision"); + return new EntitiesAtRevisionQuery(verCfg, versionsReaderImplementor, c, revision); + } + + /** + * Creates a query, which selects the revisions, at which the given entity was modified. + * Unless an explicit projection is set, the result will be a list of three-element arrays, containing: + *
    + *
  1. the entity instance
  2. + *
  3. revision entity, corresponding to the revision at which the entity was modified. If no custom + * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}
  4. + *
  5. type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})
  6. . + *
+ * Additional conditions that the results must satisfy may be specified. + * @param c Class of the entities for which to query. + * @param selectEntitiesOnly If true, instead of a list of three-element arrays, a list of entites will be + * returned as a result of executing this query. + * @param selectDeletedEntities If true, also revisions where entities were deleted will be returned. The additional + * entities will have revision type "delete", and contain no data (all fields null), except for the id field. + * @return A query for revisions at which instances of the given entity were modified, to which + * conditions can be added (for example - a specific id of an entity of class c), and which + * can then be executed. The results of the query will be sorted in ascending order by the revision number, + * unless an order or projection is added. + */ + public AuditQuery forRevisionsOfEntity(Class c, boolean selectEntitiesOnly, boolean selectDeletedEntities) { + return new RevisionsOfEntityQuery(verCfg, versionsReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities); + } +} diff --git a/envers/src/main/java/org/hibernate/envers/query/AuditRestrictions.java b/envers/src/main/java/org/hibernate/envers/query/AuditRestrictions.java new file mode 100644 index 0000000000..2a087e6ec8 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/query/AuditRestrictions.java @@ -0,0 +1,246 @@ +/* + * 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 IdentifierEqVersionsExpression(value); + } + + /** + * Apply an "equal" constraint to the named property + */ + public static AuditCriterion eq(String propertyName, Object value) { + return new SimpleVersionsExpression(propertyName, value, "="); + } + + /** + * Apply a "not equal" constraint to the named property + */ + public static AuditCriterion ne(String propertyName, Object value) { + return new SimpleVersionsExpression(propertyName, value, "<>"); + } + + /** + * Apply an "equal" constraint on an id of a related entity + */ + public static AuditCriterion relatedIdEq(String propertyName, Object id) { + return new RelatedVersionsExpression(propertyName, id, true); + } + + /** + * Apply a "not equal" constraint to the named property + */ + public static AuditCriterion relatedIdNe(String propertyName, Object id) { + return new RelatedVersionsExpression(propertyName, id, false); + } + + /** + * Apply a "like" constraint to the named property + */ + public static AuditCriterion like(String propertyName, Object value) { + return new SimpleVersionsExpression(propertyName, value, " like "); + } + + /** + * Apply a "like" constraint to the named property + */ + public static AuditCriterion like(String propertyName, String value, MatchMode matchMode) { + return new SimpleVersionsExpression(propertyName, matchMode.toMatchString(value), " like " ); + } + + /** + * Apply a "greater than" constraint to the named property + */ + public static AuditCriterion gt(String propertyName, Object value) { + return new SimpleVersionsExpression(propertyName, value, ">"); + } + + /** + * Apply a "less than" constraint to the named property + */ + public static AuditCriterion lt(String propertyName, Object value) { + return new SimpleVersionsExpression(propertyName, value, "<"); + } + + /** + * Apply a "less than or equal" constraint to the named property + */ + public static AuditCriterion le(String propertyName, Object value) { + return new SimpleVersionsExpression(propertyName, value, "<="); + } + + /** + * Apply a "greater than or equal" constraint to the named property + */ + public static AuditCriterion ge(String propertyName, Object value) { + return new SimpleVersionsExpression(propertyName, value, ">="); + } + + /** + * Apply a "between" constraint to the named property + */ + public static AuditCriterion between(String propertyName, Object lo, Object hi) { + return new BetweenVersionsExpression(propertyName, lo, hi); + } + + /** + * Apply an "in" constraint to the named property + */ + public static AuditCriterion in(String propertyName, Object[] values) { + return new InVersionsExpression(propertyName, values); + } + + /** + * Apply an "in" constraint to the named property + */ + public static AuditCriterion in(String propertyName, Collection values) { + return new InVersionsExpression(propertyName, values.toArray()); + } + + /** + * Apply an "is null" constraint to the named property + */ + public static AuditCriterion isNull(String propertyName) { + return new NullVersionsExpression(propertyName); + } + + /** + * Apply an "equal" constraint to two properties + */ + public static AuditCriterion eqProperty(String propertyName, String otherPropertyName) { + return new PropertyVersionsExpression(propertyName, otherPropertyName, "="); + } + + /** + * Apply a "not equal" constraint to two properties + */ + public static AuditCriterion neProperty(String propertyName, String otherPropertyName) { + return new PropertyVersionsExpression(propertyName, otherPropertyName, "<>"); + } + + /** + * Apply a "less than" constraint to two properties + */ + public static AuditCriterion ltProperty(String propertyName, String otherPropertyName) { + return new PropertyVersionsExpression(propertyName, otherPropertyName, "<"); + } + + /** + * Apply a "less than or equal" constraint to two properties + */ + public static AuditCriterion leProperty(String propertyName, String otherPropertyName) { + return new PropertyVersionsExpression(propertyName, otherPropertyName, "<="); + } + + /** + * Apply a "greater than" constraint to two properties + */ + public static AuditCriterion gtProperty(String propertyName, String otherPropertyName) { + return new PropertyVersionsExpression(propertyName, otherPropertyName, ">"); + } + + /** + * Apply a "greater than or equal" constraint to two properties + */ + public static AuditCriterion geProperty(String propertyName, String otherPropertyName) { + return new PropertyVersionsExpression(propertyName, otherPropertyName, ">="); + } + + /** + * Apply an "is not null" constraint to the named property + */ + public static AuditCriterion isNotNull(String propertyName) { + return new NotNullVersionsExpression(propertyName); + } + + /** + * Return the conjuction of two expressions + */ + public static AuditCriterion and(AuditCriterion lhs, AuditCriterion rhs) { + return new LogicalVersionsExpression(lhs, rhs, "and"); + } + + /** + * Return the disjuction of two expressions + */ + public static AuditCriterion or(AuditCriterion lhs, AuditCriterion rhs) { + return new LogicalVersionsExpression(lhs, rhs, "or"); + } + + /** + * Return the negation of an expression + */ + public static AuditCriterion not(AuditCriterion expression) { + return new NotVersionsExpression(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 AggregatedFieldVersionsExpression maximizeProperty(String propertyName) { + return new AggregatedFieldVersionsExpression(propertyName, + AggregatedFieldVersionsExpression.AggregatedMode.MAX); + } + + /** + * Apply a "minimize property" constraint. + */ + public static AggregatedFieldVersionsExpression minimizeProperty(String propertyName) { + return new AggregatedFieldVersionsExpression(propertyName, + AggregatedFieldVersionsExpression.AggregatedMode.MIN); + } +} diff --git a/envers/src/main/java/org/hibernate/envers/query/RevisionProperty.java b/envers/src/main/java/org/hibernate/envers/query/RevisionProperty.java index 468ad7fc6d..522b2cabf6 100644 --- a/envers/src/main/java/org/hibernate/envers/query/RevisionProperty.java +++ b/envers/src/main/java/org/hibernate/envers/query/RevisionProperty.java @@ -23,107 +23,107 @@ */ package org.hibernate.envers.query; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.query.criteria.RevisionVersionsExpression; -import org.hibernate.envers.query.criteria.VersionsCriterion; +import org.hibernate.envers.query.criteria.AuditCriterion; import org.hibernate.envers.query.order.RevisionVersionsOrder; -import org.hibernate.envers.query.order.VersionsOrder; +import org.hibernate.envers.query.order.AuditOrder; import org.hibernate.envers.query.projection.RevisionVersionsProjection; -import org.hibernate.envers.query.projection.VersionsProjection; +import org.hibernate.envers.query.projection.AuditProjection; import org.hibernate.envers.tools.Triple; /** * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"JavaDoc"}) -public class RevisionProperty implements VersionsProjection { +public class RevisionProperty implements AuditProjection { private RevisionProperty() { } /** * Apply a "greater than" constraint on the revision number */ - public static VersionsCriterion gt(Integer revision) { + public static AuditCriterion gt(Integer revision) { return new RevisionVersionsExpression(revision, ">"); } /** * Apply a "greater than or equal" constraint on the revision number */ - public static VersionsCriterion ge(Integer revision) { + public static AuditCriterion ge(Integer revision) { return new RevisionVersionsExpression(revision, ">="); } /** * Apply a "less than" constraint on the revision number */ - public static VersionsCriterion lt(Integer revision) { + public static AuditCriterion lt(Integer revision) { return new RevisionVersionsExpression(revision, "<"); } /** * Apply a "less than or equal" constraint on the revision number */ - public static VersionsCriterion le(Integer revision) { + public static AuditCriterion le(Integer revision) { return new RevisionVersionsExpression(revision, "<="); } /** * Sort the results by revision in ascending order */ - public static VersionsOrder asc() { + public static AuditOrder asc() { return new RevisionVersionsOrder(true); } /** * Sort the results by revision in descending order */ - public static VersionsOrder desc() { + public static AuditOrder desc() { return new RevisionVersionsOrder(false); } /** * Select the maximum revision */ - public static VersionsProjection max() { + public static AuditProjection max() { return new RevisionVersionsProjection(RevisionVersionsProjection.ProjectionType.MAX); } /** * Select the minimum revision */ - public static VersionsProjection min() { + public static AuditProjection min() { return new RevisionVersionsProjection(RevisionVersionsProjection.ProjectionType.MIN); } /** * Count revisions */ - public static VersionsProjection count() { + public static AuditProjection count() { return new RevisionVersionsProjection(RevisionVersionsProjection.ProjectionType.COUNT); } /** * Count distinct revisions */ - public static VersionsProjection countDistinct() { + public static AuditProjection countDistinct() { return new RevisionVersionsProjection(RevisionVersionsProjection.ProjectionType.COUNT_DISTINCT); } /** * Distinct revisions */ - public static VersionsProjection distinct() { + public static AuditProjection distinct() { return new RevisionVersionsProjection(RevisionVersionsProjection.ProjectionType.DISTINCT); } /** * Projection the revision number */ - public static VersionsProjection revisionNumber() { + public static AuditProjection revisionNumber() { return new RevisionProperty(); } - public Triple getData(VersionsConfiguration verCfg) { + public Triple getData(AuditConfiguration verCfg) { return Triple.make(null, verCfg.getVerEntCfg().getRevisionPropPath(), false); } } diff --git a/envers/src/main/java/org/hibernate/envers/query/RevisionTypeProperty.java b/envers/src/main/java/org/hibernate/envers/query/RevisionTypeProperty.java index 72787449bb..a2b9a8c926 100644 --- a/envers/src/main/java/org/hibernate/envers/query/RevisionTypeProperty.java +++ b/envers/src/main/java/org/hibernate/envers/query/RevisionTypeProperty.java @@ -23,25 +23,25 @@ */ package org.hibernate.envers.query; -import org.hibernate.envers.configuration.VersionsConfiguration; -import org.hibernate.envers.query.projection.VersionsProjection; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.query.projection.AuditProjection; import org.hibernate.envers.tools.Triple; /** * @author Adam Warski (adam at warski dot org) */ @SuppressWarnings({"JavaDoc"}) -public class RevisionTypeProperty implements VersionsProjection { +public class RevisionTypeProperty implements AuditProjection { private RevisionTypeProperty() { } /** * Projection on the revision type */ - public static VersionsProjection revisionType() { + public static AuditProjection revisionType() { return new RevisionTypeProperty(); } - public Triple getData(VersionsConfiguration verCfg) { + public Triple getData(AuditConfiguration verCfg) { return Triple.make(null, verCfg.getVerEntCfg().getRevisionTypePropName(), false); } } \ No newline at end of file diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedFieldVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedFieldVersionsExpression.java index 379761c3e2..f1d0d7510d 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedFieldVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedFieldVersionsExpression.java @@ -26,14 +26,14 @@ package org.hibernate.envers.query.criteria; import java.util.ArrayList; import java.util.List; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class AggregatedFieldVersionsExpression implements VersionsCriterion, ExtendableCriterion { +public class AggregatedFieldVersionsExpression implements AuditCriterion, ExtendableCriterion { public static enum AggregatedMode { MAX, MIN @@ -41,20 +41,20 @@ public class AggregatedFieldVersionsExpression implements VersionsCriterion, Ext private String propertyName; private AggregatedMode mode; - private List criterions; + private List criterions; public AggregatedFieldVersionsExpression(String propertyName, AggregatedMode mode) { this.propertyName = propertyName; this.mode = mode; - criterions = new ArrayList(); + criterions = new ArrayList(); } - public AggregatedFieldVersionsExpression add(VersionsCriterion criterion) { + public AggregatedFieldVersionsExpression add(AuditCriterion criterion) { criterions.add(criterion); return this; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName); // This will be the aggregated query, containing all the specified conditions @@ -62,7 +62,7 @@ public class AggregatedFieldVersionsExpression implements VersionsCriterion, Ext // Adding all specified conditions both to the main query, as well as to the // aggregated one. - for (VersionsCriterion versionsCriteria : criterions) { + for (AuditCriterion versionsCriteria : criterions) { versionsCriteria.addToQuery(verCfg, entityName, qb, parameters); versionsCriteria.addToQuery(verCfg, entityName, subQb, subQb.getRootParameters()); } diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java b/envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java new file mode 100644 index 0000000000..271f3d0956 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java @@ -0,0 +1,55 @@ +/* + * 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.criteria; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.tools.query.Parameters; +import org.hibernate.envers.tools.query.QueryBuilder; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class AuditConjunction implements AuditCriterion, ExtendableCriterion { + private List criterions; + + public AuditConjunction() { + criterions = new ArrayList(); + } + + public AuditConjunction add(AuditCriterion criterion) { + criterions.add(criterion); + return this; + } + + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + Parameters andParameters = parameters.addSubParameters(Parameters.AND); + + for (AuditCriterion criterion : criterions) { + criterion.addToQuery(verCfg, entityName, qb, andParameters); + } + } +} diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java b/envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java new file mode 100644 index 0000000000..4f5e1cf5b1 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java @@ -0,0 +1,35 @@ +/* + * 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.criteria; + +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.tools.query.Parameters; +import org.hibernate.envers.tools.query.QueryBuilder; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public interface AuditCriterion { + void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters); +} diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java b/envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java new file mode 100644 index 0000000000..eaac91f866 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java @@ -0,0 +1,55 @@ +/* + * 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.criteria; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.tools.query.Parameters; +import org.hibernate.envers.tools.query.QueryBuilder; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class AuditDisjunction implements AuditCriterion, ExtendableCriterion { + private List criterions; + + public AuditDisjunction() { + criterions = new ArrayList(); + } + + public AuditDisjunction add(AuditCriterion criterion) { + criterions.add(criterion); + return this; + } + + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + Parameters orParameters = parameters.addSubParameters(Parameters.OR); + + for (AuditCriterion criterion : criterions) { + criterion.addToQuery(verCfg, entityName, qb, orParameters); + } + } +} \ No newline at end of file diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/BetweenVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/BetweenVersionsExpression.java index f11dd4cfa6..7afa86cd7e 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/BetweenVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/BetweenVersionsExpression.java @@ -23,14 +23,14 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class BetweenVersionsExpression implements VersionsCriterion { +public class BetweenVersionsExpression implements AuditCriterion { private String propertyName; private Object lo; private Object hi; @@ -41,7 +41,7 @@ public class BetweenVersionsExpression implements VersionsCriterion { this.hi = hi; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName); parameters.addWhereWithParam(propertyName, ">=", lo); parameters.addWhereWithParam(propertyName, "<=", hi); diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/CriteriaTools.java b/envers/src/main/java/org/hibernate/envers/query/criteria/CriteriaTools.java index 2d96435af7..3780b5fbfb 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/CriteriaTools.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/CriteriaTools.java @@ -23,10 +23,10 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.RelationDescription; import org.hibernate.envers.entities.RelationType; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; /** * @author Adam Warski (adam at warski dot org) @@ -34,16 +34,16 @@ import org.hibernate.envers.exception.VersionsException; public class CriteriaTools { private CriteriaTools() { } - public static void checkPropertyNotARelation(VersionsConfiguration verCfg, String entityName, - String propertyName) throws VersionsException { + public static void checkPropertyNotARelation(AuditConfiguration verCfg, String entityName, + String propertyName) throws AuditException { if (verCfg.getEntCfg().get(entityName).isRelation(propertyName)) { - throw new VersionsException("This criterion cannot be used on a property that is " + + throw new AuditException("This criterion cannot be used on a property that is " + "a relation to another property."); } } - public static RelationDescription getRelatedEntity(VersionsConfiguration verCfg, String entityName, - String propertyName) throws VersionsException { + public static RelationDescription getRelatedEntity(AuditConfiguration verCfg, String entityName, + String propertyName) throws AuditException { RelationDescription relationDesc = verCfg.getEntCfg().getRelationDescription(entityName, propertyName); if (relationDesc == null) { @@ -54,7 +54,7 @@ public class CriteriaTools { return relationDesc; } - throw new VersionsException("This type of relation (" + entityName + "." + propertyName + + throw new AuditException("This type of relation (" + entityName + "." + propertyName + ") isn't supported and can't be used in queries."); } } diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java b/envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java index a87cd3d727..b0f6312949 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/ExtendableCriterion.java @@ -27,5 +27,5 @@ package org.hibernate.envers.query.criteria; * @author Adam Warski (adam at warski dot org) */ public interface ExtendableCriterion { - public ExtendableCriterion add(VersionsCriterion criterion); + public ExtendableCriterion add(AuditCriterion criterion); } diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/IdentifierEqVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/IdentifierEqVersionsExpression.java index 4d553c3ba2..817c4082d0 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/IdentifierEqVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/IdentifierEqVersionsExpression.java @@ -23,21 +23,21 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class IdentifierEqVersionsExpression implements VersionsCriterion { +public class IdentifierEqVersionsExpression implements AuditCriterion { private Object id; public IdentifierEqVersionsExpression(Object id) { this.id = id; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { verCfg.getEntCfg().get(entityName).getIdMapper() .addIdEqualsToQuery(parameters, id, verCfg.getVerEntCfg().getOriginalIdPropName(), true); } diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/InVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/InVersionsExpression.java index f6b69b7172..7caeeffc86 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/InVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/InVersionsExpression.java @@ -23,14 +23,14 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class InVersionsExpression implements VersionsCriterion { +public class InVersionsExpression implements AuditCriterion { private String propertyName; private Object[] values; @@ -39,7 +39,7 @@ public class InVersionsExpression implements VersionsCriterion { this.values = values; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName); parameters.addWhereWithParams(propertyName, "in (", values, ")"); } diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/LogicalVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/LogicalVersionsExpression.java index 1aba1643a1..10212894ff 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/LogicalVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/LogicalVersionsExpression.java @@ -23,25 +23,25 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class LogicalVersionsExpression implements VersionsCriterion { - private VersionsCriterion lhs; - private VersionsCriterion rhs; +public class LogicalVersionsExpression implements AuditCriterion { + private AuditCriterion lhs; + private AuditCriterion rhs; private String op; - public LogicalVersionsExpression(VersionsCriterion lhs, VersionsCriterion rhs, String op) { + public LogicalVersionsExpression(AuditCriterion lhs, AuditCriterion rhs, String op) { this.lhs = lhs; this.rhs = rhs; this.op = op; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { Parameters opParameters = parameters.addSubParameters(op); lhs.addToQuery(verCfg, entityName, qb, opParameters.addSubParameters("and")); diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/NotNullVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/NotNullVersionsExpression.java index bf4624e2fd..72053a8178 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/NotNullVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/NotNullVersionsExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.RelationDescription; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; @@ -31,14 +31,14 @@ import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class NotNullVersionsExpression implements VersionsCriterion { +public class NotNullVersionsExpression implements AuditCriterion { private String propertyName; public NotNullVersionsExpression(String propertyName) { this.propertyName = propertyName; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName); if (relatedEntity == null) { diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/NotVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/NotVersionsExpression.java index b7293ac63f..b6fd3d30ca 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/NotVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/NotVersionsExpression.java @@ -23,21 +23,21 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class NotVersionsExpression implements VersionsCriterion { - private VersionsCriterion criterion; +public class NotVersionsExpression implements AuditCriterion { + private AuditCriterion criterion; - public NotVersionsExpression(VersionsCriterion criterion) { + public NotVersionsExpression(AuditCriterion criterion) { this.criterion = criterion; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { criterion.addToQuery(verCfg, entityName, qb, parameters.addNegatedParameters()); } } diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/NullVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/NullVersionsExpression.java index d6b97ec519..10ec8379c6 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/NullVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/NullVersionsExpression.java @@ -23,7 +23,7 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.RelationDescription; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; @@ -31,14 +31,14 @@ import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class NullVersionsExpression implements VersionsCriterion { +public class NullVersionsExpression implements AuditCriterion { private String propertyName; public NullVersionsExpression(String propertyName) { this.propertyName = propertyName; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName); if (relatedEntity == null) { diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/PropertyVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/PropertyVersionsExpression.java index 3e90d26f23..b47825e863 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/PropertyVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/PropertyVersionsExpression.java @@ -23,14 +23,14 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class PropertyVersionsExpression implements VersionsCriterion { +public class PropertyVersionsExpression implements AuditCriterion { private String propertyName; private String otherPropertyName; private String op; @@ -41,7 +41,7 @@ public class PropertyVersionsExpression implements VersionsCriterion { this.op = op; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName); CriteriaTools.checkPropertyNotARelation(verCfg, entityName, otherPropertyName); parameters.addWhere(propertyName, op, otherPropertyName); diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/RelatedVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/RelatedVersionsExpression.java index 6f4683f440..aeb8b236ee 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/RelatedVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/RelatedVersionsExpression.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.RelationDescription; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class RelatedVersionsExpression implements VersionsCriterion { +public class RelatedVersionsExpression implements AuditCriterion { private String propertyName; private Object id; private boolean equals; @@ -43,11 +43,11 @@ public class RelatedVersionsExpression implements VersionsCriterion { this.equals = equals; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName); if (relatedEntity == null) { - throw new VersionsException("This criterion can only be used on a property that is " + + throw new AuditException("This criterion can only be used on a property that is " + "a relation to another property."); } else { relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, propertyName, equals); diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/RevisionVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/RevisionVersionsExpression.java index 89836e788c..8c73004970 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/RevisionVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/RevisionVersionsExpression.java @@ -23,14 +23,14 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class RevisionVersionsExpression implements VersionsCriterion { +public class RevisionVersionsExpression implements AuditCriterion { private Object value; private String op; @@ -39,7 +39,7 @@ public class RevisionVersionsExpression implements VersionsCriterion { this.op = op; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { parameters.addWhereWithParam(verCfg.getVerEntCfg().getRevisionPropPath(), op, value); } } \ No newline at end of file diff --git a/envers/src/main/java/org/hibernate/envers/query/criteria/SimpleVersionsExpression.java b/envers/src/main/java/org/hibernate/envers/query/criteria/SimpleVersionsExpression.java index dc6b7e98eb..ac07c4f64f 100644 --- a/envers/src/main/java/org/hibernate/envers/query/criteria/SimpleVersionsExpression.java +++ b/envers/src/main/java/org/hibernate/envers/query/criteria/SimpleVersionsExpression.java @@ -23,16 +23,16 @@ */ package org.hibernate.envers.query.criteria; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.RelationDescription; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.tools.query.Parameters; import org.hibernate.envers.tools.query.QueryBuilder; /** * @author Adam Warski (adam at warski dot org) */ -public class SimpleVersionsExpression implements VersionsCriterion { +public class SimpleVersionsExpression implements AuditCriterion { private String propertyName; private Object value; private String op; @@ -43,14 +43,14 @@ public class SimpleVersionsExpression implements VersionsCriterion { this.op = op; } - public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { + public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName); if (relatedEntity == null) { parameters.addWhereWithParam(propertyName, op, value); } else { if (!"=".equals(op) && !"<>".equals(op)) { - throw new VersionsException("This type of operation: " + op + " (" + entityName + "." + propertyName + + throw new AuditException("This type of operation: " + op + " (" + entityName + "." + propertyName + ") isn't supported and can't be used in queries."); } diff --git a/envers/src/main/java/org/hibernate/envers/query/impl/AbstractVersionsQuery.java b/envers/src/main/java/org/hibernate/envers/query/impl/AbstractVersionsQuery.java index e955a83ecb..9577bec2b9 100644 --- a/envers/src/main/java/org/hibernate/envers/query/impl/AbstractVersionsQuery.java +++ b/envers/src/main/java/org/hibernate/envers/query/impl/AbstractVersionsQuery.java @@ -30,14 +30,14 @@ import java.util.Map; import javax.persistence.NoResultException; import javax.persistence.NonUniqueResultException; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.entities.EntityInstantiator; -import org.hibernate.envers.exception.VersionsException; -import org.hibernate.envers.query.VersionsQuery; -import org.hibernate.envers.query.criteria.VersionsCriterion; -import org.hibernate.envers.query.order.VersionsOrder; -import org.hibernate.envers.query.projection.VersionsProjection; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.query.AuditQuery; +import org.hibernate.envers.query.criteria.AuditCriterion; +import org.hibernate.envers.query.order.AuditOrder; +import org.hibernate.envers.query.projection.AuditProjection; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.Pair; import org.hibernate.envers.tools.Triple; import org.hibernate.envers.tools.query.QueryBuilder; @@ -50,9 +50,9 @@ import org.hibernate.Query; /** * @author Adam Warski (adam at warski dot org) */ -public abstract class AbstractVersionsQuery implements VersionsQuery { +public abstract class AbstractVersionsQuery implements AuditQuery { protected EntityInstantiator entityInstantiator; - protected List criterions; + protected List criterions; protected String entityName; protected String versionsEntityName; @@ -61,15 +61,15 @@ public abstract class AbstractVersionsQuery implements VersionsQuery { protected boolean hasProjection; protected boolean hasOrder; - protected final VersionsConfiguration verCfg; - private final VersionsReaderImplementor versionsReader; + protected final AuditConfiguration verCfg; + private final AuditReaderImplementor versionsReader; - protected AbstractVersionsQuery(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader, + protected AbstractVersionsQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, Class cls) { this.verCfg = verCfg; this.versionsReader = versionsReader; - criterions = new ArrayList(); + criterions = new ArrayList(); entityInstantiator = new EntityInstantiator(verCfg, versionsReader); entityName = cls.getName(); @@ -94,13 +94,13 @@ public abstract class AbstractVersionsQuery implements VersionsQuery { return query.list(); } - public abstract List list() throws VersionsException; + public abstract List list() throws AuditException; - public List getResultList() throws VersionsException { + public List getResultList() throws AuditException { return list(); } - public Object getSingleResult() throws VersionsException, NonUniqueResultException, NoResultException { + public Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException { List result = list(); if (result == null || result.size() == 0) { @@ -114,33 +114,33 @@ public abstract class AbstractVersionsQuery implements VersionsQuery { return result.get(0); } - public VersionsQuery add(VersionsCriterion criterion) { + public AuditQuery add(AuditCriterion criterion) { criterions.add(criterion); return this; } // Projection and order - public VersionsQuery addProjection(String function, String propertyName) { + public AuditQuery addProjection(String function, String propertyName) { hasProjection = true; qb.addProjection(function, propertyName, false); return this; } - public VersionsQuery addProjection(VersionsProjection projection) { + public AuditQuery addProjection(AuditProjection projection) { Triple projectionData = projection.getData(verCfg); hasProjection = true; qb.addProjection(projectionData.getFirst(), projectionData.getSecond(), projectionData.getThird()); return this; } - public VersionsQuery addOrder(String propertyName, boolean asc) { + public AuditQuery addOrder(String propertyName, boolean asc) { hasOrder = true; qb.addOrder(propertyName, asc); return this; } - public VersionsQuery addOrder(VersionsOrder order) { + public AuditQuery addOrder(AuditOrder order) { Pair orderData = order.getData(verCfg); return addOrder(orderData.getFirst(), orderData.getSecond()); } @@ -157,47 +157,47 @@ public abstract class AbstractVersionsQuery implements VersionsQuery { private Integer timeout; private LockMode lockMode; - public VersionsQuery setMaxResults(int maxResults) { + public AuditQuery setMaxResults(int maxResults) { this.maxResults = maxResults; return this; } - public VersionsQuery setFirstResult(int firstResult) { + public AuditQuery setFirstResult(int firstResult) { this.firstResult = firstResult; return this; } - public VersionsQuery setCacheable(boolean cacheable) { + public AuditQuery setCacheable(boolean cacheable) { this.cacheable = cacheable; return this; } - public VersionsQuery setCacheRegion(String cacheRegion) { + public AuditQuery setCacheRegion(String cacheRegion) { this.cacheRegion = cacheRegion; return this; } - public VersionsQuery setComment(String comment) { + public AuditQuery setComment(String comment) { this.comment = comment; return this; } - public VersionsQuery setFlushMode(FlushMode flushMode) { + public AuditQuery setFlushMode(FlushMode flushMode) { this.flushMode = flushMode; return this; } - public VersionsQuery setCacheMode(CacheMode cacheMode) { + public AuditQuery setCacheMode(CacheMode cacheMode) { this.cacheMode = cacheMode; return this; } - public VersionsQuery setTimeout(int timeout) { + public AuditQuery setTimeout(int timeout) { this.timeout = timeout; return this; } - public VersionsQuery setLockMode(LockMode lockMode) { + public AuditQuery setLockMode(LockMode lockMode) { this.lockMode = lockMode; return this; } diff --git a/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java b/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java index e9dc4a8d07..6c6f4142ef 100644 --- a/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java +++ b/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java @@ -27,10 +27,10 @@ import java.util.ArrayList; import java.util.List; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.VersionsConfiguration; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; -import org.hibernate.envers.query.criteria.VersionsCriterion; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; +import org.hibernate.envers.query.criteria.AuditCriterion; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.query.QueryBuilder; /** @@ -39,8 +39,8 @@ import org.hibernate.envers.tools.query.QueryBuilder; public class EntitiesAtRevisionQuery extends AbstractVersionsQuery { private final Number revision; - public EntitiesAtRevisionQuery(VersionsConfiguration verCfg, - VersionsReaderImplementor versionsReader, Class cls, + public EntitiesAtRevisionQuery(AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, Class cls, Number revision) { super(verCfg, versionsReader, cls); this.revision = revision; @@ -59,7 +59,7 @@ public class EntitiesAtRevisionQuery extends AbstractVersionsQuery { QueryBuilder maxRevQb = qb.newSubQueryBuilder(versionsEntityName, "e2"); - VersionsEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg(); + AuditEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg(); String revisionPropertyPath = verEntCfg.getRevisionPropPath(); String originalIdPropertyName = verEntCfg.getOriginalIdPropName(); @@ -77,7 +77,7 @@ public class EntitiesAtRevisionQuery extends AbstractVersionsQuery { // e.revision = (SELECT max(...) ...) qb.getRootParameters().addWhere(revisionPropertyPath, verCfg.getGlobalCfg().getCorrelatedSubqueryOperator(), maxRevQb); // all specified conditions - for (VersionsCriterion criterion : criterions) { + for (AuditCriterion criterion : criterions) { criterion.addToQuery(verCfg, entityName, qb, qb.getRootParameters()); } diff --git a/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java b/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java index 6d247e2579..cb6ac231ae 100644 --- a/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java +++ b/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java @@ -28,11 +28,11 @@ import java.util.List; import java.util.Map; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.VersionsConfiguration; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; -import org.hibernate.envers.exception.VersionsException; -import org.hibernate.envers.query.criteria.VersionsCriterion; -import org.hibernate.envers.reader.VersionsReaderImplementor; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.query.criteria.AuditCriterion; +import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.proxy.HibernateProxy; @@ -43,8 +43,8 @@ public class RevisionsOfEntityQuery extends AbstractVersionsQuery { private final boolean selectEntitiesOnly; private final boolean selectDeletedEntities; - public RevisionsOfEntityQuery(VersionsConfiguration verCfg, - VersionsReaderImplementor versionsReader, + public RevisionsOfEntityQuery(AuditConfiguration verCfg, + AuditReaderImplementor versionsReader, Class cls, boolean selectEntitiesOnly, boolean selectDeletedEntities) { super(verCfg, versionsReader, cls); @@ -54,7 +54,7 @@ public class RevisionsOfEntityQuery extends AbstractVersionsQuery { } private Number getRevisionNumber(Map versionsEntity) { - VersionsEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg(); + AuditEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg(); String originalId = verEntCfg.getOriginalIdPropName(); String revisionPropertyName = verEntCfg.getRevisionPropName(); @@ -70,8 +70,8 @@ public class RevisionsOfEntityQuery extends AbstractVersionsQuery { } @SuppressWarnings({"unchecked"}) - public List list() throws VersionsException { - VersionsEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg(); + public List list() throws AuditException { + AuditEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg(); /* The query that should be executed in the versions table: @@ -87,7 +87,7 @@ public class RevisionsOfEntityQuery extends AbstractVersionsQuery { } // all specified conditions, transformed - for (VersionsCriterion criterion : criterions) { + for (AuditCriterion criterion : criterions) { criterion.addToQuery(verCfg, entityName, qb, qb.getRootParameters()); } diff --git a/envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java b/envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java new file mode 100644 index 0000000000..41aff3d1ce --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java @@ -0,0 +1,38 @@ +/* + * 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.order; + +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.tools.Pair; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public interface AuditOrder { + /** + * @param verCfg Configuration. + * @return A pair: (property name, ascending?). + */ + Pair getData(AuditConfiguration verCfg); +} diff --git a/envers/src/main/java/org/hibernate/envers/query/order/RevisionVersionsOrder.java b/envers/src/main/java/org/hibernate/envers/query/order/RevisionVersionsOrder.java index 0f037a7760..61cefa63ec 100644 --- a/envers/src/main/java/org/hibernate/envers/query/order/RevisionVersionsOrder.java +++ b/envers/src/main/java/org/hibernate/envers/query/order/RevisionVersionsOrder.java @@ -23,20 +23,20 @@ */ package org.hibernate.envers.query.order; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.Pair; /** * @author Adam Warski (adam at warski dot org) */ -public class RevisionVersionsOrder implements VersionsOrder { +public class RevisionVersionsOrder implements AuditOrder { private final boolean asc; public RevisionVersionsOrder(boolean asc) { this.asc = asc; } - public Pair getData(VersionsConfiguration verCfg) { + public Pair getData(AuditConfiguration verCfg) { String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath(); return Pair.make(revisionPropPath, asc); } diff --git a/envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java b/envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java new file mode 100644 index 0000000000..1c8c084ffc --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java @@ -0,0 +1,39 @@ +/* + * 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.projection; + +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.tools.Triple; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public interface AuditProjection { + /** + * + * @param verCfg Configuration. + * @return A triple: (function name - possibly null, property name, add distinct?). + */ + Triple getData(AuditConfiguration verCfg); +} diff --git a/envers/src/main/java/org/hibernate/envers/query/projection/RevisionVersionsProjection.java b/envers/src/main/java/org/hibernate/envers/query/projection/RevisionVersionsProjection.java index 17bc0350f7..bb2483aa8a 100644 --- a/envers/src/main/java/org/hibernate/envers/query/projection/RevisionVersionsProjection.java +++ b/envers/src/main/java/org/hibernate/envers/query/projection/RevisionVersionsProjection.java @@ -23,13 +23,13 @@ */ package org.hibernate.envers.query.projection; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.tools.Triple; /** * @author Adam Warski (adam at warski dot org) */ -public class RevisionVersionsProjection implements VersionsProjection { +public class RevisionVersionsProjection implements AuditProjection { public static enum ProjectionType { MAX, MIN, @@ -44,7 +44,7 @@ public class RevisionVersionsProjection implements VersionsProjection { this.type = type; } - public Triple getData(VersionsConfiguration verCfg) { + public Triple getData(AuditConfiguration verCfg) { String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath(); switch (type) { diff --git a/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java b/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java new file mode 100644 index 0000000000..6177b6b1d8 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java @@ -0,0 +1,197 @@ +/* + * 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.reader; + +import java.util.Date; +import java.util.List; +import javax.persistence.NoResultException; + +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.exception.NotVersionedException; +import org.hibernate.envers.exception.RevisionDoesNotExistException; +import org.hibernate.envers.exception.AuditException; +import org.hibernate.envers.query.RevisionProperty; +import org.hibernate.envers.query.AuditQueryCreator; +import org.hibernate.envers.query.AuditRestrictions; +import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull; +import static org.hibernate.envers.tools.ArgumentsTools.checkPositive; + +import org.hibernate.NonUniqueResultException; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.engine.SessionImplementor; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class AuditReaderImpl implements AuditReaderImplementor { + private final AuditConfiguration verCfg; + private final SessionImplementor sessionImplementor; + private final Session session; + private final FirstLevelCache firstLevelCache; + + public AuditReaderImpl(AuditConfiguration verCfg, Session session, + SessionImplementor sessionImplementor) { + this.verCfg = verCfg; + this.sessionImplementor = sessionImplementor; + this.session = session; + + firstLevelCache = new FirstLevelCache(); + } + + private void checkSession() { + if (!session.isOpen()) { + throw new IllegalStateException("The associated entity manager is closed!"); + } + } + + public SessionImplementor getSessionImplementor() { + return sessionImplementor; + } + + public Session getSession() { + return session; + } + + public FirstLevelCache getFirstLevelCache() { + return firstLevelCache; + } + + @SuppressWarnings({"unchecked"}) + public T find(Class cls, Object primaryKey, Number revision) throws + IllegalArgumentException, NotVersionedException, IllegalStateException { + checkNotNull(cls, "Entity class"); + checkNotNull(primaryKey, "Primary key"); + checkNotNull(revision, "Entity revision"); + checkPositive(revision, "Entity revision"); + checkSession(); + + String entityName = cls.getName(); + + if (!verCfg.getEntCfg().isVersioned(entityName)) { + throw new NotVersionedException(entityName, entityName + " is not versioned!"); + } + + if (firstLevelCache.contains(entityName, revision, primaryKey)) { + return (T) firstLevelCache.get(entityName, revision, primaryKey); + } + + Object result; + try { + // The result is put into the cache by the entity instantiator called from the query + result = createQuery().forEntitiesAtRevision(cls, revision) + .add(AuditRestrictions.idEq(primaryKey)).getSingleResult(); + } catch (NoResultException e) { + result = null; + } catch (NonUniqueResultException e) { + throw new AuditException(e); + } + + return (T) result; + } + + @SuppressWarnings({"unchecked"}) + public List getRevisions(Class cls, Object primaryKey) + throws IllegalArgumentException, NotVersionedException, IllegalStateException { + // todo: if a class is not versioned from the beginning, there's a missing ADD rev - what then? + checkNotNull(cls, "Entity class"); + checkNotNull(primaryKey, "Primary key"); + checkSession(); + + String entityName = cls.getName(); + + if (!verCfg.getEntCfg().isVersioned(entityName)) { + throw new NotVersionedException(entityName, entityName + " is not versioned!"); + } + + return createQuery().forRevisionsOfEntity(cls, false, true) + .addProjection(RevisionProperty.revisionNumber()) + .add(AuditRestrictions.idEq(primaryKey)) + .getResultList(); + } + + public Date getRevisionDate(Number revision) throws IllegalArgumentException, RevisionDoesNotExistException, + IllegalStateException{ + checkNotNull(revision, "Entity revision"); + checkPositive(revision, "Entity revision"); + checkSession(); + + Query query = verCfg.getRevisionInfoQueryCreator().getRevisionDateQuery(session, revision); + + try { + Long timestamp = (Long) query.uniqueResult(); + if (timestamp == null) { + throw new RevisionDoesNotExistException(revision); + } + + return new Date(timestamp); + } catch (NonUniqueResultException e) { + throw new AuditException(e); + } + } + + public Number getRevisionNumberForDate(Date date) { + checkNotNull(date, "Date of revision"); + checkSession(); + + Query query = verCfg.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery(session, date); + + try { + Number res = (Number) query.uniqueResult(); + if (res == null) { + throw new RevisionDoesNotExistException(date); + } + + return res; + } catch (NonUniqueResultException e) { + throw new AuditException(e); + } + } + + @SuppressWarnings({"unchecked"}) + public T findRevision(Class revisionEntityClass, Number revision) throws IllegalArgumentException, + RevisionDoesNotExistException, IllegalStateException { + checkNotNull(revision, "Entity revision"); + checkPositive(revision, "Entity revision"); + checkSession(); + + Query query = verCfg.getRevisionInfoQueryCreator().getRevisionQuery(session, revision); + + try { + T revisionData = (T) query.uniqueResult(); + + if (revisionData == null) { + throw new RevisionDoesNotExistException(revision); + } + + return revisionData; + } catch (NonUniqueResultException e) { + throw new AuditException(e); + } + } + + public AuditQueryCreator createQuery() { + return new AuditQueryCreator(verCfg, this); + } +} diff --git a/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java b/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java new file mode 100644 index 0000000000..b8ba1f6414 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java @@ -0,0 +1,39 @@ +/* + * 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.reader; + +import org.hibernate.envers.AuditReader; + +import org.hibernate.Session; +import org.hibernate.engine.SessionImplementor; + +/** + * An interface exposed by a VersionsReader to library-facing classes. + * @author Adam Warski (adam at warski dot org) + */ +public interface AuditReaderImplementor extends AuditReader { + SessionImplementor getSessionImplementor(); + Session getSession(); + FirstLevelCache getFirstLevelCache(); +} diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java b/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java new file mode 100644 index 0000000000..8a12f15b55 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java @@ -0,0 +1,160 @@ +/* + * 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.synchronization; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Queue; +import javax.transaction.Synchronization; + +import org.hibernate.envers.revisioninfo.RevisionInfoGenerator; +import org.hibernate.envers.synchronization.work.AuditWorkUnit; +import org.hibernate.envers.tools.Pair; + +import org.hibernate.FlushMode; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.event.EventSource; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class AuditSync implements Synchronization { + private final RevisionInfoGenerator revisionInfoGenerator; + private final AuditSyncManager manager; + private final EventSource session; + + private final Transaction transaction; + private final LinkedList workUnits; + private final Queue undoQueue; + private final Map, AuditWorkUnit> usedIds; + + private Object revisionData; + + public AuditSync(AuditSyncManager manager, EventSource session, RevisionInfoGenerator revisionInfoGenerator) { + this.manager = manager; + this.session = session; + this.revisionInfoGenerator = revisionInfoGenerator; + + transaction = session.getTransaction(); + workUnits = new LinkedList(); + undoQueue = new LinkedList(); + usedIds = new HashMap, AuditWorkUnit>(); + } + + private void removeWorkUnit(AuditWorkUnit vwu) { + workUnits.remove(vwu); + if (vwu.isPerformed()) { + // If this work unit has already been performed, it must be deleted (undone) first. + undoQueue.offer(vwu); + } + } + + public void addWorkUnit(AuditWorkUnit vwu) { + if (vwu.containsWork()) { + Object entityId = vwu.getEntityId(); + + if (entityId == null) { + // Just adding the work unit - it's not associated with any persistent entity. + workUnits.offer(vwu); + } else { + String entityName = vwu.getEntityName(); + Pair usedIdsKey = Pair.make(entityName, entityId); + + if (usedIds.containsKey(usedIdsKey)) { + AuditWorkUnit other = usedIds.get(usedIdsKey); + + // The entity with entityId has two work units; checking which one should be kept. + switch (vwu.dispatch(other)) { + case FIRST: + // Simply not adding the second + break; + + case SECOND: + removeWorkUnit(other); + usedIds.put(usedIdsKey, vwu); + workUnits.offer(vwu); + break; + + case NONE: + removeWorkUnit(other); + break; + } + } else { + usedIds.put(usedIdsKey, vwu); + workUnits.offer(vwu); + } + } + } + } + + private void executeInSession(Session session) { + if (revisionData == null) { + revisionData = revisionInfoGenerator.generate(session); + } + + AuditWorkUnit vwu; + + // First undoing any performed work units + while ((vwu = undoQueue.poll()) != null) { + vwu.undo(session); + } + + while ((vwu = workUnits.poll()) != null) { + vwu.perform(session, revisionData); + } + } + + public void beforeCompletion() { + if (workUnits.size() == 0 && undoQueue.size() == 0) { + return; + } + + // see: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4178431 + if (FlushMode.isManualFlushMode(session.getFlushMode()) || session.isClosed()) { + Session temporarySession = null; + try { + temporarySession = session.getFactory().openTemporarySession(); + + executeInSession(temporarySession); + + temporarySession.flush(); + } finally { + if (temporarySession != null) { + temporarySession.close(); + } + } + } else { + executeInSession(session); + + // Explicity flushing the session, as the auto-flush may have already happened. + session.flush(); + } + } + + public void afterCompletion(int i) { + manager.remove(transaction); + } +} diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/AuditSyncManager.java b/envers/src/main/java/org/hibernate/envers/synchronization/AuditSyncManager.java new file mode 100644 index 0000000000..219293ec26 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/synchronization/AuditSyncManager.java @@ -0,0 +1,66 @@ +/* + * 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.synchronization; + +import java.util.Map; + +import org.hibernate.envers.revisioninfo.RevisionInfoGenerator; +import org.hibernate.envers.tools.ConcurrentReferenceHashMap; + +import org.hibernate.Transaction; +import org.hibernate.event.EventSource; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class AuditSyncManager { + private final Map versionsSyncs; + private final RevisionInfoGenerator revisionInfoGenerator; + + public AuditSyncManager(RevisionInfoGenerator revisionInfoGenerator) { + versionsSyncs = new ConcurrentReferenceHashMap(10, + ConcurrentReferenceHashMap.ReferenceType.WEAK, + ConcurrentReferenceHashMap.ReferenceType.STRONG); + + this.revisionInfoGenerator = revisionInfoGenerator; + } + + public AuditSync get(EventSource session) { + Transaction transaction = session.getTransaction(); + + AuditSync verSync = versionsSyncs.get(transaction); + if (verSync == null) { + verSync = new AuditSync(this, session, revisionInfoGenerator); + versionsSyncs.put(transaction, verSync); + + transaction.registerSynchronization(verSync); + } + + return verSync; + } + + public void remove(Transaction transaction) { + versionsSyncs.remove(transaction); + } +} diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java new file mode 100644 index 0000000000..d741c05a8d --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java @@ -0,0 +1,86 @@ +/* + * 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.synchronization.work; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.hibernate.envers.RevisionType; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; + +import org.hibernate.Session; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public abstract class AbstractAuditWorkUnit implements AuditWorkUnit { + protected final AuditConfiguration verCfg; + protected final Serializable id; + + private final String entityName; + + private Object performedData; + + protected AbstractAuditWorkUnit(String entityName, AuditConfiguration verCfg, Serializable id) { + this.verCfg = verCfg; + this.id = id; + this.entityName = entityName; + } + + protected void fillDataWithId(Map data, Object revision, RevisionType revisionType) { + AuditEntitiesConfiguration entitiesCfg = verCfg.getVerEntCfg(); + + Map originalId = new HashMap(); + originalId.put(entitiesCfg.getRevisionPropName(), revision); + + verCfg.getEntCfg().get(getEntityName()).getIdMapper().mapToMapFromId(originalId, id); + data.put(entitiesCfg.getRevisionTypePropName(), revisionType); + data.put(entitiesCfg.getOriginalIdPropName(), originalId); + } + + public Object getEntityId() { + return id; + } + + public boolean isPerformed() { + return performedData != null; + } + + public String getEntityName() { + return entityName; + } + + protected void setPerformed(Object performedData) { + this.performedData = performedData; + } + + public void undo(Session session) { + if (isPerformed()) { + session.delete(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), performedData); + session.flush(); + } + } +} diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/AddWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/AddWorkUnit.java index 51fccc43cf..3b3dea01af 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/AddWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/AddWorkUnit.java @@ -28,7 +28,7 @@ import java.util.HashMap; import java.util.Map; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.Session; import org.hibernate.persister.entity.EntityPersister; @@ -36,11 +36,11 @@ import org.hibernate.persister.entity.EntityPersister; /** * @author Adam Warski (adam at warski dot org) */ -public class AddWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit { +public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { private final Object[] state; private final String[] propertyNames; - public AddWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id, + public AddWorkUnit(String entityName, AuditConfiguration verCfg, Serializable id, EntityPersister entityPersister, Object[] state) { super(entityName, verCfg, id); diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java new file mode 100644 index 0000000000..f6c2ee1df0 --- /dev/null +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/AuditWorkUnit.java @@ -0,0 +1,41 @@ +/* + * 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.synchronization.work; + +import org.hibernate.Session; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public interface AuditWorkUnit extends KeepCheckVisitor, KeepCheckDispatcher { + Object getEntityId(); + String getEntityName(); + + boolean containsWork(); + + boolean isPerformed(); + + void perform(Session session, Object revisionData); + void undo(Session session); +} diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/CollectionChangeWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/CollectionChangeWorkUnit.java index 53a97ebe58..5d3f989623 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/CollectionChangeWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/CollectionChangeWorkUnit.java @@ -28,17 +28,17 @@ import java.util.HashMap; import java.util.Map; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.Session; /** * @author Adam Warski (adam at warski dot org) */ -public class CollectionChangeWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit { +public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { private final Object entity; - public CollectionChangeWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id, Object entity) { + public CollectionChangeWorkUnit(String entityName, AuditConfiguration verCfg, Serializable id, Object entity) { super(entityName, verCfg, id); this.entity = entity; diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java index ce7d511523..25c924e3ce 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java @@ -28,15 +28,15 @@ import java.util.HashMap; import java.util.Map; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.Session; /** * @author Adam Warski (adam at warski dot org) */ -public class DelWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit { - public DelWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id) { +public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { + public DelWorkUnit(String entityName, AuditConfiguration verCfg, Serializable id) { super(entityName, verCfg, id); } diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/ModWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/ModWorkUnit.java index bd692b68cd..2c30678d69 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/ModWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/ModWorkUnit.java @@ -28,7 +28,7 @@ import java.util.HashMap; import java.util.Map; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.configuration.VersionsConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.Session; import org.hibernate.persister.entity.EntityPersister; @@ -36,11 +36,11 @@ import org.hibernate.persister.entity.EntityPersister; /** * @author Adam Warski (adam at warski dot org) */ -public class ModWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit { +public class ModWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { private final Map data; private final boolean changes; - public ModWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id, + public ModWorkUnit(String entityName, AuditConfiguration verCfg, Serializable id, EntityPersister entityPersister, Object[] newState, Object[] oldState) { super(entityName, verCfg, id); diff --git a/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java b/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java index e78ec57e1f..b10881b139 100644 --- a/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java +++ b/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java @@ -27,8 +27,8 @@ import java.io.Serializable; import java.util.List; import java.util.Map; -import org.hibernate.envers.configuration.VersionsConfiguration; -import org.hibernate.envers.configuration.VersionsEntitiesConfiguration; +import org.hibernate.envers.configuration.AuditConfiguration; +import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData; import org.hibernate.Session; @@ -37,11 +37,11 @@ import org.hibernate.collection.PersistentCollection; /** * @author Adam Warski (adam at warski dot org) */ -public class PersistentCollectionChangeWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit { +public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { private final List collectionChanges; private final String referencingPropertyName; - public PersistentCollectionChangeWorkUnit(String entityName, VersionsConfiguration verCfg, + public PersistentCollectionChangeWorkUnit(String entityName, AuditConfiguration verCfg, PersistentCollection collection, String role, Serializable snapshot, Serializable id) { super(entityName, verCfg, null); @@ -58,7 +58,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractVersionsWorkUnit @SuppressWarnings({"unchecked"}) public void perform(Session session, Object revisionData) { - VersionsEntitiesConfiguration entitiesCfg = verCfg.getVerEntCfg(); + AuditEntitiesConfiguration entitiesCfg = verCfg.getVerEntCfg(); for (PersistentCollectionChangeData persistentCollectionChangeData : collectionChanges) { // Setting the revision number diff --git a/envers/src/main/java/org/hibernate/envers/tools/log/YLog.java b/envers/src/main/java/org/hibernate/envers/tools/log/YLog.java index 78c31af0ce..d48fd75cd7 100644 --- a/envers/src/main/java/org/hibernate/envers/tools/log/YLog.java +++ b/envers/src/main/java/org/hibernate/envers/tools/log/YLog.java @@ -26,7 +26,7 @@ package org.hibernate.envers.tools.log; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; /** * A simple logger facade which delegates through reflection to a logging delegate. @@ -44,19 +44,19 @@ public class YLog { try { errorMethod = delegate.getClass().getMethod("error", argClass); } catch (NoSuchMethodException e) { - throw new VersionsException(e); + throw new AuditException(e); } try { warnMethod = delegate.getClass().getMethod("warn", argClass); } catch (NoSuchMethodException e) { - throw new VersionsException(e); + throw new AuditException(e); } try { infoMethod = delegate.getClass().getMethod("info", argClass); } catch (NoSuchMethodException e) { - throw new VersionsException(e); + throw new AuditException(e); } } @@ -64,9 +64,9 @@ public class YLog { try { errorMethod.invoke(delegate, message); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } @@ -74,9 +74,9 @@ public class YLog { try { warnMethod.invoke(delegate, message); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } @@ -84,9 +84,9 @@ public class YLog { try { infoMethod.invoke(delegate, message); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } } diff --git a/envers/src/main/java/org/hibernate/envers/tools/log/YLogManager.java b/envers/src/main/java/org/hibernate/envers/tools/log/YLogManager.java index 799e5b7dc8..071ebe21ac 100644 --- a/envers/src/main/java/org/hibernate/envers/tools/log/YLogManager.java +++ b/envers/src/main/java/org/hibernate/envers/tools/log/YLogManager.java @@ -26,7 +26,7 @@ package org.hibernate.envers.tools.log; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; /** * A class for creating logging facades either to loggers obtained from @@ -47,7 +47,7 @@ public class YLogManager { getLogMethod = logFactoryClass.getMethod("getLog", Class.class); argClass = Object.class; } catch (NoSuchMethodException e) { - throw new VersionsException("No 'getLog' method in org.apache.commons.logging.LogFactory."); + throw new AuditException("No 'getLog' method in org.apache.commons.logging.LogFactory."); } } catch (ClassNotFoundException e) { try { @@ -56,10 +56,10 @@ public class YLogManager { getLogMethod = loggerFactoryClass.getMethod("getLogger", Class.class); argClass = String.class; } catch (NoSuchMethodException e1) { - throw new VersionsException("No 'getLogger' method in org.slf4j.LoggerFactory."); + throw new AuditException("No 'getLogger' method in org.slf4j.LoggerFactory."); } } catch (ClassNotFoundException e1) { - throw new VersionsException("No org.apache.commons.logging.LogFactory or org.slf4j.LoggerFactory found."); + throw new AuditException("No org.apache.commons.logging.LogFactory or org.slf4j.LoggerFactory found."); } } } @@ -68,9 +68,9 @@ public class YLogManager { try { return new YLog(getLogMethod.invoke(null, cls), argClass); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } diff --git a/envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java b/envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java index dddafd5c57..355c0cb1ca 100644 --- a/envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java +++ b/envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java @@ -25,7 +25,7 @@ package org.hibernate.envers.tools.reflection; import java.util.Map; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.tools.ConcurrentReferenceHashMap; import org.hibernate.envers.tools.Pair; import static org.hibernate.envers.tools.Pair.make; @@ -55,7 +55,7 @@ public class ReflectionTools { try { return Thread.currentThread().getContextClassLoader().loadClass(name); } catch (ClassNotFoundException e) { - throw new VersionsException(e); + throw new AuditException(e); } } diff --git a/envers/src/main/java/org/hibernate/envers/tools/reflection/YClass.java b/envers/src/main/java/org/hibernate/envers/tools/reflection/YClass.java index 7615555cea..5953a2956d 100644 --- a/envers/src/main/java/org/hibernate/envers/tools/reflection/YClass.java +++ b/envers/src/main/java/org/hibernate/envers/tools/reflection/YClass.java @@ -28,7 +28,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; /** * @author Adam Warski (adam at warski dot org) @@ -50,9 +50,9 @@ public class YClass { try { return (String) ymc.getXClass_getNameMethod().invoke(delegate); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } @@ -60,9 +60,9 @@ public class YClass { try { return new YClass(ymc, ymc.getXClass_getSuperclassMethod().invoke(delegate)); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } @@ -72,9 +72,9 @@ public class YClass { try { delegates = (List) ymc.getXClass_getDeclaredPropertiesMethod().invoke(delegate, accessMode); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } List ret = new ArrayList(); @@ -90,9 +90,9 @@ public class YClass { //noinspection unchecked return (T) ymc.getXClass_getAnnotationMethod().invoke(delegate, annotation); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } } diff --git a/envers/src/main/java/org/hibernate/envers/tools/reflection/YMethodsAndClasses.java b/envers/src/main/java/org/hibernate/envers/tools/reflection/YMethodsAndClasses.java index 282612532d..859563e153 100644 --- a/envers/src/main/java/org/hibernate/envers/tools/reflection/YMethodsAndClasses.java +++ b/envers/src/main/java/org/hibernate/envers/tools/reflection/YMethodsAndClasses.java @@ -25,7 +25,7 @@ package org.hibernate.envers.tools.reflection; import java.lang.reflect.Method; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; /** * @author Adam Warski (adam at warski dot org) @@ -54,7 +54,7 @@ public class YMethodsAndClasses { try { xClassClass = cl.loadClass("org.hibernate.reflection.XClass"); } catch (ClassNotFoundException e1) { - throw new VersionsException("No XClass found."); + throw new AuditException("No XClass found."); } } @@ -65,7 +65,7 @@ public class YMethodsAndClasses { try { xPropertyClass = cl.loadClass("org.hibernate.reflection.XProperty"); } catch (ClassNotFoundException e1) { - throw new VersionsException("No XProperty found."); + throw new AuditException("No XProperty found."); } } diff --git a/envers/src/main/java/org/hibernate/envers/tools/reflection/YProperty.java b/envers/src/main/java/org/hibernate/envers/tools/reflection/YProperty.java index a214418bdb..953a48c132 100644 --- a/envers/src/main/java/org/hibernate/envers/tools/reflection/YProperty.java +++ b/envers/src/main/java/org/hibernate/envers/tools/reflection/YProperty.java @@ -26,7 +26,7 @@ package org.hibernate.envers.tools.reflection; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; /** * @author Adam Warski (adam at warski dot org) @@ -44,9 +44,9 @@ public class YProperty { try { return (String) ymc.getXProperty_getNameMethod().invoke(delegate); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } @@ -55,9 +55,9 @@ public class YProperty { //noinspection unchecked return (T) ymc.getXProperty_getAnnotationMethod().invoke(delegate, annotation); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } @@ -65,9 +65,9 @@ public class YProperty { try { return new YClass(ymc, ymc.getXProperty_getTypeMethod().invoke(delegate)); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } } diff --git a/envers/src/main/java/org/hibernate/envers/tools/reflection/YReflectionManager.java b/envers/src/main/java/org/hibernate/envers/tools/reflection/YReflectionManager.java index f647cf3b12..5e0f37d429 100644 --- a/envers/src/main/java/org/hibernate/envers/tools/reflection/YReflectionManager.java +++ b/envers/src/main/java/org/hibernate/envers/tools/reflection/YReflectionManager.java @@ -25,7 +25,7 @@ package org.hibernate.envers.tools.reflection; import java.lang.reflect.InvocationTargetException; -import org.hibernate.envers.exception.VersionsException; +import org.hibernate.envers.exception.AuditException; import org.hibernate.MappingException; import org.hibernate.cfg.Configuration; @@ -57,9 +57,9 @@ public class YReflectionManager { try { return new YClass(ymc, ymc.getReflectionManager_classForNameMethod().invoke(delegate, className, caller)); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } @@ -67,9 +67,9 @@ public class YReflectionManager { try { return (Boolean) ymc.getReflectionManager_equalsMethod().invoke(delegate, class1.getDelegate(), class2); } catch (IllegalAccessException e) { - throw new VersionsException(e); + throw new AuditException(e); } catch (InvocationTargetException e) { - throw new VersionsException(e); + throw new AuditException(e); } } diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java b/envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java index 9a89c5a340..3340bee749 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java @@ -26,7 +26,7 @@ package org.hibernate.envers.test.integration.query; import java.util.List; import javax.persistence.EntityManager; -import org.hibernate.envers.query.VersionsRestrictions; +import org.hibernate.envers.query.AuditRestrictions; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.entities.reventity.CustomRevEntity; @@ -79,7 +79,7 @@ public class CustomRevEntityQuery extends AbstractEntityTest { public void testRevisionsOfId1Query() { List result = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.idEq(id1)) .getResultList(); assert result.get(0)[0].equals(new StrIntTestEntity("a", 10, id1)); @@ -95,7 +95,7 @@ public class CustomRevEntityQuery extends AbstractEntityTest { public void testRevisionsOfId2Query() { List result = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.idEq(id2)) .getResultList(); assert result.get(0)[0].equals(new StrIntTestEntity("b", 15, id2)); diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java b/envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java index 3242a72781..a68ecc0290 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java @@ -28,7 +28,7 @@ import javax.persistence.EntityManager; import org.hibernate.envers.DefaultRevisionEntity; import org.hibernate.envers.RevisionType; -import org.hibernate.envers.query.VersionsRestrictions; +import org.hibernate.envers.query.AuditRestrictions; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.testng.annotations.BeforeClass; @@ -88,7 +88,7 @@ public class DeletedEntities extends AbstractEntityTest { public void testRevisionsOfEntityWithoutDelete() { List result = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, false) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.idEq(id2)) .getResultList(); assert result.size() == 1; diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java b/envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java index 017378da76..05b408f487 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java @@ -28,7 +28,7 @@ import java.util.List; import javax.persistence.EntityManager; import org.hibernate.envers.query.RevisionProperty; -import org.hibernate.envers.query.VersionsRestrictions; +import org.hibernate.envers.query.AuditRestrictions; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.testng.annotations.BeforeClass; @@ -104,8 +104,8 @@ public class MaximalizePropertyQuery extends AbstractEntityTest { List revs_id1 = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionProperty.revisionNumber()) - .add(VersionsRestrictions.maximizeProperty("number") - .add(VersionsRestrictions.idEq(id2))) + .add(AuditRestrictions.maximizeProperty("number") + .add(AuditRestrictions.idEq(id2))) .getResultList(); assert Arrays.asList(2, 3, 4).equals(revs_id1); @@ -116,8 +116,8 @@ public class MaximalizePropertyQuery extends AbstractEntityTest { List result = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionProperty.revisionNumber()) - .add(VersionsRestrictions.minimizeProperty("number") - .add(VersionsRestrictions.eq("str1", "a"))) + .add(AuditRestrictions.minimizeProperty("number") + .add(AuditRestrictions.eq("str1", "a"))) .getResultList(); assert Arrays.asList(1).equals(result); diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java b/envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java index 1667259be7..55071de88a 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java @@ -28,7 +28,7 @@ import java.util.List; import javax.persistence.EntityManager; import org.hibernate.envers.query.RevisionProperty; -import org.hibernate.envers.query.VersionsRestrictions; +import org.hibernate.envers.query.AuditRestrictions; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.testng.annotations.BeforeClass; @@ -126,7 +126,7 @@ public class RevisionConstraintQuery extends AbstractEntityTest { .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionProperty.revisionNumber()) .add(RevisionProperty.le(3)) - .add(VersionsRestrictions.eq("str1", "a")) + .add(AuditRestrictions.eq("str1", "a")) .getResultList(); assert Arrays.asList(1).equals(result); @@ -138,7 +138,7 @@ public class RevisionConstraintQuery extends AbstractEntityTest { .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionProperty.revisionNumber()) .add(RevisionProperty.gt(1)) - .add(VersionsRestrictions.lt("number", 10)) + .add(AuditRestrictions.lt("number", 10)) .getResultList(); assert Arrays.asList(3, 4).equals(result); @@ -152,7 +152,7 @@ public class RevisionConstraintQuery extends AbstractEntityTest { .addProjection(RevisionProperty.count()) .addProjection(RevisionProperty.countDistinct()) .addProjection(RevisionProperty.min()) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.idEq(id1)) .getSingleResult(); assert (Integer) result[0] == 4; @@ -166,7 +166,7 @@ public class RevisionConstraintQuery extends AbstractEntityTest { List result = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionProperty.revisionNumber()) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.idEq(id1)) .addOrder(RevisionProperty.desc()) .getResultList(); @@ -179,7 +179,7 @@ public class RevisionConstraintQuery extends AbstractEntityTest { Object result = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionProperty.count()) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.idEq(id1)) .getSingleResult(); assert (Long) result == 4; diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java b/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java index 9c5a680432..6ec5cbb69a 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java @@ -32,7 +32,7 @@ import org.hibernate.envers.DefaultRevisionEntity; import org.hibernate.envers.RevisionType; import org.hibernate.envers.query.RevisionProperty; import org.hibernate.envers.query.RevisionTypeProperty; -import org.hibernate.envers.query.VersionsRestrictions; +import org.hibernate.envers.query.AuditRestrictions; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.tools.TestTools; @@ -108,7 +108,7 @@ public class SimpleQuery extends AbstractEntityTest { public void testEntitiesIdQuery() { StrIntTestEntity ver2 = (StrIntTestEntity) getVersionsReader().createQuery() .forEntitiesAtRevision(StrIntTestEntity.class, 2) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.idEq(id2)) .getSingleResult(); assert ver2.equals(new StrIntTestEntity("a", 20, id2)); @@ -118,17 +118,17 @@ public class SimpleQuery extends AbstractEntityTest { public void testEntitiesPropertyEqualsQuery() { List ver1 = getVersionsReader().createQuery() .forEntitiesAtRevision(StrIntTestEntity.class, 1) - .add(VersionsRestrictions.eq("str1", "a")) + .add(AuditRestrictions.eq("str1", "a")) .getResultList(); List ver2 = getVersionsReader().createQuery() .forEntitiesAtRevision(StrIntTestEntity.class, 2) - .add(VersionsRestrictions.eq("str1", "a")) + .add(AuditRestrictions.eq("str1", "a")) .getResultList(); List ver3 = getVersionsReader().createQuery() .forEntitiesAtRevision(StrIntTestEntity.class, 3) - .add(VersionsRestrictions.eq("str1", "a")) + .add(AuditRestrictions.eq("str1", "a")) .getResultList(); assert new HashSet(ver1).equals(TestTools.makeSet(new StrIntTestEntity("a", 10, id1), @@ -142,17 +142,17 @@ public class SimpleQuery extends AbstractEntityTest { public void testEntitiesPropertyLeQuery() { List ver1 = getVersionsReader().createQuery() .forEntitiesAtRevision(StrIntTestEntity.class, 1) - .add(VersionsRestrictions.le("number", 10)) + .add(AuditRestrictions.le("number", 10)) .getResultList(); List ver2 = getVersionsReader().createQuery() .forEntitiesAtRevision(StrIntTestEntity.class, 2) - .add(VersionsRestrictions.le("number", 10)) + .add(AuditRestrictions.le("number", 10)) .getResultList(); List ver3 = getVersionsReader().createQuery() .forEntitiesAtRevision(StrIntTestEntity.class, 3) - .add(VersionsRestrictions.le("number", 10)) + .add(AuditRestrictions.le("number", 10)) .getResultList(); assert new HashSet(ver1).equals(TestTools.makeSet(new StrIntTestEntity("a", 10, id1), @@ -168,22 +168,22 @@ public class SimpleQuery extends AbstractEntityTest { List revs_id1 = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionProperty.revisionNumber()) - .add(VersionsRestrictions.le("str1", "a")) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.le("str1", "a")) + .add(AuditRestrictions.idEq(id1)) .getResultList(); List revs_id2 = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionProperty.revisionNumber()) - .add(VersionsRestrictions.le("str1", "a")) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.le("str1", "a")) + .add(AuditRestrictions.idEq(id2)) .getResultList(); List revs_id3 = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionProperty.revisionNumber()) - .add(VersionsRestrictions.le("str1", "a")) - .add(VersionsRestrictions.idEq(id3)) + .add(AuditRestrictions.le("str1", "a")) + .add(AuditRestrictions.idEq(id3)) .getResultList(); assert Arrays.asList(1).equals(revs_id1); @@ -195,7 +195,7 @@ public class SimpleQuery extends AbstractEntityTest { public void testSelectEntitiesQuery() { List result = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, true, false) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.idEq(id1)) .getResultList(); assert result.size() == 2; @@ -208,7 +208,7 @@ public class SimpleQuery extends AbstractEntityTest { public void testSelectEntitiesAndRevisionsQuery() { List result = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.idEq(id1)) .getResultList(); assert result.size() == 3; @@ -231,7 +231,7 @@ public class SimpleQuery extends AbstractEntityTest { List result = getVersionsReader().createQuery() .forRevisionsOfEntity(StrIntTestEntity.class, false, true) .addProjection(RevisionTypeProperty.revisionType()) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.idEq(id1)) .getResultList(); assert result.size() == 3; diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java b/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java index 98a7aab912..efb50e8694 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Set; import javax.persistence.EntityManager; -import org.hibernate.envers.query.VersionsRestrictions; +import org.hibernate.envers.query.AuditRestrictions; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.entities.ids.EmbId; import org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity; @@ -105,32 +105,32 @@ public class EmbIdOneToManyQuery extends AbstractEntityTest { public void testEntitiesReferencedToId3() { Set rev1_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) .getResultList()); Set rev1 = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(VersionsRestrictions.eq("reference", new SetRefEdEmbIdEntity(id3, null))) + .add(AuditRestrictions.eq("reference", new SetRefEdEmbIdEntity(id3, null))) .getResultList()); Set rev2_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) .getResultList()); Set rev2 = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(VersionsRestrictions.eq("reference", new SetRefEdEmbIdEntity(id3, null))) + .add(AuditRestrictions.eq("reference", new SetRefEdEmbIdEntity(id3, null))) .getResultList()); Set rev3_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) .getResultList()); Set rev3 = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(VersionsRestrictions.eq("reference", new SetRefEdEmbIdEntity(id3, null))) + .add(AuditRestrictions.eq("reference", new SetRefEdEmbIdEntity(id3, null))) .getResultList()); assert rev1.equals(rev1_related); @@ -147,17 +147,17 @@ public class EmbIdOneToManyQuery extends AbstractEntityTest { public void testEntitiesReferencedToId4() { Set rev1_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(VersionsRestrictions.relatedIdEq("reference", id4)) + .add(AuditRestrictions.relatedIdEq("reference", id4)) .getResultList()); Set rev2_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(VersionsRestrictions.relatedIdEq("reference", id4)) + .add(AuditRestrictions.relatedIdEq("reference", id4)) .getResultList()); Set rev3_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(VersionsRestrictions.relatedIdEq("reference", id4)) + .add(AuditRestrictions.relatedIdEq("reference", id4)) .getResultList()); assert rev1_related.equals(TestTools.makeSet()); @@ -169,20 +169,20 @@ public class EmbIdOneToManyQuery extends AbstractEntityTest { public void testEntitiesReferencedByIng1ToId3() { List rev1_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id1)) .getResultList(); Object rev2_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id1)) .getSingleResult(); Object rev3_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id1)) .getSingleResult(); assert rev1_related.size() == 0; @@ -194,20 +194,20 @@ public class EmbIdOneToManyQuery extends AbstractEntityTest { public void testEntitiesReferencedByIng2ToId3() { List rev1_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id2)) .getResultList(); List rev2_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id2)) .getResultList(); Object rev3_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id2)) .getSingleResult(); assert rev1_related.size() == 0; diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java b/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java index f3ffe69d85..ffef83a5ff 100644 --- a/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java +++ b/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Set; import javax.persistence.EntityManager; -import org.hibernate.envers.query.VersionsRestrictions; +import org.hibernate.envers.query.AuditRestrictions; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.entities.ids.MulId; import org.hibernate.envers.test.entities.onetomany.ids.SetRefEdMulIdEntity; @@ -105,32 +105,32 @@ public class MulIdOneToManyQuery extends AbstractEntityTest { public void testEntitiesReferencedToId3() { Set rev1_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) .getResultList()); Set rev1 = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(VersionsRestrictions.eq("reference", new SetRefEdMulIdEntity(id3, null))) + .add(AuditRestrictions.eq("reference", new SetRefEdMulIdEntity(id3, null))) .getResultList()); Set rev2_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) .getResultList()); Set rev2 = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(VersionsRestrictions.eq("reference", new SetRefEdMulIdEntity(id3, null))) + .add(AuditRestrictions.eq("reference", new SetRefEdMulIdEntity(id3, null))) .getResultList()); Set rev3_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) .getResultList()); Set rev3 = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(VersionsRestrictions.eq("reference", new SetRefEdMulIdEntity(id3, null))) + .add(AuditRestrictions.eq("reference", new SetRefEdMulIdEntity(id3, null))) .getResultList()); assert rev1.equals(rev1_related); @@ -147,17 +147,17 @@ public class MulIdOneToManyQuery extends AbstractEntityTest { public void testEntitiesReferencedToId4() { Set rev1_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(VersionsRestrictions.relatedIdEq("reference", id4)) + .add(AuditRestrictions.relatedIdEq("reference", id4)) .getResultList()); Set rev2_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(VersionsRestrictions.relatedIdEq("reference", id4)) + .add(AuditRestrictions.relatedIdEq("reference", id4)) .getResultList()); Set rev3_related = new HashSet(getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(VersionsRestrictions.relatedIdEq("reference", id4)) + .add(AuditRestrictions.relatedIdEq("reference", id4)) .getResultList()); assert rev1_related.equals(TestTools.makeSet()); @@ -169,20 +169,20 @@ public class MulIdOneToManyQuery extends AbstractEntityTest { public void testEntitiesReferencedByIng1ToId3() { List rev1_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id1)) .getResultList(); Object rev2_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id1)) .getSingleResult(); Object rev3_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id1)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id1)) .getSingleResult(); assert rev1_related.size() == 0; @@ -194,20 +194,20 @@ public class MulIdOneToManyQuery extends AbstractEntityTest { public void testEntitiesReferencedByIng2ToId3() { List rev1_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id2)) .getResultList(); List rev2_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id2)) .getResultList(); Object rev3_related = getVersionsReader().createQuery() .forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3) - .add(VersionsRestrictions.relatedIdEq("reference", id3)) - .add(VersionsRestrictions.idEq(id2)) + .add(AuditRestrictions.relatedIdEq("reference", id3)) + .add(AuditRestrictions.idEq(id2)) .getSingleResult(); assert rev1_related.size() == 0;