HHH-3570: renaming versioned to audited
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15460 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
90f70231c6
commit
9fc49bf328
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<Configuration, AuditConfiguration> cfgs
|
||||
= new WeakHashMap<Configuration, AuditConfiguration>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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<String, String> 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<String, String>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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<String, EntityConfiguration> entitiesConfigurations;
|
||||
|
||||
// Map entity name -> (join descriptor -> element describing the "versioned" join)
|
||||
private final Map<String, Map<Join, Element>> 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<String, EntityConfiguration>();
|
||||
entitiesJoins = new HashMap<String, Map<Join, Element>>();
|
||||
}
|
||||
|
||||
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<String> 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<Property> 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<Join> joins = pc.getJoinIterator();
|
||||
|
||||
Map<Join, Element> joinElements = new HashMap<Join, Element>();
|
||||
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<Join> 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<Property>) 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<Property>) pc.getUnjoinedPropertyIterator(),
|
||||
propertyMapper, versioningData, entityName, xmlMappingData, false);
|
||||
|
||||
// Mapping joins (second pass)
|
||||
addJoins(pc, propertyMapper, versioningData, entityName, xmlMappingData, false);
|
||||
}
|
||||
|
||||
public Map<String, EntityConfiguration> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<MiddleIdData> idDatas;
|
||||
|
||||
QueryGeneratorBuilder(GlobalConfiguration globalCfg, VersionsEntitiesConfiguration verEntCfg,
|
||||
QueryGeneratorBuilder(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
|
||||
MiddleIdData referencingIdData, String versionsMiddleEntityName) {
|
||||
this.globalCfg = globalCfg;
|
||||
this.verEntCfg = verEntCfg;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<T> 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<T> implements PropertyMapper {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected abstract Initializor<T> getInitializor(VersionsConfiguration verCfg,
|
||||
VersionsReaderImplementor versionsReader, Object primaryKey,
|
||||
protected abstract Initializor<T> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T extends Collection> extends AbstractC
|
|||
this.elementComponentData = elementComponentData;
|
||||
}
|
||||
|
||||
protected Initializor<T> getInitializor(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader,
|
||||
protected Initializor<T> getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader,
|
||||
Object primaryKey, Number revision) {
|
||||
return new BasicCollectionInitializor<T>(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(),
|
||||
primaryKey, revision, collectionClass, elementComponentData);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<List> i
|
|||
this.indexComponentData = indexComponentData;
|
||||
}
|
||||
|
||||
protected Initializor<List> getInitializor(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader,
|
||||
protected Initializor<List> getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader,
|
||||
Object primaryKey, Number revision) {
|
||||
return new ListCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(),
|
||||
primaryKey, revision, elementComponentData, indexComponentData);
|
||||
|
|
|
@ -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<T extends Map> extends AbstractCollection
|
|||
this.indexComponentData = indexComponentData;
|
||||
}
|
||||
|
||||
protected Initializor<T> getInitializor(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader,
|
||||
protected Initializor<T> getInitializor(AuditConfiguration verCfg, AuditReaderImplementor versionsReader,
|
||||
Object primaryKey, Number revision) {
|
||||
return new MapCollectionInitializor<T>(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(),
|
||||
primaryKey, revision, collectionClass, elementComponentData, indexComponentData);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 + ")");
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<T> implements Initializor<T> {
|
||||
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;
|
||||
|
|
|
@ -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<Ob
|
|||
private final MiddleComponentData elementComponentData;
|
||||
private final MiddleComponentData indexComponentData;
|
||||
|
||||
public ArrayCollectionInitializor(VersionsConfiguration verCfg,
|
||||
VersionsReaderImplementor versionsReader,
|
||||
public ArrayCollectionInitializor(AuditConfiguration verCfg,
|
||||
AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator,
|
||||
Object primaryKey, Number revision,
|
||||
MiddleComponentData elementComponentData,
|
||||
|
|
|
@ -27,11 +27,11 @@ 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.relation.MiddleComponentData;
|
||||
import org.hibernate.envers.entities.mapper.relation.query.RelationQueryGenerator;
|
||||
import org.hibernate.envers.exception.VersionsException;
|
||||
import org.hibernate.envers.reader.VersionsReaderImplementor;
|
||||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.reader.AuditReaderImplementor;
|
||||
|
||||
/**
|
||||
* Initializes a non-indexed java collection (set or list, eventually sorted).
|
||||
|
@ -41,8 +41,8 @@ public class BasicCollectionInitializor<T extends Collection> extends AbstractCo
|
|||
private final Class<? extends T> collectionClass;
|
||||
private final MiddleComponentData elementComponentData;
|
||||
|
||||
public BasicCollectionInitializor(VersionsConfiguration verCfg,
|
||||
VersionsReaderImplementor versionsReader,
|
||||
public BasicCollectionInitializor(AuditConfiguration verCfg,
|
||||
AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator,
|
||||
Object primaryKey, Number revision,
|
||||
Class<? extends T> collectionClass,
|
||||
|
@ -57,9 +57,9 @@ public class BasicCollectionInitializor<T extends Collection> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Lis
|
|||
private final MiddleComponentData elementComponentData;
|
||||
private final MiddleComponentData indexComponentData;
|
||||
|
||||
public ListCollectionInitializor(VersionsConfiguration verCfg,
|
||||
VersionsReaderImplementor versionsReader,
|
||||
public ListCollectionInitializor(AuditConfiguration verCfg,
|
||||
AuditReaderImplementor versionsReader,
|
||||
RelationQueryGenerator queryGenerator,
|
||||
Object primaryKey, Number revision,
|
||||
MiddleComponentData elementComponentData,
|
||||
|
|
|
@ -26,11 +26,11 @@ 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.exception.VersionsException;
|
||||
import org.hibernate.envers.reader.VersionsReaderImplementor;
|
||||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.reader.AuditReaderImplementor;
|
||||
|
||||
/**
|
||||
* Initializes a map.
|
||||
|
@ -41,8 +41,8 @@ public class MapCollectionInitializor<T extends Map> 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<? extends T> collectionClass,
|
||||
|
@ -59,9 +59,9 @@ public class MapCollectionInitializor<T extends Map> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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:
|
||||
* <ol>
|
||||
* <li>the entity instance</li>
|
||||
* <li>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}</li>
|
||||
* <li>type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})</li>.
|
||||
* </ol>
|
||||
* 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 <code>c</code>), 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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<String, String, Boolean> getData(VersionsConfiguration verCfg) {
|
||||
public Triple<String, String, Boolean> getData(AuditConfiguration verCfg) {
|
||||
return Triple.make(null, verCfg.getVerEntCfg().getRevisionPropPath(), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, String, Boolean> getData(VersionsConfiguration verCfg) {
|
||||
public Triple<String, String, Boolean> getData(AuditConfiguration verCfg) {
|
||||
return Triple.make(null, verCfg.getVerEntCfg().getRevisionTypePropName(), false);
|
||||
}
|
||||
}
|
|
@ -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<VersionsCriterion> criterions;
|
||||
private List<AuditCriterion> criterions;
|
||||
|
||||
public AggregatedFieldVersionsExpression(String propertyName, AggregatedMode mode) {
|
||||
this.propertyName = propertyName;
|
||||
this.mode = mode;
|
||||
criterions = new ArrayList<VersionsCriterion>();
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -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<AuditCriterion> criterions;
|
||||
|
||||
public AuditConjunction() {
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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<AuditCriterion> criterions;
|
||||
|
||||
public AuditDisjunction() {
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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, ")");
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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.");
|
||||
}
|
||||
|
||||
|
|
|
@ -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<VersionsCriterion> criterions;
|
||||
protected List<AuditCriterion> 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<VersionsCriterion>();
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
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<String, String, Boolean> 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<String, Boolean> 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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, Boolean> getData(AuditConfiguration verCfg);
|
||||
}
|
|
@ -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<String, Boolean> getData(VersionsConfiguration verCfg) {
|
||||
public Pair<String, Boolean> getData(AuditConfiguration verCfg) {
|
||||
String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath();
|
||||
return Pair.make(revisionPropPath, asc);
|
||||
}
|
||||
|
|
|
@ -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<String, String, Boolean> getData(AuditConfiguration verCfg);
|
||||
}
|
|
@ -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<String, String, Boolean> getData(VersionsConfiguration verCfg) {
|
||||
public Triple<String, String, Boolean> getData(AuditConfiguration verCfg) {
|
||||
String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath();
|
||||
|
||||
switch (type) {
|
||||
|
|
|
@ -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> T find(Class<T> 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<Number> 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> T findRevision(Class<T> 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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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<AuditWorkUnit> workUnits;
|
||||
private final Queue<AuditWorkUnit> undoQueue;
|
||||
private final Map<Pair<String, Object>, 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<AuditWorkUnit>();
|
||||
undoQueue = new LinkedList<AuditWorkUnit>();
|
||||
usedIds = new HashMap<Pair<String, Object>, 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<String, Object> 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);
|
||||
}
|
||||
}
|
|
@ -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<Transaction, AuditSync> versionsSyncs;
|
||||
private final RevisionInfoGenerator revisionInfoGenerator;
|
||||
|
||||
public AuditSyncManager(RevisionInfoGenerator revisionInfoGenerator) {
|
||||
versionsSyncs = new ConcurrentReferenceHashMap<Transaction, AuditSync>(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);
|
||||
}
|
||||
}
|
|
@ -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<String, Object> data, Object revision, RevisionType revisionType) {
|
||||
AuditEntitiesConfiguration entitiesCfg = verCfg.getVerEntCfg();
|
||||
|
||||
Map<String, Object> originalId = new HashMap<String, Object>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, Object> 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);
|
||||
|
||||
|
|
|
@ -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<PersistentCollectionChangeData> 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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<YProperty> ret = new ArrayList<YProperty>();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Object[]> 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<Object[]> 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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue