HHH-10664 - Prepare Envers for 5.2 - deprecation fixes, javadoc fixes, java 8 code adoption.
This commit is contained in:
parent
bdff7ab169
commit
eb2bf6e2e7
|
@ -280,5 +280,5 @@ public interface AuditReader {
|
|||
* marked with {@link ModifiedEntityNames} interface.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException;
|
||||
CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public interface CrossTypeRevisionChangesReader {
|
|||
* @throws IllegalStateException If the associated entity manager is closed.
|
||||
* @throws IllegalArgumentException If a revision number is <code>null</code>, less or equal to 0.
|
||||
*/
|
||||
public List<Object> findEntities(Number revision) throws IllegalStateException, IllegalArgumentException;
|
||||
List<Object> findEntities(Number revision) throws IllegalStateException, IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Find all entities changed (added, updated or removed) in a given revision. Executes <i>n+1</i> SQL queries,
|
||||
|
@ -45,7 +45,7 @@ public interface CrossTypeRevisionChangesReader {
|
|||
* @throws IllegalStateException If the associated entity manager is closed.
|
||||
* @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0.
|
||||
*/
|
||||
public List<Object> findEntities(Number revision, RevisionType revisionType) throws IllegalStateException,
|
||||
List<Object> findEntities(Number revision, RevisionType revisionType) throws IllegalStateException,
|
||||
IllegalArgumentException;
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ public interface CrossTypeRevisionChangesReader {
|
|||
* @throws IllegalStateException If the associated entity manager is closed.
|
||||
* @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0.
|
||||
*/
|
||||
public Map<RevisionType, List<Object>> findEntitiesGroupByRevisionType(Number revision)
|
||||
Map<RevisionType, List<Object>> findEntitiesGroupByRevisionType(Number revision)
|
||||
throws IllegalStateException,
|
||||
IllegalArgumentException;
|
||||
|
||||
|
@ -77,6 +77,6 @@ public interface CrossTypeRevisionChangesReader {
|
|||
* @throws IllegalStateException If the associated entity manager is closed.
|
||||
* @throws IllegalArgumentException If a revision number is {@code null}, less or equal to 0.
|
||||
*/
|
||||
public Set<Pair<String, Class>> findEntityTypes(Number revision)
|
||||
Set<Pair<String, Class>> findEntityTypes(Number revision)
|
||||
throws IllegalStateException, IllegalArgumentException;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class DefaultTrackingModifiedEntitiesRevisionEntity extends DefaultRevisi
|
|||
@Column(name = "ENTITYNAME")
|
||||
@Fetch(FetchMode.JOIN)
|
||||
@ModifiedEntityNames
|
||||
private Set<String> modifiedEntityNames = new HashSet<String>();
|
||||
private Set<String> modifiedEntityNames = new HashSet<>();
|
||||
|
||||
public Set<String> getModifiedEntityNames() {
|
||||
return modifiedEntityNames;
|
||||
|
|
|
@ -57,7 +57,7 @@ public class AdditionalJaxbMappingProducerImpl implements AdditionalJaxbMappingP
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final ArrayList<MappingDocument> additionalMappingDocuments = new ArrayList<MappingDocument>();
|
||||
final ArrayList<MappingDocument> additionalMappingDocuments = new ArrayList<>();
|
||||
|
||||
// atm we do not have distinct origin info for envers
|
||||
final Origin origin = new Origin( SourceType.OTHER, "envers" );
|
||||
|
|
|
@ -15,103 +15,103 @@ public interface EnversSettings {
|
|||
/**
|
||||
* Triggers revision generation when not-owned relation field changes. Defaults to {@code true}.
|
||||
*/
|
||||
public static final String REVISION_ON_COLLECTION_CHANGE = "org.hibernate.envers.revision_on_collection_change";
|
||||
String REVISION_ON_COLLECTION_CHANGE = "org.hibernate.envers.revision_on_collection_change";
|
||||
|
||||
/**
|
||||
* Treats optimistic locking properties as unversioned. Defaults to {@code true}.
|
||||
*/
|
||||
public static final String DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD = "org.hibernate.envers.do_not_audit_optimistic_locking_field";
|
||||
String DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD = "org.hibernate.envers.do_not_audit_optimistic_locking_field";
|
||||
|
||||
/**
|
||||
* Indicates whether entity data should be stored during removal. Defaults to {@code false}.
|
||||
*/
|
||||
public static final String STORE_DATA_AT_DELETE = "org.hibernate.envers.store_data_at_delete";
|
||||
String STORE_DATA_AT_DELETE = "org.hibernate.envers.store_data_at_delete";
|
||||
|
||||
/**
|
||||
* Default name of the schema containing audit tables.
|
||||
*/
|
||||
public static final String DEFAULT_SCHEMA = "org.hibernate.envers.default_schema";
|
||||
String DEFAULT_SCHEMA = "org.hibernate.envers.default_schema";
|
||||
|
||||
/**
|
||||
* Default name of the catalog containing audit tables.
|
||||
*/
|
||||
public static final String DEFAULT_CATALOG = "org.hibernate.envers.default_catalog";
|
||||
String DEFAULT_CATALOG = "org.hibernate.envers.default_catalog";
|
||||
|
||||
/**
|
||||
* Track entity names that have been changed during each revision. Defaults to {@code false}.
|
||||
*/
|
||||
public static final String TRACK_ENTITIES_CHANGED_IN_REVISION = "org.hibernate.envers.track_entities_changed_in_revision";
|
||||
String TRACK_ENTITIES_CHANGED_IN_REVISION = "org.hibernate.envers.track_entities_changed_in_revision";
|
||||
|
||||
/**
|
||||
* Use revision entity with native identifier generator. Defaults to {@code true} for backward compatibility.
|
||||
*/
|
||||
public static final String USE_REVISION_ENTITY_WITH_NATIVE_ID = "org.hibernate.envers.use_revision_entity_with_native_id";
|
||||
String USE_REVISION_ENTITY_WITH_NATIVE_ID = "org.hibernate.envers.use_revision_entity_with_native_id";
|
||||
|
||||
/**
|
||||
* Globally activates modified properties flag feature. Defaults to {@code false}.
|
||||
*/
|
||||
public static final String GLOBAL_WITH_MODIFIED_FLAG = "org.hibernate.envers.global_with_modified_flag";
|
||||
String GLOBAL_WITH_MODIFIED_FLAG = "org.hibernate.envers.global_with_modified_flag";
|
||||
|
||||
/**
|
||||
* Suffix of modified flag columns. Defaults to {@literal _MOD}.
|
||||
*/
|
||||
public static final String MODIFIED_FLAG_SUFFIX = "org.hibernate.envers.modified_flag_suffix";
|
||||
String MODIFIED_FLAG_SUFFIX = "org.hibernate.envers.modified_flag_suffix";
|
||||
|
||||
/**
|
||||
* Fully qualified class name of user defined revision listener.
|
||||
*/
|
||||
public static final String REVISION_LISTENER = "org.hibernate.envers.revision_listener";
|
||||
String REVISION_LISTENER = "org.hibernate.envers.revision_listener";
|
||||
|
||||
/**
|
||||
* Audit table prefix. Empty by default.
|
||||
*/
|
||||
public static final String AUDIT_TABLE_PREFIX = "org.hibernate.envers.audit_table_prefix";
|
||||
String AUDIT_TABLE_PREFIX = "org.hibernate.envers.audit_table_prefix";
|
||||
|
||||
/**
|
||||
* Audit table suffix. Defaults to {@literal _AUD}.
|
||||
*/
|
||||
public static final String AUDIT_TABLE_SUFFIX = "org.hibernate.envers.audit_table_suffix";
|
||||
String AUDIT_TABLE_SUFFIX = "org.hibernate.envers.audit_table_suffix";
|
||||
|
||||
/**
|
||||
* Audit strategy. Defaults to {@link org.hibernate.envers.strategy.DefaultAuditStrategy}.
|
||||
*/
|
||||
public static final String AUDIT_STRATEGY = "org.hibernate.envers.audit_strategy";
|
||||
String AUDIT_STRATEGY = "org.hibernate.envers.audit_strategy";
|
||||
|
||||
/**
|
||||
* Revision field name. Defaults to {@literal REV}.
|
||||
*/
|
||||
public static final String REVISION_FIELD_NAME = "org.hibernate.envers.revision_field_name";
|
||||
String REVISION_FIELD_NAME = "org.hibernate.envers.revision_field_name";
|
||||
|
||||
/**
|
||||
* Revision type field name. Defaults to {@literal REVTYPE}.
|
||||
*/
|
||||
public static final String REVISION_TYPE_FIELD_NAME = "org.hibernate.envers.revision_type_field_name";
|
||||
String REVISION_TYPE_FIELD_NAME = "org.hibernate.envers.revision_type_field_name";
|
||||
|
||||
/**
|
||||
* Column name that will hold the end revision number in audit entities. Defaults to {@literal REVEND}.
|
||||
*/
|
||||
public static final String AUDIT_STRATEGY_VALIDITY_END_REV_FIELD_NAME = "org.hibernate.envers.audit_strategy_validity_end_rev_field_name";
|
||||
String AUDIT_STRATEGY_VALIDITY_END_REV_FIELD_NAME = "org.hibernate.envers.audit_strategy_validity_end_rev_field_name";
|
||||
|
||||
/**
|
||||
* Store the timestamp of the end revision, until which the data was valid,
|
||||
* in addition to the end revision itself. Defaults to {@code false}.
|
||||
*/
|
||||
public static final String AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP = "org.hibernate.envers.audit_strategy_validity_store_revend_timestamp";
|
||||
String AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP = "org.hibernate.envers.audit_strategy_validity_store_revend_timestamp";
|
||||
|
||||
/**
|
||||
* Column name of the timestamp of the end revision until which the data was valid.
|
||||
* Defaults to {@literal REVEND_TSTMP}.
|
||||
*/
|
||||
public static final String AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME = "org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name";
|
||||
String AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME = "org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name";
|
||||
|
||||
/**
|
||||
* Name of column used for storing ordinal of the change in sets of embeddable elements. Defaults to {@literal SETORDINAL}.
|
||||
*/
|
||||
public static final String EMBEDDABLE_SET_ORDINAL_FIELD_NAME = "org.hibernate.envers.embeddable_set_ordinal_field_name";
|
||||
String EMBEDDABLE_SET_ORDINAL_FIELD_NAME = "org.hibernate.envers.embeddable_set_ordinal_field_name";
|
||||
|
||||
/**
|
||||
* Guarantees proper validity audit strategy behavior when application reuses identifiers of deleted entities.
|
||||
* Exactly one row with {@code null} end date exists for each identifier.
|
||||
*/
|
||||
public static final String ALLOW_IDENTIFIER_REUSE = "org.hibernate.envers.allow_identifier_reuse";
|
||||
String ALLOW_IDENTIFIER_REUSE = "org.hibernate.envers.allow_identifier_reuse";
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class AuditEntitiesConfiguration {
|
|||
revisionEndTimestampFieldName = null;
|
||||
}
|
||||
|
||||
customAuditTablesNames = new HashMap<String, String>();
|
||||
customAuditTablesNames = new HashMap<>();
|
||||
|
||||
revisionNumberPath = originalIdPropName + "." + revisionFieldName + ".id";
|
||||
revisionPropBasePath = originalIdPropName + "." + revisionFieldName + ".";
|
||||
|
|
|
@ -31,8 +31,8 @@ public class ClassesAuditingData {
|
|||
ClassesAuditingData.class.getName()
|
||||
);
|
||||
|
||||
private final Map<String, ClassAuditingData> entityNameToAuditingData = new HashMap<String, ClassAuditingData>();
|
||||
private final Map<PersistentClass, ClassAuditingData> persistentClassToAuditingData = new LinkedHashMap<PersistentClass, ClassAuditingData>();
|
||||
private final Map<String, ClassAuditingData> entityNameToAuditingData = new HashMap<>();
|
||||
private final Map<PersistentClass, ClassAuditingData> persistentClassToAuditingData = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Stores information about auditing meta-data for the given class.
|
||||
|
|
|
@ -51,7 +51,7 @@ public class EntitiesConfigurator {
|
|||
.iterator();
|
||||
|
||||
final ClassesAuditingData classesAuditingData = new ClassesAuditingData();
|
||||
final Map<PersistentClass, EntityXmlMappingData> xmlMappings = new HashMap<PersistentClass, EntityXmlMappingData>();
|
||||
final Map<PersistentClass, EntityXmlMappingData> xmlMappings = new HashMap<>();
|
||||
|
||||
// Reading metadata from annotations
|
||||
while ( classes.hasNext() ) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class PersistentClassGraphDefiner implements GraphDefiner<PersistentClass
|
|||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public List<PersistentClass> getNeighbours(PersistentClass pc) {
|
||||
final List<PersistentClass> neighbours = new ArrayList<PersistentClass>();
|
||||
final List<PersistentClass> neighbours = new ArrayList<>();
|
||||
|
||||
addNeighbours( neighbours, (Iterator<PersistentClass>) pc.getSubclassIterator() );
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import org.hibernate.MappingException;
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class AuditEntityNameRegister {
|
||||
private final Set<String> auditEntityNames = new HashSet<String>();
|
||||
private final Set<String> auditEntityNames = new HashSet<>();
|
||||
|
||||
/**
|
||||
* @param auditEntityName Name of the audit entity.
|
||||
|
|
|
@ -113,9 +113,9 @@ public final class AuditMetadataGenerator {
|
|||
|
||||
this.auditEntityNameRegister = auditEntityNameRegister;
|
||||
|
||||
entitiesConfigurations = new HashMap<String, EntityConfiguration>();
|
||||
notAuditedEntitiesConfigurations = new HashMap<String, EntityConfiguration>();
|
||||
entitiesJoins = new HashMap<String, Map<Join, Element>>();
|
||||
entitiesConfigurations = new HashMap<>();
|
||||
notAuditedEntitiesConfigurations = new HashMap<>();
|
||||
entitiesJoins = new HashMap<>();
|
||||
|
||||
classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
||||
}
|
||||
|
@ -439,7 +439,7 @@ public final class AuditMetadataGenerator {
|
|||
@SuppressWarnings({"unchecked"})
|
||||
private void createJoins(PersistentClass pc, Element parent, ClassAuditingData auditingData) {
|
||||
final Iterator<Join> joins = pc.getJoinIterator();
|
||||
final Map<Join, Element> joinElements = new HashMap<Join, Element>();
|
||||
final Map<Join, Element> joinElements = new HashMap<>();
|
||||
entitiesJoins.put( pc.getEntityName(), joinElements );
|
||||
|
||||
while ( joins.hasNext() ) {
|
||||
|
|
|
@ -27,7 +27,7 @@ public class EntityXmlMappingData {
|
|||
|
||||
public EntityXmlMappingData() {
|
||||
mainXmlMapping = DocumentHelper.createDocument();
|
||||
additionalXmlMappings = new ArrayList<Document>();
|
||||
additionalXmlMappings = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Document getMainXmlMapping() {
|
||||
|
|
|
@ -50,7 +50,7 @@ public final class QueryGeneratorBuilder {
|
|||
this.auditMiddleEntityName = auditMiddleEntityName;
|
||||
this.revisionTypeInId = revisionTypeInId;
|
||||
|
||||
idDatas = new ArrayList<MiddleIdData>();
|
||||
idDatas = new ArrayList<>();
|
||||
}
|
||||
|
||||
void addRelation(MiddleIdData idData) {
|
||||
|
|
|
@ -27,7 +27,7 @@ public class PropertyAuditingData {
|
|||
private String mapKey;
|
||||
private AuditJoinTable joinTable;
|
||||
private String accessType;
|
||||
private final List<AuditOverride> auditJoinTableOverrides = new ArrayList<AuditOverride>( 0 );
|
||||
private final List<AuditOverride> auditJoinTableOverrides = new ArrayList<>( 0 );
|
||||
private RelationTargetAuditMode relationTargetAuditMode;
|
||||
private String auditMappedBy;
|
||||
private String relationMappedBy;
|
||||
|
|
|
@ -33,7 +33,7 @@ public class SequenceIdTrackingModifiedEntitiesRevisionEntity extends SequenceId
|
|||
@Column(name = "ENTITYNAME")
|
||||
@Fetch(FetchMode.JOIN)
|
||||
@ModifiedEntityNames
|
||||
private Set<String> modifiedEntityNames = new HashSet<String>();
|
||||
private Set<String> modifiedEntityNames = new HashSet<>();
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Set<String> getModifiedEntityNames() {
|
||||
|
|
|
@ -25,7 +25,7 @@ public class EntitiesConfigurations {
|
|||
private Map<String, EntityConfiguration> notAuditedEntitiesConfigurations;
|
||||
|
||||
// Map versions entity name -> entity name
|
||||
private Map<String, String> entityNamesForVersionsEntityNames = new HashMap<String, String>();
|
||||
private Map<String, String> entityNamesForVersionsEntityNames = new HashMap<>();
|
||||
|
||||
public EntitiesConfigurations(
|
||||
Map<String, EntityConfiguration> entitiesConfigurations,
|
||||
|
@ -38,20 +38,17 @@ public class EntitiesConfigurations {
|
|||
}
|
||||
|
||||
private void generateVersionsEntityToEntityNames() {
|
||||
entityNamesForVersionsEntityNames = new HashMap<String, String>();
|
||||
|
||||
for ( String entityName : entitiesConfigurations.keySet() ) {
|
||||
entityNamesForVersionsEntityNames.put(
|
||||
entitiesConfigurations.get( entityName ).getVersionsEntityName(),
|
||||
entityName
|
||||
);
|
||||
entityNamesForVersionsEntityNames = new HashMap<>();
|
||||
for ( Map.Entry<String, EntityConfiguration> entry : entitiesConfigurations.entrySet() ) {
|
||||
entityNamesForVersionsEntityNames.put( entry.getValue().getVersionsEntityName(), entry.getKey() );
|
||||
}
|
||||
}
|
||||
|
||||
private void generateBidirectionRelationInfo() {
|
||||
// Checking each relation if it is bidirectional. If so, storing that information.
|
||||
for ( String entityName : entitiesConfigurations.keySet() ) {
|
||||
final EntityConfiguration entCfg = entitiesConfigurations.get( entityName );
|
||||
for ( Map.Entry<String, EntityConfiguration> entry : entitiesConfigurations.entrySet() ) {
|
||||
final String entityName = entry.getKey();
|
||||
final EntityConfiguration entCfg = entry.getValue();
|
||||
// Iterating over all relations from that entity
|
||||
for ( RelationDescription relDesc : entCfg.getRelationsIterator() ) {
|
||||
// If this is an "owned" relation, checking the related entity, if it has a relation that has
|
||||
|
@ -116,7 +113,7 @@ public class EntitiesConfigurations {
|
|||
|
||||
private Collection<RelationDescription> getRelationDescriptions(String entityName) {
|
||||
final EntityConfiguration entCfg = entitiesConfigurations.get( entityName );
|
||||
Collection<RelationDescription> descriptions = new ArrayList<RelationDescription>();
|
||||
Collection<RelationDescription> descriptions = new ArrayList<>();
|
||||
if ( entCfg.getParentEntityName() != null ) {
|
||||
// collect descriptions from super classes
|
||||
descriptions.addAll( getRelationDescriptions( entCfg.getParentEntityName() ) );
|
||||
|
@ -137,14 +134,14 @@ public class EntitiesConfigurations {
|
|||
}
|
||||
|
||||
private Set<String> getEntityAndParentsNames(String entityName) {
|
||||
final Set<String> names = new HashSet<String>();
|
||||
final Set<String> names = new HashSet<>();
|
||||
addWithParentEntityNames( entityName, names );
|
||||
return names;
|
||||
}
|
||||
|
||||
public Set<String> getToPropertyNames(String fromEntityName, String fromPropertyName, String toEntityName) {
|
||||
final Set<String> entityAndParentsNames = getEntityAndParentsNames( fromEntityName );
|
||||
final Set<String> toPropertyNames = new HashSet<String>();
|
||||
final Set<String> toPropertyNames = new HashSet<>();
|
||||
for ( RelationDescription relationDescription : getRelationDescriptions( toEntityName ) ) {
|
||||
final String relToEntityName = relationDescription.getToEntityName();
|
||||
final String mappedByPropertyName = relationDescription.getMappedByPropertyName();
|
||||
|
|
|
@ -41,7 +41,7 @@ public class EntityConfiguration {
|
|||
this.propertyMapper = propertyMapper;
|
||||
this.parentEntityName = parentEntityName;
|
||||
|
||||
this.relations = new HashMap<String, RelationDescription>();
|
||||
this.relations = new HashMap<>();
|
||||
}
|
||||
|
||||
public void addToOneRelation(
|
||||
|
|
|
@ -145,7 +145,8 @@ public class EntityInstantiator {
|
|||
key,
|
||||
versionsReader.getSessionImplementor()
|
||||
.getFactory()
|
||||
.getEntityPersister( entityName )
|
||||
.getMetamodel()
|
||||
.entityPersister( entityName )
|
||||
.createProxy( entityId, delegate )
|
||||
);
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB
|
|||
if ( propertyData.isUsingModifiedFlag() ) {
|
||||
data.put(
|
||||
propertyData.getModifiedFlagPropertyName(),
|
||||
delegate.mapToMapFromEntity( session, new HashMap<String, Object>(), newObj, oldObj )
|
||||
delegate.mapToMapFromEntity( session, new HashMap<>(), newObj, oldObj )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ import org.hibernate.envers.internal.entities.PropertyData;
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public interface CompositeMapperBuilder extends SimpleMapperBuilder {
|
||||
public CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass);
|
||||
CompositeMapperBuilder addComponent(PropertyData propertyData, Class componentClass);
|
||||
|
||||
public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper);
|
||||
void addComposite(PropertyData propertyData, PropertyMapper propertyMapper);
|
||||
|
||||
public Map<PropertyData, PropertyMapper> getProperties();
|
||||
Map<PropertyData, PropertyMapper> getProperties();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.hibernate.engine.spi.SessionImplementor;
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public interface ExtendedPropertyMapper extends PropertyMapper, CompositeMapperBuilder {
|
||||
public boolean map(
|
||||
boolean map(
|
||||
SessionImplementor session,
|
||||
Map<String, Object> data,
|
||||
String[] propertyNames,
|
||||
|
|
|
@ -35,14 +35,16 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper {
|
|||
Object newObj,
|
||||
Object oldObj) {
|
||||
boolean ret = false;
|
||||
for ( PropertyData propertyData : properties.keySet() ) {
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet() ) {
|
||||
final PropertyData propertyData = entry.getKey();
|
||||
final PropertyMapper propertyMapper = entry.getValue();
|
||||
if ( newObj == null && oldObj == null ) {
|
||||
return false;
|
||||
}
|
||||
Object newValue = newObj == null ? null : getValue( newObj, propertyData );
|
||||
Object oldValue = oldObj == null ? null : getValue( oldObj, propertyData );
|
||||
|
||||
ret |= properties.get( propertyData ).mapToMapFromEntity( session, data, newValue, oldValue );
|
||||
ret |= propertyMapper.mapToMapFromEntity( session, data, newValue, oldValue );
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -81,13 +83,15 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper {
|
|||
Map<String, Object> data,
|
||||
Object newObj,
|
||||
Object oldObj) {
|
||||
for ( PropertyData propertyData : properties.keySet() ) {
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet() ) {
|
||||
final PropertyData propertyData = entry.getKey();
|
||||
final PropertyMapper propertyMapper = entry.getValue();
|
||||
if ( newObj == null && oldObj == null ) {
|
||||
return;
|
||||
}
|
||||
Object newValue = newObj == null ? null : getValue( newObj, propertyData );
|
||||
Object oldValue = oldObj == null ? null : getValue( oldObj, propertyData );
|
||||
properties.get( propertyData ).mapModifiedFlagsToMapFromEntity( session, data, newValue, oldValue );
|
||||
propertyMapper.mapModifiedFlagsToMapFromEntity( session, data, newValue, oldValue );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,8 +110,7 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper {
|
|||
properties.keySet(),
|
||||
enversService.getClassLoaderService()
|
||||
);
|
||||
for ( PropertyData propertyData : properties.keySet() ) {
|
||||
PropertyMapper mapper = properties.get( propertyData );
|
||||
for ( PropertyMapper mapper : properties.values() ) {
|
||||
mapper.mapToEntityFromMap( enversService, mapProxy, data, primaryKey, versionsReader, revision );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,9 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
|
|||
Object newObj,
|
||||
Object oldObj) {
|
||||
boolean ret = false;
|
||||
for ( PropertyData propertyData : properties.keySet() ) {
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet() ) {
|
||||
final PropertyData propertyData = entry.getKey();
|
||||
final PropertyMapper propertyMapper = entry.getValue();
|
||||
Getter getter;
|
||||
if ( newObj != null ) {
|
||||
getter = ReflectionTools.getGetter( newObj.getClass(), propertyData, session.getFactory().getServiceRegistry() );
|
||||
|
@ -110,8 +112,7 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
|
|||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret |= properties.get( propertyData ).mapToMapFromEntity(
|
||||
ret |= propertyMapper.mapToMapFromEntity(
|
||||
session, data,
|
||||
newObj == null ? null : getter.get( newObj ),
|
||||
oldObj == null ? null : getter.get( oldObj )
|
||||
|
@ -127,7 +128,9 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
|
|||
Map<String, Object> data,
|
||||
Object newObj,
|
||||
Object oldObj) {
|
||||
for ( PropertyData propertyData : properties.keySet() ) {
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet() ) {
|
||||
final PropertyData propertyData = entry.getKey();
|
||||
final PropertyMapper propertyMapper = entry.getValue();
|
||||
Getter getter;
|
||||
if ( newObj != null ) {
|
||||
getter = ReflectionTools.getGetter( newObj.getClass(), propertyData, session.getFactory().getServiceRegistry() );
|
||||
|
@ -138,8 +141,7 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
|
|||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
properties.get( propertyData ).mapModifiedFlagsToMapFromEntity(
|
||||
propertyMapper.mapModifiedFlagsToMapFromEntity(
|
||||
session, data,
|
||||
newObj == null ? null : getter.get( newObj ),
|
||||
oldObj == null ? null : getter.get( oldObj )
|
||||
|
|
|
@ -12,5 +12,5 @@ import org.hibernate.envers.internal.entities.PropertyData;
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public interface SimpleMapperBuilder {
|
||||
public void add(PropertyData propertyData);
|
||||
void add(PropertyData propertyData);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.hibernate.envers.internal.entities.PropertyData;
|
|||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.internal.tools.ReflectionTools;
|
||||
import org.hibernate.envers.internal.tools.StringTools;
|
||||
import org.hibernate.envers.internal.tools.Tools;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.property.access.spi.Setter;
|
||||
import org.hibernate.property.access.spi.SetterFieldImpl;
|
||||
|
||||
|
@ -57,12 +57,12 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder
|
|||
Object oldObj) {
|
||||
data.put( propertyData.getName(), newObj );
|
||||
boolean dbLogicallyDifferent = true;
|
||||
if ( (session.getFactory()
|
||||
if ( (session.getFactory().getJdbcServices()
|
||||
.getDialect() instanceof Oracle8iDialect) && (newObj instanceof String || oldObj instanceof String) ) {
|
||||
// Don't generate new revision when database replaces empty string with NULL during INSERT or UPDATE statements.
|
||||
dbLogicallyDifferent = !(StringTools.isEmpty( newObj ) && StringTools.isEmpty( oldObj ));
|
||||
}
|
||||
return dbLogicallyDifferent && !Tools.objectsEqual( newObj, oldObj );
|
||||
return dbLogicallyDifferent && !EqualsHelper.areEqual( newObj, oldObj );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,7 +72,7 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder
|
|||
Object newObj,
|
||||
Object oldObj) {
|
||||
if ( propertyData.isUsingModifiedFlag() ) {
|
||||
data.put( propertyData.getModifiedFlagPropertyName(), !Tools.objectsEqual( newObj, oldObj ) );
|
||||
data.put( propertyData.getModifiedFlagPropertyName(), !EqualsHelper.areEqual( newObj, oldObj ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ public class SubclassPropertyMapper implements ExtendedPropertyMapper {
|
|||
|
||||
@Override
|
||||
public Map<PropertyData, PropertyMapper> getProperties() {
|
||||
final Map<PropertyData, PropertyMapper> joinedProperties = new HashMap<PropertyData, PropertyMapper>();
|
||||
final Map<PropertyData, PropertyMapper> joinedProperties = new HashMap<>();
|
||||
joinedProperties.putAll( parentMapper.getProperties() );
|
||||
joinedProperties.putAll( main.getProperties() );
|
||||
return joinedProperties;
|
||||
|
|
|
@ -100,10 +100,10 @@ public class EmbeddedIdMapper extends AbstractCompositeIdMapper implements Simpl
|
|||
|
||||
@Override
|
||||
public List<QueryParameterData> mapToQueryParametersFromId(Object obj) {
|
||||
final Map<String, Object> data = new LinkedHashMap<String, Object>();
|
||||
final Map<String, Object> data = new LinkedHashMap<>();
|
||||
mapToMapFromId( data, obj );
|
||||
|
||||
final List<QueryParameterData> ret = new ArrayList<QueryParameterData>();
|
||||
final List<QueryParameterData> ret = new ArrayList<>();
|
||||
|
||||
for ( Map.Entry<String, Object> propertyData : data.entrySet() ) {
|
||||
ret.add( new QueryParameterData( propertyData.getKey(), propertyData.getValue() ) );
|
||||
|
|
|
@ -81,10 +81,10 @@ public class MultipleIdMapper extends AbstractCompositeIdMapper implements Simpl
|
|||
|
||||
@Override
|
||||
public List<QueryParameterData> mapToQueryParametersFromId(Object obj) {
|
||||
final Map<String, Object> data = new LinkedHashMap<String, Object>();
|
||||
final Map<String, Object> data = new LinkedHashMap<>();
|
||||
mapToMapFromId( data, obj );
|
||||
|
||||
final List<QueryParameterData> ret = new ArrayList<QueryParameterData>();
|
||||
final List<QueryParameterData> ret = new ArrayList<>();
|
||||
|
||||
for ( Map.Entry<String, Object> propertyData : data.entrySet() ) {
|
||||
ret.add( new QueryParameterData( propertyData.getKey(), propertyData.getValue() ) );
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.envers.internal.entities.mapper.id;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
|
|
|
@ -125,7 +125,7 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
|||
|
||||
@Override
|
||||
public List<QueryParameterData> mapToQueryParametersFromId(Object obj) {
|
||||
final List<QueryParameterData> ret = new ArrayList<QueryParameterData>();
|
||||
final List<QueryParameterData> ret = new ArrayList<>();
|
||||
|
||||
ret.add( new QueryParameterData( propertyData.getName(), obj ) );
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.hibernate.envers.internal.entities.mapper.PropertyMapper;
|
|||
import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor;
|
||||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.internal.tools.ReflectionTools;
|
||||
import org.hibernate.envers.internal.tools.Tools;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.property.access.spi.Setter;
|
||||
|
||||
/**
|
||||
|
@ -86,7 +86,7 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
* @return Map for holding identifier data.
|
||||
*/
|
||||
protected Map<String, Object> createIdMap(int ordinal) {
|
||||
final Map<String, Object> idMap = new HashMap<String, Object>();
|
||||
final Map<String, Object> idMap = new HashMap<>();
|
||||
if ( ordinalInId ) {
|
||||
idMap.put( commonCollectionMapperData.getVerEntCfg().getEmbeddableSetOrdinalPropertyName(), ordinal );
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
int ordinal = 0;
|
||||
|
||||
for ( Object changedObj : changed ) {
|
||||
final Map<String, Object> entityData = new HashMap<String, Object>();
|
||||
final Map<String, Object> entityData = new HashMap<>();
|
||||
final Map<String, Object> originalId = createIdMap( ordinal++ );
|
||||
entityData.put( commonCollectionMapperData.getVerEntCfg().getOriginalIdPropName(), originalId );
|
||||
|
||||
|
@ -134,13 +134,13 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
return null;
|
||||
}
|
||||
|
||||
final List<PersistentCollectionChangeData> collectionChanges = new ArrayList<PersistentCollectionChangeData>();
|
||||
final List<PersistentCollectionChangeData> collectionChanges = new ArrayList<>();
|
||||
|
||||
// Comparing new and old collection content.
|
||||
final Collection newCollection = getNewCollectionContent( newColl );
|
||||
final Collection oldCollection = getOldCollectionContent( oldColl );
|
||||
|
||||
final Set<Object> added = new HashSet<Object>();
|
||||
final Set<Object> added = new HashSet<>();
|
||||
if ( newColl != null ) {
|
||||
added.addAll( newCollection );
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
|
||||
addCollectionChanges( session, collectionChanges, added, RevisionType.ADD, id );
|
||||
|
||||
final Set<Object> deleted = new HashSet<Object>();
|
||||
final Set<Object> deleted = new HashSet<>();
|
||||
if ( oldColl != null ) {
|
||||
deleted.addAll( oldCollection );
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
if ( propertyData.isUsingModifiedFlag() ) {
|
||||
if ( isNotPersistentCollection( newObj ) || isNotPersistentCollection( oldObj ) ) {
|
||||
// Compare POJOs.
|
||||
data.put( propertyData.getModifiedFlagPropertyName(), !Tools.objectsEqual( newObj, oldObj ) );
|
||||
data.put( propertyData.getModifiedFlagPropertyName(), !EqualsHelper.areEqual( newObj, oldObj ) );
|
||||
}
|
||||
else if ( isFromNullToEmptyOrFromEmptyToNull( (PersistentCollection) newObj, (Serializable) oldObj ) ) {
|
||||
data.put( propertyData.getModifiedFlagPropertyName(), true );
|
||||
|
|
|
@ -42,7 +42,7 @@ public class BasicCollectionMapper<T extends Collection> extends AbstractCollect
|
|||
Object primaryKey,
|
||||
Number revision,
|
||||
boolean removed) {
|
||||
return new BasicCollectionInitializor<T>(
|
||||
return new BasicCollectionInitializor<>(
|
||||
enversService,
|
||||
versionsReader,
|
||||
commonCollectionMapperData.getQueryGenerator(),
|
||||
|
|
|
@ -42,7 +42,7 @@ public class MapCollectionMapper<T extends Map> extends AbstractCollectionMapper
|
|||
Object primaryKey,
|
||||
Number revision,
|
||||
boolean removed) {
|
||||
return new MapCollectionInitializor<T>(
|
||||
return new MapCollectionInitializor<>(
|
||||
enversService,
|
||||
versionsReader,
|
||||
commonCollectionMapperData.getQueryGenerator(),
|
||||
|
|
|
@ -58,9 +58,8 @@ public class OneToOnePrimaryKeyJoinColumnMapper extends AbstractOneToOneMapper {
|
|||
private Object createNotAuditedEntityReference(
|
||||
AuditReaderImplementor versionsReader, Class<?> entityClass,
|
||||
String entityName, Serializable primaryKey) {
|
||||
final EntityPersister entityPersister = versionsReader.getSessionImplementor().getFactory().getEntityPersister(
|
||||
entityName
|
||||
);
|
||||
final EntityPersister entityPersister = versionsReader.getSessionImplementor().getFactory().getMetamodel()
|
||||
.entityPersister( entityName );
|
||||
if ( entityPersister.hasProxy() ) {
|
||||
// If possible create a proxy. Returning complete object may affect performance.
|
||||
return versionsReader.getSession().load( entityClass, primaryKey );
|
||||
|
|
|
@ -57,7 +57,8 @@ public final class ToOneEntityLoader {
|
|||
EnversService enversService) {
|
||||
final EntityPersister persister = versionsReader.getSessionImplementor()
|
||||
.getFactory()
|
||||
.getEntityPersister( entityName );
|
||||
.getMetamodel()
|
||||
.entityPersister( entityName );
|
||||
return persister.createProxy(
|
||||
(Serializable) entityId,
|
||||
new ToOneDelegateSessionImplementor( versionsReader, entityClass, entityId, revision, removed, enversService )
|
||||
|
@ -78,7 +79,8 @@ public final class ToOneEntityLoader {
|
|||
EnversService enversService) {
|
||||
final EntityPersister persister = versionsReader.getSessionImplementor()
|
||||
.getFactory()
|
||||
.getEntityPersister( entityName );
|
||||
.getMetamodel()
|
||||
.entityPersister( entityName );
|
||||
if ( persister.hasProxy() ) {
|
||||
return createProxy( versionsReader, entityClass, entityName, entityId, revision, removed, enversService );
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class ToOneIdMapper extends AbstractToOneMapper {
|
|||
Map<String, Object> data,
|
||||
Object newObj,
|
||||
Object oldObj) {
|
||||
final HashMap<String, Object> newData = new HashMap<String, Object>();
|
||||
final HashMap<String, Object> newData = new HashMap<>();
|
||||
|
||||
// If this property is originally non-insertable, but made insertable because it is in a many-to-one "fake"
|
||||
// bi-directional relation, we always store the "old", unchaged data, to prevent storing changes made
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.envers.internal.entities.mapper.relation.lazy;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.spi.SessionDelegatorBaseImpl;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
|
||||
|
@ -18,7 +17,7 @@ import org.hibernate.engine.spi.SessionImplementor;
|
|||
*/
|
||||
public abstract class AbstractDelegateSessionImplementor extends SessionDelegatorBaseImpl implements SessionImplementor {
|
||||
public AbstractDelegateSessionImplementor(SessionImplementor delegate) {
|
||||
super( delegate, (Session) delegate );
|
||||
super( delegate );
|
||||
}
|
||||
|
||||
public abstract Object doImmediateLoad(String entityName);
|
||||
|
|
|
@ -9,13 +9,13 @@ package org.hibernate.envers.internal.entities.mapper.relation.query;
|
|||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration;
|
||||
import org.hibernate.envers.internal.entities.mapper.id.QueryParameterData;
|
||||
import org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData;
|
||||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.internal.tools.query.QueryBuilder;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.DEL_REVISION_TYPE_PARAMETER;
|
||||
import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REVISION_PARAMETER;
|
||||
|
@ -70,7 +70,7 @@ public abstract class AbstractRelationQueryGenerator implements RelationQueryGen
|
|||
}
|
||||
|
||||
protected String queryToString(QueryBuilder query) {
|
||||
return queryToString( query, Collections.<String, Object>emptyMap() );
|
||||
return queryToString( query, Collections.emptyMap() );
|
||||
}
|
||||
|
||||
protected String queryToString(QueryBuilder query, Map<String, Object> queryParamValues) {
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.envers.internal.entities.mapper.relation.query;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
/**
|
||||
* TODO: cleanup implementations and extract common code
|
||||
|
|
|
@ -12,9 +12,9 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.NoResultException;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.hibernate.Session;
|
||||
|
@ -29,6 +29,7 @@ import org.hibernate.envers.query.AuditEntity;
|
|||
import org.hibernate.envers.query.AuditQueryCreator;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import static org.hibernate.envers.internal.tools.ArgumentsTools.checkNotNull;
|
||||
import static org.hibernate.envers.internal.tools.ArgumentsTools.checkPositive;
|
||||
|
@ -174,7 +175,7 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
|||
checkPositive( revision, "Entity revision" );
|
||||
checkSession();
|
||||
|
||||
final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionDateQuery( session, revision );
|
||||
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionDateQuery( session, revision );
|
||||
|
||||
try {
|
||||
final Object timestampObject = query.uniqueResult();
|
||||
|
@ -195,7 +196,7 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
|||
checkNotNull( date, "Date of revision" );
|
||||
checkSession();
|
||||
|
||||
final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery( session, date );
|
||||
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery( session, date );
|
||||
|
||||
try {
|
||||
final Number res = (Number) query.uniqueResult();
|
||||
|
@ -219,9 +220,9 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
|||
checkPositive( revision, "Entity revision" );
|
||||
checkSession();
|
||||
|
||||
final Set<Number> revisions = new HashSet<Number>( 1 );
|
||||
final Set<Number> revisions = new HashSet<>( 1 );
|
||||
revisions.add( revision );
|
||||
final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions );
|
||||
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions );
|
||||
|
||||
try {
|
||||
final T revisionData = (T) query.uniqueResult();
|
||||
|
@ -243,7 +244,7 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
|||
throws IllegalArgumentException,
|
||||
IllegalStateException {
|
||||
revisionEntityClass = getTargetClassIfProxied( revisionEntityClass );
|
||||
final Map<Number, T> result = new HashMap<Number, T>( revisions.size() );
|
||||
final Map<Number, T> result = new HashMap<>( revisions.size() );
|
||||
|
||||
for ( Number revision : revisions ) {
|
||||
checkNotNull( revision, "Entity revision" );
|
||||
|
@ -251,13 +252,13 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
|||
}
|
||||
checkSession();
|
||||
|
||||
final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions );
|
||||
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions );
|
||||
|
||||
try {
|
||||
final List<T> revisionList = query.list();
|
||||
for ( T revision : revisionList ) {
|
||||
final List<?> revisionList = query.getResultList();
|
||||
for ( Object revision : revisionList ) {
|
||||
final Number revNo = enversService.getRevisionInfoNumberReader().getRevisionNumber( revision );
|
||||
result.put( revNo, revision );
|
||||
result.put( revNo, (T) revision );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.envers.CrossTypeRevisionChangesReader;
|
||||
|
@ -23,6 +22,7 @@ import org.hibernate.envers.boot.internal.EnversService;
|
|||
import org.hibernate.envers.internal.tools.EntityTools;
|
||||
import org.hibernate.envers.query.criteria.internal.RevisionTypeAuditExpression;
|
||||
import org.hibernate.envers.tools.Pair;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import static org.hibernate.envers.internal.tools.ArgumentsTools.checkNotNull;
|
||||
import static org.hibernate.envers.internal.tools.ArgumentsTools.checkPositive;
|
||||
|
@ -45,7 +45,7 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan
|
|||
@SuppressWarnings({"unchecked"})
|
||||
public List<Object> findEntities(Number revision) throws IllegalStateException, IllegalArgumentException {
|
||||
final Set<Pair<String, Class>> entityTypes = findEntityTypes( revision );
|
||||
final List<Object> result = new ArrayList<Object>();
|
||||
final List<Object> result = new ArrayList<>();
|
||||
for ( Pair<String, Class> type : entityTypes ) {
|
||||
result.addAll(
|
||||
auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision(
|
||||
|
@ -64,7 +64,7 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan
|
|||
public List<Object> findEntities(Number revision, RevisionType revisionType)
|
||||
throws IllegalStateException, IllegalArgumentException {
|
||||
final Set<Pair<String, Class>> entityTypes = findEntityTypes( revision );
|
||||
final List<Object> result = new ArrayList<Object>();
|
||||
final List<Object> result = new ArrayList<>();
|
||||
for ( Pair<String, Class> type : entityTypes ) {
|
||||
result.addAll(
|
||||
auditReaderImplementor.createQuery().forEntitiesModifiedAtRevision(
|
||||
|
@ -83,9 +83,9 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan
|
|||
public Map<RevisionType, List<Object>> findEntitiesGroupByRevisionType(Number revision)
|
||||
throws IllegalStateException, IllegalArgumentException {
|
||||
final Set<Pair<String, Class>> entityTypes = findEntityTypes( revision );
|
||||
final Map<RevisionType, List<Object>> result = new HashMap<RevisionType, List<Object>>();
|
||||
final Map<RevisionType, List<Object>> result = new HashMap<>();
|
||||
for ( RevisionType revisionType : RevisionType.values() ) {
|
||||
result.put( revisionType, new ArrayList<Object>() );
|
||||
result.put( revisionType, new ArrayList<>() );
|
||||
for ( Pair<String, Class> type : entityTypes ) {
|
||||
final List<Object> list = auditReaderImplementor.createQuery()
|
||||
.forEntitiesModifiedAtRevision( type.getSecond(), type.getFirst(), revision )
|
||||
|
@ -108,9 +108,9 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan
|
|||
final Session session = auditReaderImplementor.getSession();
|
||||
final SessionImplementor sessionImplementor = auditReaderImplementor.getSessionImplementor();
|
||||
|
||||
final Set<Number> revisions = new HashSet<Number>( 1 );
|
||||
final Set<Number> revisions = new HashSet<>( 1 );
|
||||
revisions.add( revision );
|
||||
final Criteria query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions );
|
||||
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery( session, revisions );
|
||||
final Object revisionInfo = query.uniqueResult();
|
||||
|
||||
if ( revisionInfo != null ) {
|
||||
|
@ -118,13 +118,12 @@ public class CrossTypeRevisionChangesReaderImpl implements CrossTypeRevisionChan
|
|||
final Set<String> entityNames = enversService.getModifiedEntityNamesReader().getModifiedEntityNames( revisionInfo );
|
||||
if ( entityNames != null ) {
|
||||
// Generate result that contains entity names and corresponding Java classes.
|
||||
final Set<Pair<String, Class>> result = new HashSet<Pair<String, Class>>();
|
||||
final Set<Pair<String, Class>> result = new HashSet<>();
|
||||
for ( String entityName : entityNames ) {
|
||||
result.add(
|
||||
Pair.make(
|
||||
entityName, EntityTools.getEntityClass(
|
||||
sessionImplementor,
|
||||
session,
|
||||
entityName
|
||||
)
|
||||
)
|
||||
|
|
|
@ -54,7 +54,7 @@ public class DefaultTrackingModifiedEntitiesRevisionInfoGenerator extends Defaul
|
|||
super.entityChanged( entityClass, entityName, entityId, revisionType, revisionEntity );
|
||||
Set<String> modifiedEntityNames = (Set<String>) modifiedEntityNamesGetter.get( revisionEntity );
|
||||
if ( modifiedEntityNames == null ) {
|
||||
modifiedEntityNames = new HashSet<String>();
|
||||
modifiedEntityNames = new HashSet<>();
|
||||
modifiedEntityNamesSetter.set( revisionEntity, modifiedEntityNames, null );
|
||||
}
|
||||
modifiedEntityNames.add( entityName );
|
||||
|
|
|
@ -9,16 +9,22 @@ package org.hibernate.envers.internal.revisioninfo;
|
|||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.criterion.Projections;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
public class RevisionInfoQueryCreator {
|
||||
private static final String REVISION_DATE_QUERY = "SELECT %s FROM %s WHERE %s = :revision";
|
||||
private static final String REVISION_DATE_QUERY_PARAMETER = "revision";
|
||||
private static final String REVISION_NUMBER_FOR_DATE_QUERY = "SELECT MAX(%s) FROM %s WHERE %s <= :date";
|
||||
private static final String REVISION_NUMBER_FOR_DATE_QUERY_PARAMETER = "date";
|
||||
private static final String REVISIONS_QUERY = "FROM %s WHERE %s IN (:revisions)";
|
||||
private static final String REVISIONS_QUERY_PARAMETER = "revisions";
|
||||
|
||||
private final String revisionInfoEntityName;
|
||||
private final String revisionInfoIdName;
|
||||
private final String revisionInfoTimestampName;
|
||||
|
@ -33,21 +39,31 @@ public class RevisionInfoQueryCreator {
|
|||
this.timestampAsDate = timestampAsDate;
|
||||
}
|
||||
|
||||
public Criteria getRevisionDateQuery(Session session, Number revision) {
|
||||
return session.createCriteria( revisionInfoEntityName ).setProjection(
|
||||
Projections.property(
|
||||
public Query<?> getRevisionDateQuery(Session session, Number revision) {
|
||||
return session.createQuery(
|
||||
String.format(
|
||||
REVISION_DATE_QUERY,
|
||||
revisionInfoTimestampName,
|
||||
revisionInfoEntityName,
|
||||
revisionInfoIdName
|
||||
)
|
||||
).setParameter( REVISION_DATE_QUERY_PARAMETER, revision );
|
||||
}
|
||||
|
||||
public Query<?> getRevisionNumberForDateQuery(Session session, Date date) {
|
||||
return session.createQuery(
|
||||
String.format(
|
||||
REVISION_NUMBER_FOR_DATE_QUERY,
|
||||
revisionInfoIdName,
|
||||
revisionInfoEntityName,
|
||||
revisionInfoTimestampName
|
||||
)
|
||||
)
|
||||
.add( Restrictions.eq( revisionInfoIdName, revision ) );
|
||||
).setParameter( REVISION_NUMBER_FOR_DATE_QUERY_PARAMETER, timestampAsDate ? date : date.getTime() );
|
||||
}
|
||||
|
||||
public Criteria getRevisionNumberForDateQuery(Session session, Date date) {
|
||||
return session.createCriteria( revisionInfoEntityName ).setProjection( Projections.max( revisionInfoIdName ) )
|
||||
.add( Restrictions.le( revisionInfoTimestampName, timestampAsDate ? date : date.getTime() ) );
|
||||
}
|
||||
|
||||
public Criteria getRevisionsQuery(Session session, Set<Number> revisions) {
|
||||
return session.createCriteria( revisionInfoEntityName ).add( Restrictions.in( revisionInfoIdName, revisions ) );
|
||||
public Query<?> getRevisionsQuery(Session session, Set<Number> revisions) {
|
||||
return session.createQuery(
|
||||
String.format( REVISIONS_QUERY, revisionInfoEntityName, revisionInfoIdName )
|
||||
).setParameter( REVISIONS_QUERY_PARAMETER, revisions );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,15 +10,16 @@ import java.util.HashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
import javax.persistence.FlushModeType;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.envers.internal.revisioninfo.RevisionInfoGenerator;
|
||||
import org.hibernate.envers.internal.synchronization.work.AuditWorkUnit;
|
||||
import org.hibernate.envers.tools.Pair;
|
||||
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
|
@ -41,9 +42,9 @@ public class AuditProcess implements BeforeTransactionCompletionProcess {
|
|||
this.revisionInfoGenerator = revisionInfoGenerator;
|
||||
this.session = session;
|
||||
|
||||
workUnits = new LinkedList<AuditWorkUnit>();
|
||||
undoQueue = new LinkedList<AuditWorkUnit>();
|
||||
usedIds = new HashMap<Pair<String, Object>, AuditWorkUnit>();
|
||||
workUnits = new LinkedList<>();
|
||||
undoQueue = new LinkedList<>();
|
||||
usedIds = new HashMap<>();
|
||||
entityChangeNotifier = new EntityChangeNotifier( revisionInfoGenerator, session );
|
||||
}
|
||||
|
||||
|
@ -136,10 +137,10 @@ public class AuditProcess implements BeforeTransactionCompletionProcess {
|
|||
if ( FlushModeType.COMMIT.equals( session.getFlushMode() ) ) {
|
||||
Session temporarySession = null;
|
||||
try {
|
||||
temporarySession = ( (Session) session ).sessionWithOptions()
|
||||
.transactionContext()
|
||||
temporarySession = session.sessionWithOptions()
|
||||
.connection()
|
||||
.autoClose( false )
|
||||
.connectionReleaseMode( ConnectionReleaseMode.AFTER_TRANSACTION )
|
||||
.connectionHandlingMode( PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION )
|
||||
.openSession();
|
||||
executeInSession( temporarySession );
|
||||
temporarySession.flush();
|
||||
|
@ -151,7 +152,7 @@ public class AuditProcess implements BeforeTransactionCompletionProcess {
|
|||
}
|
||||
}
|
||||
else {
|
||||
executeInSession( (Session) session );
|
||||
executeInSession( session );
|
||||
|
||||
// Explicitly flushing the session, as the auto-flush may have already happened.
|
||||
session.flush();
|
||||
|
|
|
@ -25,7 +25,7 @@ public class AuditProcessManager {
|
|||
private final RevisionInfoGenerator revisionInfoGenerator;
|
||||
|
||||
public AuditProcessManager(RevisionInfoGenerator revisionInfoGenerator) {
|
||||
auditProcesses = new ConcurrentHashMap<Transaction, AuditProcess>();
|
||||
auditProcesses = new ConcurrentHashMap<>();
|
||||
|
||||
this.revisionInfoGenerator = revisionInfoGenerator;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class EntityChangeNotifier {
|
|||
// Notify about a change in collection owner entity.
|
||||
entityId = ( (PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) entityId ).getOwnerId();
|
||||
}
|
||||
final Class entityClass = EntityTools.getEntityClass( sessionImplementor, session, vwu.getEntityName() );
|
||||
final Class entityClass = EntityTools.getEntityClass( sessionImplementor, vwu.getEntityName() );
|
||||
revisionInfoGenerator.entityChanged(
|
||||
entityClass,
|
||||
vwu.getEntityName(),
|
||||
|
|
|
@ -49,7 +49,7 @@ public abstract class AbstractAuditWorkUnit implements AuditWorkUnit {
|
|||
protected void fillDataWithId(Map<String, Object> data, Object revision) {
|
||||
final AuditEntitiesConfiguration entitiesCfg = enversService.getAuditEntitiesConfiguration();
|
||||
|
||||
final Map<String, Object> originalId = new HashMap<String, Object>();
|
||||
final Map<String, Object> originalId = new HashMap<>();
|
||||
originalId.put( entitiesCfg.getRevisionFieldName(), revision );
|
||||
|
||||
enversService.getEntitiesConfigurations().get( getEntityName() ).getIdMapper().mapToMapFromId( originalId, id );
|
||||
|
|
|
@ -31,7 +31,7 @@ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit
|
|||
Serializable id, EntityPersister entityPersister, Object[] state) {
|
||||
super( sessionImplementor, entityName, enversService, id, RevisionType.ADD );
|
||||
|
||||
this.data = new HashMap<String, Object>();
|
||||
this.data = new HashMap<>();
|
||||
this.state = state;
|
||||
this.enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().map(
|
||||
sessionImplementor,
|
||||
|
@ -51,8 +51,8 @@ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit
|
|||
super( sessionImplementor, entityName, enversService, id, RevisionType.ADD );
|
||||
|
||||
this.data = data;
|
||||
final String[] propertyNames = sessionImplementor.getFactory()
|
||||
.getEntityPersister( getEntityName() )
|
||||
final String[] propertyNames = sessionImplementor.getFactory().getMetamodel()
|
||||
.entityPersister( getEntityName() )
|
||||
.getPropertyNames();
|
||||
this.state = ArraysTools.mapToArray( data, propertyNames );
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.hibernate.envers.boot.internal.EnversService;
|
|||
public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit {
|
||||
private Object entity;
|
||||
private final String collectionPropertyName;
|
||||
private final Map<String, Object> data = new HashMap<String, Object>();
|
||||
private final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
public CollectionChangeWorkUnit(
|
||||
SessionImplementor session,
|
||||
|
@ -44,7 +44,7 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A
|
|||
@Override
|
||||
public Map<String, Object> generateData(Object revisionData) {
|
||||
fillDataWithId( data, revisionData );
|
||||
final Map<String, Object> preGenerateData = new HashMap<String, Object>( data );
|
||||
final Map<String, Object> preGenerateData = new HashMap<>( data );
|
||||
enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().mapToMapFromEntity(
|
||||
sessionImplementor,
|
||||
data,
|
||||
|
|
|
@ -46,7 +46,7 @@ public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit
|
|||
|
||||
@Override
|
||||
public Map<String, Object> generateData(Object revisionData) {
|
||||
final Map<String, Object> data = new HashMap<String, Object>();
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
fillDataWithId( data, revisionData );
|
||||
|
||||
if ( enversService.getGlobalConfiguration().isStoreDataAtDelete() ) {
|
||||
|
|
|
@ -46,7 +46,7 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp
|
|||
this.nestedWorkUnit = nestedWorkUnit;
|
||||
|
||||
// Adding the change for the relation.
|
||||
fakeRelationChanges = new HashMap<String, FakeRelationChange>();
|
||||
fakeRelationChanges = new HashMap<>();
|
||||
fakeRelationChanges.put(
|
||||
referencingPropertyName, new FakeRelationChange(
|
||||
owningEntity,
|
||||
|
@ -72,7 +72,7 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp
|
|||
|
||||
this.nestedWorkUnit = nestedWorkUnit;
|
||||
|
||||
fakeRelationChanges = new HashMap<String, FakeRelationChange>( original.getFakeRelationChanges() );
|
||||
fakeRelationChanges = new HashMap<>( original.getFakeRelationChanges() );
|
||||
}
|
||||
|
||||
public AuditWorkUnit getNestedWorkUnit() {
|
||||
|
@ -92,7 +92,7 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp
|
|||
public Map<String, Object> generateData(Object revisionData) {
|
||||
// Generating data with the nested work unit. This data contains all data except the fake relation.
|
||||
// Making a defensive copy not to modify the data held by the nested work unit.
|
||||
final Map<String, Object> nestedData = new HashMap<String, Object>( nestedWorkUnit.generateData( revisionData ) );
|
||||
final Map<String, Object> nestedData = new HashMap<>( nestedWorkUnit.generateData( revisionData ) );
|
||||
|
||||
// Now adding data for all fake relations.
|
||||
for ( FakeRelationChange fakeRelationChange : fakeRelationChanges.values() ) {
|
||||
|
@ -129,8 +129,8 @@ public class FakeBidirectionalRelationWorkUnit extends AbstractAuditWorkUnit imp
|
|||
|
||||
// Now merging the fake relation changes from both work units.
|
||||
final Map<String, FakeRelationChange> secondFakeRelationChanges = second.getFakeRelationChanges();
|
||||
final Map<String, FakeRelationChange> mergedFakeRelationChanges = new HashMap<String, FakeRelationChange>();
|
||||
final Set<String> allPropertyNames = new HashSet<String>( fakeRelationChanges.keySet() );
|
||||
final Map<String, FakeRelationChange> mergedFakeRelationChanges = new HashMap<>();
|
||||
final Set<String> allPropertyNames = new HashSet<>( fakeRelationChanges.keySet() );
|
||||
allPropertyNames.addAll( secondFakeRelationChanges.keySet() );
|
||||
|
||||
for ( String propertyName : allPropertyNames ) {
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ModWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit
|
|||
this.entityPersister = entityPersister;
|
||||
this.oldState = oldState;
|
||||
this.newState = newState;
|
||||
this.data = new HashMap<String, Object>();
|
||||
this.data = new HashMap<>();
|
||||
this.changes = enversService.getEntitiesConfigurations().get( getEntityName() ).getPropertyMapper().map(
|
||||
sessionImplementor,
|
||||
data,
|
||||
|
|
|
@ -138,7 +138,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
|
|||
// First building a map from the ids of the collection-entry-entities from the "second" collection changes,
|
||||
// to the PCCD objects. That way, we will be later able to check if an "original" collection change
|
||||
// should be added, or if it is overshadowed by a new one.
|
||||
final Map<Object, PersistentCollectionChangeData> newChangesIdMap = new HashMap<Object, PersistentCollectionChangeData>();
|
||||
final Map<Object, PersistentCollectionChangeData> newChangesIdMap = new HashMap<>();
|
||||
for ( PersistentCollectionChangeData persistentCollectionChangeData : getCollectionChanges() ) {
|
||||
newChangesIdMap.put(
|
||||
getOriginalId( persistentCollectionChangeData ),
|
||||
|
@ -147,7 +147,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
|
|||
}
|
||||
|
||||
// This will be the list with the resulting (merged) changes.
|
||||
final List<PersistentCollectionChangeData> mergedChanges = new ArrayList<PersistentCollectionChangeData>();
|
||||
final List<PersistentCollectionChangeData> mergedChanges = new ArrayList<>();
|
||||
|
||||
// Including only those original changes, which are not overshadowed by new ones.
|
||||
for ( PersistentCollectionChangeData originalCollectionChangeData : original.getCollectionChanges() ) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
|
@ -22,7 +23,7 @@ public abstract class EntityTools {
|
|||
final Object id1 = getIdentifier( session, entityName, obj1 );
|
||||
final Object id2 = getIdentifier( session, entityName, obj2 );
|
||||
|
||||
return Tools.objectsEqual( id1, id2 );
|
||||
return EqualsHelper.areEqual( id1, id2 );
|
||||
}
|
||||
|
||||
public static Object getIdentifier(SessionImplementor session, String entityName, Object obj) {
|
||||
|
@ -85,8 +86,8 @@ public abstract class EntityTools {
|
|||
/**
|
||||
* @return Java class mapped to specified entity name.
|
||||
*/
|
||||
public static Class getEntityClass(SessionImplementor sessionImplementor, Session session, String entityName) {
|
||||
final EntityPersister entityPersister = sessionImplementor.getFactory().getEntityPersister( entityName );
|
||||
public static Class getEntityClass(SessionImplementor sessionImplementor, String entityName) {
|
||||
final EntityPersister entityPersister = sessionImplementor.getFactory().getMetamodel().entityPersister( entityName );
|
||||
return entityPersister.getMappedClass();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,16 +36,15 @@ public final class MapProxyTool {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates instance of map proxy class. This proxy class will be a java bean with properties from <code>propertyDatas</code>.
|
||||
* Instance will proxy calls to instance of the map passed as parameter.
|
||||
*
|
||||
* @param className Name of the class to construct (should be unique within class loader)
|
||||
* @param map instance that will be proxied by java bean
|
||||
* @param propertyDatas properties that should java bean declare
|
||||
* @param classLoaderService
|
||||
* @param classLoaderService class loader service
|
||||
*
|
||||
* @return new instance of proxy
|
||||
*
|
||||
* @author Lukasz Zuchowski (author at zuchos dot com)
|
||||
* Creates instance of map proxy class. This proxy class will be a java bean with properties from <code>propertyDatas</code>.
|
||||
* Instance will proxy calls to instance of the map passed as parameter.
|
||||
*/
|
||||
public static Object newInstanceOfBeanProxyForMap(
|
||||
String className,
|
||||
|
@ -66,7 +65,7 @@ public final class MapProxyTool {
|
|||
}
|
||||
|
||||
private static Map<String, Class<?>> prepareProperties(Set<PropertyData> propertyDatas) {
|
||||
Map<String, Class<?>> properties = new HashMap<String, Class<?>>();
|
||||
Map<String, Class<?>> properties = new HashMap<>();
|
||||
for ( PropertyData propertyData : propertyDatas ) {
|
||||
properties.put( propertyData.getBeanName(), Object.class );
|
||||
}
|
||||
|
@ -88,7 +87,7 @@ public final class MapProxyTool {
|
|||
*
|
||||
* @param className name of the class that will be generated/loaded
|
||||
* @param properties list of properties that should be exposed via java bean
|
||||
* @param classLoaderService
|
||||
* @param classLoaderService class loader service
|
||||
*
|
||||
* @return proxy class that wraps map into java bean
|
||||
*/
|
||||
|
|
|
@ -26,15 +26,15 @@ import org.hibernate.service.ServiceRegistry;
|
|||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public abstract class ReflectionTools {
|
||||
private static final Map<Pair<Class, String>, Getter> GETTER_CACHE = new ConcurrentReferenceHashMap<Pair<Class, String>, Getter>(
|
||||
private static final Map<Pair<Class, String>, Getter> GETTER_CACHE = new ConcurrentReferenceHashMap<>(
|
||||
10,
|
||||
ConcurrentReferenceHashMap.ReferenceType.SOFT,
|
||||
ConcurrentReferenceHashMap.ReferenceType.SOFT
|
||||
);
|
||||
private static final Map<Pair<Class, String>, Setter> SETTER_CACHE = new ConcurrentReferenceHashMap<Pair<Class, String>, Setter>(
|
||||
10,
|
||||
ConcurrentReferenceHashMap.ReferenceType.SOFT,
|
||||
ConcurrentReferenceHashMap.ReferenceType.SOFT
|
||||
private static final Map<Pair<Class, String>, Setter> SETTER_CACHE = new ConcurrentReferenceHashMap<>(
|
||||
10,
|
||||
ConcurrentReferenceHashMap.ReferenceType.SOFT,
|
||||
ConcurrentReferenceHashMap.ReferenceType.SOFT
|
||||
);
|
||||
|
||||
private static PropertyAccessStrategy getAccessStrategy(Class<?> cls, ServiceRegistry serviceRegistry, String accessorType) {
|
||||
|
|
|
@ -63,7 +63,7 @@ public abstract class StringTools {
|
|||
/**
|
||||
* Capitalizes first letter of the string
|
||||
*
|
||||
* @param fieldName
|
||||
* @param fieldName field name
|
||||
*
|
||||
* @return capitalized string
|
||||
*/
|
||||
|
|
|
@ -27,15 +27,15 @@ import org.hibernate.internal.util.compare.EqualsHelper;
|
|||
*/
|
||||
public abstract class Tools {
|
||||
public static <K, V> Map<K, V> newHashMap() {
|
||||
return new HashMap<K, V>();
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
public static <E> Set<E> newHashSet() {
|
||||
return new HashSet<E>();
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
public static <K, V> Map<K, V> newLinkedHashMap() {
|
||||
return new LinkedHashMap<K, V>();
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +49,7 @@ public abstract class Tools {
|
|||
}
|
||||
|
||||
public static <T> List<T> iteratorToList(Iterator<T> iter) {
|
||||
final List<T> ret = new ArrayList<T>();
|
||||
final List<T> ret = new ArrayList<>();
|
||||
while ( iter.hasNext() ) {
|
||||
ret.add( iter.next() );
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public abstract class Tools {
|
|||
return (List<X>) collection;
|
||||
}
|
||||
else {
|
||||
List<X> list = new ArrayList<X>();
|
||||
List<X> list = new ArrayList<>();
|
||||
list.addAll( collection );
|
||||
return list;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public abstract class Tools {
|
|||
* @return A list of pairs: ((0, element_at_index_0), (1, element_at_index_1), ...)
|
||||
*/
|
||||
public static <T> List<Pair<Integer, T>> listToIndexElementPairList(List<T> list) {
|
||||
final List<Pair<Integer, T>> ret = new ArrayList<Pair<Integer, T>>();
|
||||
final List<Pair<Integer, T>> ret = new ArrayList<>();
|
||||
final Iterator<T> listIter = list.iterator();
|
||||
for ( int i = 0; i < list.size(); i++ ) {
|
||||
ret.add( Pair.make( i, listIter.next() ) );
|
||||
|
|
|
@ -65,6 +65,6 @@ public class Triple<T1, T2, T3> {
|
|||
}
|
||||
|
||||
public static <T1, T2, T3> Triple<T1, T2, T3> make(T1 obj1, T2 obj2, T3 obj3) {
|
||||
return new Triple<T1, T2, T3>( obj1, obj2, obj3 );
|
||||
return new Triple<>( obj1, obj2, obj3 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,12 +27,12 @@ public final class GraphTopologicalSort {
|
|||
*/
|
||||
public static <V, R> List<V> sort(GraphDefiner<V, R> definer) {
|
||||
final List<V> values = definer.getValues();
|
||||
final Map<R, Vertex<R>> vertices = new HashMap<R, Vertex<R>>();
|
||||
final Map<R, Vertex<R>> vertices = new HashMap<>();
|
||||
|
||||
// Creating a vertex for each representation
|
||||
for ( V v : values ) {
|
||||
final R rep = definer.getRepresentation( v );
|
||||
vertices.put( rep, new Vertex<R>( rep ) );
|
||||
vertices.put( rep, new Vertex<>( rep ) );
|
||||
}
|
||||
|
||||
// Connecting neighbourhooding vertices
|
||||
|
@ -47,7 +47,7 @@ public final class GraphTopologicalSort {
|
|||
final List<R> sortedReps = new TopologicalSort<R>().sort( vertices.values() );
|
||||
|
||||
// Transforming the sorted representations to sorted values
|
||||
final List<V> sortedValues = new ArrayList<V>( sortedReps.size() );
|
||||
final List<V> sortedValues = new ArrayList<>( sortedReps.size() );
|
||||
for ( R rep : sortedReps ) {
|
||||
sortedValues.add( definer.getValue( rep ) );
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class TopologicalSort<R> {
|
|||
}
|
||||
|
||||
public List<R> sort(Collection<Vertex<R>> vertices) {
|
||||
sorted = new ArrayList<R>( vertices.size() );
|
||||
sorted = new ArrayList<>( vertices.size() );
|
||||
|
||||
time = 1;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public class Vertex<R> {
|
|||
|
||||
public Vertex(R representation) {
|
||||
this.representation = representation;
|
||||
this.neighbours = new ArrayList<Vertex<R>>();
|
||||
this.neighbours = new ArrayList<>();
|
||||
this.startTime = 0;
|
||||
this.endTime = 0;
|
||||
}
|
||||
|
|
|
@ -58,10 +58,10 @@ public class Parameters {
|
|||
this.connective = connective;
|
||||
this.queryParamCounter = queryParamCounter;
|
||||
|
||||
subParameters = new ArrayList<Parameters>();
|
||||
negatedParameters = new ArrayList<Parameters>();
|
||||
expressions = new ArrayList<String>();
|
||||
localQueryParamValues = new HashMap<String, Object>();
|
||||
subParameters = new ArrayList<>();
|
||||
negatedParameters = new ArrayList<>();
|
||||
expressions = new ArrayList<>();
|
||||
localQueryParamValues = new HashMap<>();
|
||||
}
|
||||
|
||||
// Only for deep copy purpose.
|
||||
|
@ -70,16 +70,16 @@ public class Parameters {
|
|||
this.connective = other.connective;
|
||||
this.queryParamCounter = other.queryParamCounter.deepCopy();
|
||||
|
||||
subParameters = new ArrayList<Parameters>( other.subParameters.size() );
|
||||
subParameters = new ArrayList<>( other.subParameters.size() );
|
||||
for ( Parameters p : other.subParameters ) {
|
||||
subParameters.add( p.deepCopy() );
|
||||
}
|
||||
negatedParameters = new ArrayList<Parameters>( other.negatedParameters.size() );
|
||||
negatedParameters = new ArrayList<>( other.negatedParameters.size() );
|
||||
for ( Parameters p : other.negatedParameters ) {
|
||||
negatedParameters.add( p.deepCopy() );
|
||||
}
|
||||
expressions = new ArrayList<String>( other.expressions );
|
||||
localQueryParamValues = new HashMap<String, Object>( other.localQueryParamValues );
|
||||
expressions = new ArrayList<>( other.expressions );
|
||||
localQueryParamValues = new HashMap<>( other.localQueryParamValues );
|
||||
}
|
||||
|
||||
public Parameters deepCopy() {
|
||||
|
|
|
@ -11,13 +11,13 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.internal.entities.RevisionTypeType;
|
||||
import org.hibernate.envers.internal.tools.MutableInteger;
|
||||
import org.hibernate.envers.internal.tools.StringTools;
|
||||
import org.hibernate.envers.internal.tools.Triple;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.type.CustomType;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ public class QueryBuilder {
|
|||
/**
|
||||
* "where" parameters for this query. Each parameter element of the list for one alias from the "from" part.
|
||||
*/
|
||||
private final List<Parameters> parameters = new ArrayList<Parameters>();
|
||||
private final List<Parameters> parameters = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A list of triples (from entity name, alias name, whether to select the entity).
|
||||
|
@ -73,9 +73,9 @@ public class QueryBuilder {
|
|||
final Parameters rootParameters = new Parameters( alias, "and", paramCounter );
|
||||
parameters.add( rootParameters );
|
||||
|
||||
froms = new ArrayList<Triple<String, String, Boolean>>();
|
||||
orders = new ArrayList<Triple<String, String, Boolean>>();
|
||||
projections = new ArrayList<String>();
|
||||
froms = new ArrayList<>();
|
||||
orders = new ArrayList<>();
|
||||
projections = new ArrayList<>();
|
||||
|
||||
addFrom( entityName, alias, true );
|
||||
}
|
||||
|
@ -90,9 +90,9 @@ public class QueryBuilder {
|
|||
this.parameters.add( params.deepCopy() );
|
||||
}
|
||||
|
||||
froms = new ArrayList<Triple<String, String, Boolean>>( other.froms );
|
||||
orders = new ArrayList<Triple<String, String, Boolean>>( other.orders );
|
||||
projections = new ArrayList<String>( other.projections );
|
||||
froms = new ArrayList<>( other.froms );
|
||||
orders = new ArrayList<>( other.orders );
|
||||
projections = new ArrayList<>( other.projections );
|
||||
}
|
||||
|
||||
public QueryBuilder deepCopy() {
|
||||
|
@ -209,7 +209,7 @@ public class QueryBuilder {
|
|||
}
|
||||
|
||||
private List<String> getSelectAliasList() {
|
||||
final List<String> aliasList = new ArrayList<String>();
|
||||
final List<String> aliasList = new ArrayList<>();
|
||||
for ( Triple<String, String, Boolean> from : froms ) {
|
||||
if ( from.getThird() ) {
|
||||
aliasList.add( from.getSecond() );
|
||||
|
@ -224,7 +224,7 @@ public class QueryBuilder {
|
|||
}
|
||||
|
||||
private List<String> getFromList() {
|
||||
final List<String> fromList = new ArrayList<String>();
|
||||
final List<String> fromList = new ArrayList<>();
|
||||
for ( Triple<String, String, Boolean> from : froms ) {
|
||||
fromList.add( from.getFirst() + " " + from.getSecond() );
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ public class QueryBuilder {
|
|||
}
|
||||
|
||||
private List<String> getOrderList() {
|
||||
final List<String> orderList = new ArrayList<String>();
|
||||
final List<String> orderList = new ArrayList<>();
|
||||
for ( Triple<String, String, Boolean> order : orders ) {
|
||||
orderList.add( order.getFirst() + "." + order.getSecond() + " " + (order.getThird() ? "asc" : "desc") );
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ public class QueryBuilder {
|
|||
|
||||
public Query toQuery(Session session) {
|
||||
final StringBuilder querySb = new StringBuilder();
|
||||
final Map<String, Object> queryParamValues = new HashMap<String, Object>();
|
||||
final Map<String, Object> queryParamValues = new HashMap<>();
|
||||
|
||||
build( querySb, queryParamValues );
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ package org.hibernate.envers.internal.tools.query;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.envers.internal.tools.MutableInteger;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
|
@ -32,7 +32,7 @@ public class UpdateBuilder {
|
|||
this.alias = alias;
|
||||
this.paramCounter = paramCounter;
|
||||
rootParameters = new Parameters( alias, "and", paramCounter );
|
||||
updates = new HashMap<String, Object>();
|
||||
updates = new HashMap<>();
|
||||
}
|
||||
|
||||
public Parameters getRootParameters() {
|
||||
|
@ -68,7 +68,7 @@ public class UpdateBuilder {
|
|||
|
||||
public Query toQuery(Session session) {
|
||||
final StringBuilder querySb = new StringBuilder();
|
||||
final Map<String, Object> queryParamValues = new HashMap<String, Object>();
|
||||
final Map<String, Object> queryParamValues = new HashMap<>();
|
||||
|
||||
build( querySb, queryParamValues );
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public class AuditEntity {
|
|||
* @param propertyName Name of the property.
|
||||
*/
|
||||
public static AuditProperty<Object> property(String propertyName) {
|
||||
return new AuditProperty<Object>( new EntityPropertyName( propertyName ) );
|
||||
return new AuditProperty<>( new EntityPropertyName( propertyName ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ public class AuditEntity {
|
|||
* audited entity.
|
||||
*/
|
||||
public static AuditProperty<Number> revisionNumber() {
|
||||
return new AuditProperty<Number>( new RevisionNumberPropertyName() );
|
||||
return new AuditProperty<>( new RevisionNumberPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@ public class AuditEntity {
|
|||
* @param propertyName Name of the property.
|
||||
*/
|
||||
public static AuditProperty<Object> revisionProperty(String propertyName) {
|
||||
return new AuditProperty<Object>( new RevisionPropertyPropertyName( propertyName ) );
|
||||
return new AuditProperty<>( new RevisionPropertyPropertyName( propertyName ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ public class AuditEntity {
|
|||
* audited entity.
|
||||
*/
|
||||
public static AuditProperty<RevisionType> revisionType() {
|
||||
return new AuditProperty<RevisionType>( new RevisionTypePropertyName() );
|
||||
return new AuditProperty<>( new RevisionTypePropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,10 +30,10 @@ public class AggregatedAuditExpression implements AuditCriterion, ExtendableCrit
|
|||
public AggregatedAuditExpression(PropertyNameGetter propertyNameGetter, AggregatedMode mode) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
this.mode = mode;
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
criterions = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static enum AggregatedMode {
|
||||
public enum AggregatedMode {
|
||||
MAX,
|
||||
MIN
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class AuditConjunction implements AuditCriterion, ExtendableCriterion {
|
|||
private List<AuditCriterion> criterions;
|
||||
|
||||
public AuditConjunction() {
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
criterions = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,7 @@ public class AuditDisjunction implements AuditCriterion, ExtendableCriterion {
|
|||
private List<AuditCriterion> criterions;
|
||||
|
||||
public AuditDisjunction() {
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
criterions = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,5 +11,5 @@ package org.hibernate.envers.query.criteria;
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public interface ExtendableCriterion {
|
||||
public ExtendableCriterion add(AuditCriterion criterion);
|
||||
ExtendableCriterion add(AuditCriterion criterion);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public abstract class CriteriaTools {
|
|||
final SessionFactoryImplementor sessionFactory = versionsReader.getSessionImplementor().getFactory();
|
||||
|
||||
if ( AuditId.IDENTIFIER_PLACEHOLDER.equals( propertyName ) ) {
|
||||
final String identifierPropertyName = sessionFactory.getEntityPersister( entityName ).getIdentifierPropertyName();
|
||||
final String identifierPropertyName = sessionFactory.getMetamodel().entityPersister( entityName ).getIdentifierPropertyName();
|
||||
propertyName = enversService.getAuditEntitiesConfiguration().getOriginalIdPropName() + "." + identifierPropertyName;
|
||||
}
|
||||
else {
|
||||
|
@ -101,12 +101,12 @@ public abstract class CriteriaTools {
|
|||
* @return List of property names representing entity identifier.
|
||||
*/
|
||||
private static List<String> identifierPropertyNames(SessionFactoryImplementor sessionFactory, String entityName) {
|
||||
final String identifierPropertyName = sessionFactory.getEntityPersister( entityName ).getIdentifierPropertyName();
|
||||
final String identifierPropertyName = sessionFactory.getMetamodel().entityPersister( entityName ).getIdentifierPropertyName();
|
||||
if ( identifierPropertyName != null ) {
|
||||
// Single id.
|
||||
return Arrays.asList( identifierPropertyName );
|
||||
}
|
||||
final Type identifierType = sessionFactory.getEntityPersister( entityName ).getIdentifierType();
|
||||
final Type identifierType = sessionFactory.getMetamodel().entityPersister( entityName ).getIdentifierType();
|
||||
if ( identifierType instanceof EmbeddedComponentType ) {
|
||||
// Multiple ids.
|
||||
final EmbeddedComponentType embeddedComponentType = (EmbeddedComponentType) identifierType;
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.NonUniqueResultException;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
|
@ -18,7 +19,6 @@ import org.hibernate.CacheMode;
|
|||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.envers.boot.internal.EnversService;
|
||||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.internal.entities.EntityInstantiator;
|
||||
|
@ -32,6 +32,7 @@ import org.hibernate.envers.query.criteria.internal.CriteriaTools;
|
|||
import org.hibernate.envers.query.order.AuditOrder;
|
||||
import org.hibernate.envers.query.projection.AuditProjection;
|
||||
import org.hibernate.envers.tools.Pair;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REFERENCED_ENTITY_ALIAS;
|
||||
|
||||
|
@ -53,9 +54,9 @@ public abstract class AbstractAuditQuery implements AuditQueryImplementor {
|
|||
protected final EnversService enversService;
|
||||
protected final AuditReaderImplementor versionsReader;
|
||||
|
||||
protected final List<AuditAssociationQueryImpl<?>> associationQueries = new ArrayList<AuditAssociationQueryImpl<?>>();
|
||||
protected final Map<String, AuditAssociationQueryImpl<AuditQueryImplementor>> associationQueryMap = new HashMap<String, AuditAssociationQueryImpl<AuditQueryImplementor>>();
|
||||
protected final List<Pair<String, AuditProjection>> projections = new ArrayList<Pair<String,AuditProjection>>();
|
||||
protected final List<AuditAssociationQueryImpl<?>> associationQueries = new ArrayList<>();
|
||||
protected final Map<String, AuditAssociationQueryImpl<AuditQueryImplementor>> associationQueryMap = new HashMap<>();
|
||||
protected final List<Pair<String, AuditProjection>> projections = new ArrayList<>();
|
||||
|
||||
protected AbstractAuditQuery(
|
||||
EnversService enversService,
|
||||
|
@ -72,7 +73,7 @@ public abstract class AbstractAuditQuery implements AuditQueryImplementor {
|
|||
this.enversService = enversService;
|
||||
this.versionsReader = versionsReader;
|
||||
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
criterions = new ArrayList<>();
|
||||
entityInstantiator = new EntityInstantiator( enversService, versionsReader );
|
||||
|
||||
entityClassName = cls.getName();
|
||||
|
@ -160,7 +161,7 @@ public abstract class AbstractAuditQuery implements AuditQueryImplementor {
|
|||
public AuditAssociationQuery<? extends AuditQuery> traverseRelation(String associationName, JoinType joinType) {
|
||||
AuditAssociationQueryImpl<AuditQueryImplementor> result = associationQueryMap.get( associationName );
|
||||
if (result == null) {
|
||||
result = new AuditAssociationQueryImpl<AuditQueryImplementor>( enversService, versionsReader, this, qb, entityName, associationName, joinType, REFERENCED_ENTITY_ALIAS );
|
||||
result = new AuditAssociationQueryImpl<>( enversService, versionsReader, this, qb, entityName, associationName, joinType, REFERENCED_ENTITY_ALIAS );
|
||||
associationQueries.add( result );
|
||||
associationQueryMap.put( associationName, result );
|
||||
}
|
||||
|
|
|
@ -51,10 +51,10 @@ public class AuditAssociationQueryImpl<Q extends AuditQueryImplementor>
|
|||
private final IdMapper ownerAssociationIdMapper;
|
||||
private final String ownerAlias;
|
||||
private final String alias;
|
||||
private final List<AuditCriterion> criterions = new ArrayList<AuditCriterion>();
|
||||
private final List<AuditCriterion> criterions = new ArrayList<>();
|
||||
private final Parameters parameters;
|
||||
private final List<AuditAssociationQueryImpl<?>> associationQueries = new ArrayList<AuditAssociationQueryImpl<?>>();
|
||||
private final Map<String, AuditAssociationQueryImpl<AuditAssociationQueryImpl<Q>>> associationQueryMap = new HashMap<String, AuditAssociationQueryImpl<AuditAssociationQueryImpl<Q>>>();
|
||||
private final List<AuditAssociationQueryImpl<?>> associationQueries = new ArrayList<>();
|
||||
private final Map<String, AuditAssociationQueryImpl<AuditAssociationQueryImpl<Q>>> associationQueryMap = new HashMap<>();
|
||||
private boolean hasProjections;
|
||||
private boolean hasOrders;
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class AuditAssociationQueryImpl<Q extends AuditQueryImplementor>
|
|||
JoinType joinType) {
|
||||
AuditAssociationQueryImpl<AuditAssociationQueryImpl<Q>> result = associationQueryMap.get( associationName );
|
||||
if ( result == null ) {
|
||||
result = new AuditAssociationQueryImpl<AuditAssociationQueryImpl<Q>>(
|
||||
result = new AuditAssociationQueryImpl<>(
|
||||
enversService,
|
||||
auditReader,
|
||||
this,
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.envers.query.internal.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.boot.internal.EnversService;
|
||||
import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration;
|
||||
|
@ -17,6 +16,7 @@ import org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData;
|
|||
import org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants;
|
||||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.query.criteria.AuditCriterion;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REFERENCED_ENTITY_ALIAS;
|
||||
import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REFERENCED_ENTITY_ALIAS_DEF_AUD_STR;
|
||||
|
@ -120,7 +120,7 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery {
|
|||
|
||||
Query query = buildQuery();
|
||||
// add named parameter (used for ValidityAuditStrategy and association queries)
|
||||
List<String> params = Arrays.asList( query.getNamedParameters() );
|
||||
Collection<String> params = query.getParameterMetadata().getNamedParameterNames();
|
||||
if ( params.contains( REVISION_PARAMETER ) ) {
|
||||
query.setParameter( REVISION_PARAMETER, revision );
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ package org.hibernate.envers.query.internal.impl;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.envers.boot.internal.EnversService;
|
||||
import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration;
|
||||
import org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants;
|
||||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.query.criteria.AuditCriterion;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
/**
|
||||
* In comparison to {@link EntitiesAtRevisionQuery} this query returns an empty collection if an entity
|
||||
|
|
|
@ -19,5 +19,5 @@ public interface PropertyNameGetter {
|
|||
*
|
||||
* @return Name of the property, to be used in a query.
|
||||
*/
|
||||
public String get(EnversService enversService);
|
||||
String get(EnversService enversService);
|
||||
}
|
||||
|
|
|
@ -128,13 +128,13 @@ public class ValidityAuditStrategy implements AuditStrategy {
|
|||
updateTableName = rootAuditedEntityQueryable.getTableName();
|
||||
}
|
||||
|
||||
final Type revisionInfoIdType = sessionImplementor.getFactory().getEntityPersister( revisionInfoEntityName ).getIdentifierType();
|
||||
final Type revisionInfoIdType = sessionImplementor.getFactory().getMetamodel().entityPersister( revisionInfoEntityName ).getIdentifierType();
|
||||
final String revEndColumnName = rootAuditedEntityQueryable.toColumns( enversService.getAuditEntitiesConfiguration().getRevisionEndFieldName() )[0];
|
||||
|
||||
final boolean isRevisionEndTimestampEnabled = enversService.getAuditEntitiesConfiguration().isRevisionEndTimestampEnabled();
|
||||
|
||||
// update audit_ent set REVEND = ? [, REVEND_TSTMP = ?] where (prod_ent_id) = ? and REV <> ? and REVEND is null
|
||||
final Update update = new Update( sessionImplementor.getFactory().getDialect() ).setTableName( updateTableName );
|
||||
final Update update = new Update( sessionImplementor.getFactory().getJdbcServices().getDialect() ).setTableName( updateTableName );
|
||||
// set REVEND = ?
|
||||
update.addColumn( revEndColumnName );
|
||||
// set [, REVEND_TSTMP = ?]
|
||||
|
@ -156,7 +156,7 @@ public class ValidityAuditStrategy implements AuditStrategy {
|
|||
// Now lets execute the sql...
|
||||
final String updateSql = update.toStatementString();
|
||||
|
||||
int rowCount = ( (Session) sessionImplementor ).doReturningWork(
|
||||
int rowCount = sessionImplementor.doReturningWork(
|
||||
new ReturningWork<Integer>() {
|
||||
@Override
|
||||
public Integer execute(Connection connection) throws SQLException {
|
||||
|
@ -206,7 +206,7 @@ public class ValidityAuditStrategy implements AuditStrategy {
|
|||
.getJdbcCoordinator().getResultSetReturn().executeUpdate( preparedStatement );
|
||||
}
|
||||
finally {
|
||||
sessionImplementor.getJdbcCoordinator().getResourceRegistry().release(
|
||||
sessionImplementor.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(
|
||||
preparedStatement
|
||||
);
|
||||
sessionImplementor.getJdbcCoordinator().afterStatementExecution();
|
||||
|
@ -227,7 +227,7 @@ public class ValidityAuditStrategy implements AuditStrategy {
|
|||
}
|
||||
|
||||
private Queryable getQueryable(String entityName, SessionImplementor sessionImplementor) {
|
||||
return (Queryable) sessionImplementor.getFactory().getEntityPersister( entityName );
|
||||
return (Queryable) sessionImplementor.getFactory().getMetamodel().entityPersister( entityName );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -258,7 +258,7 @@ public class ValidityAuditStrategy implements AuditStrategy {
|
|||
}
|
||||
|
||||
final SessionFactoryImplementor sessionFactory = ( (SessionImplementor) session ).getFactory();
|
||||
final Type propertyType = sessionFactory.getEntityPersister( entityName ).getPropertyType( propertyName );
|
||||
final Type propertyType = sessionFactory.getMetamodel().entityPersister( entityName ).getPropertyType( propertyName );
|
||||
if ( propertyType.isCollectionType() ) {
|
||||
CollectionType collectionPropertyType = (CollectionType) propertyType;
|
||||
// Handling collection of components.
|
||||
|
|
|
@ -61,6 +61,6 @@ public class Pair<T1, T2> {
|
|||
}
|
||||
|
||||
public static <T1, T2> Pair<T1, T2> make(T1 obj1, T2 obj2) {
|
||||
return new Pair<T1, T2>( obj1, obj2 );
|
||||
return new Pair<>( obj1, obj2 );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue