Removing unused Hiberntae 3.2.4.SP1 integration facilities (ReflectionManager)

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15464 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Adam Warski 2008-10-31 12:23:27 +00:00
parent c1312db934
commit a94515206d
8 changed files with 33 additions and 407 deletions

View File

@ -31,9 +31,10 @@
import org.hibernate.envers.revisioninfo.RevisionInfoNumberReader;
import org.hibernate.envers.revisioninfo.RevisionInfoQueryCreator;
import org.hibernate.envers.synchronization.AuditSyncManager;
import org.hibernate.envers.tools.reflection.YReflectionManager;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.annotations.common.reflection.ReflectionManager;
/**
* @author Adam Warski (adam at warski dot org)
@ -74,7 +75,7 @@ public RevisionInfoNumberReader getRevisionInfoNumberReader() {
public AuditConfiguration(Configuration cfg) {
Properties properties = cfg.getProperties();
YReflectionManager reflectionManager = YReflectionManager.get(cfg);
ReflectionManager reflectionManager = ((AnnotationConfiguration) cfg).getReflectionManager();
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration();
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
verEntCfg = new AuditEntitiesConfiguration(properties, revInfoCfgResult.getRevisionInfoEntityName());

View File

@ -44,9 +44,9 @@
import org.hibernate.envers.entities.EntitiesConfigurations;
import org.hibernate.envers.tools.StringTools;
import org.hibernate.envers.tools.graph.GraphTopologicalSort;
import org.hibernate.envers.tools.reflection.YReflectionManager;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.PersistentClass;
@ -54,7 +54,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class EntitiesConfigurator {
public EntitiesConfigurations configure(Configuration cfg, YReflectionManager reflectionManager,
public EntitiesConfigurations configure(Configuration cfg, ReflectionManager reflectionManager,
GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) {
AuditMetadataGenerator versionsMetaGen = new AuditMetadataGenerator(cfg, globalCfg, verEntCfg,

View File

@ -36,11 +36,11 @@
import org.hibernate.envers.revisioninfo.RevisionInfoNumberReader;
import org.hibernate.envers.revisioninfo.RevisionInfoQueryCreator;
import org.hibernate.envers.tools.MutableBoolean;
import org.hibernate.envers.tools.reflection.YClass;
import org.hibernate.envers.tools.reflection.YProperty;
import org.hibernate.envers.tools.reflection.YReflectionManager;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.PersistentClass;
@ -92,10 +92,10 @@ private Element generateRevisionInfoRelationMapping() {
return rev_rel_mapping;
}
private void searchForRevisionInfoCfgInProperties(YClass clazz, YReflectionManager reflectionManager,
private void searchForRevisionInfoCfgInProperties(XClass clazz, ReflectionManager reflectionManager,
MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound,
String accessType) {
for (YProperty property : clazz.getDeclaredProperties(accessType)) {
for (XProperty property : clazz.getDeclaredProperties(accessType)) {
RevisionNumber revisionNumber = property.getAnnotation(RevisionNumber.class);
RevisionTimestamp revisionTimestamp = property.getAnnotation(RevisionTimestamp.class);
@ -104,7 +104,7 @@ private void searchForRevisionInfoCfgInProperties(YClass clazz, YReflectionManag
throw new MappingException("Only one property may be annotated with @RevisionNumber!");
}
YClass revisionNumberClass = property.getType();
XClass revisionNumberClass = property.getType();
if (reflectionManager.equals(revisionNumberClass, Integer.class) ||
reflectionManager.equals(revisionNumberClass, Integer.TYPE)) {
revisionInfoIdName = property.getName();
@ -127,7 +127,7 @@ private void searchForRevisionInfoCfgInProperties(YClass clazz, YReflectionManag
throw new MappingException("Only one property may be annotated with @RevisionTimestamp!");
}
YClass revisionTimestampClass = property.getType();
XClass revisionTimestampClass = property.getType();
if (reflectionManager.equals(revisionTimestampClass, Long.class) ||
reflectionManager.equals(revisionTimestampClass, Long.TYPE)) {
revisionInfoTimestampName = property.getName();
@ -140,9 +140,9 @@ private void searchForRevisionInfoCfgInProperties(YClass clazz, YReflectionManag
}
}
private void searchForRevisionInfoCfg(YClass clazz, YReflectionManager reflectionManager,
private void searchForRevisionInfoCfg(XClass clazz, ReflectionManager reflectionManager,
MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound) {
YClass superclazz = clazz.getSuperclass();
XClass superclazz = clazz.getSuperclass();
if (!"java.lang.Object".equals(superclazz.getName())) {
searchForRevisionInfoCfg(superclazz, reflectionManager, revisionNumberFound, revisionTimestampFound);
}
@ -154,7 +154,7 @@ private void searchForRevisionInfoCfg(YClass clazz, YReflectionManager reflectio
}
@SuppressWarnings({"unchecked"})
public RevisionInfoConfigurationResult configure(Configuration cfg, YReflectionManager reflectionManager) {
public RevisionInfoConfigurationResult configure(Configuration cfg, ReflectionManager reflectionManager) {
Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
boolean revisionEntityFound = false;
RevisionInfoGenerator revisionInfoGenerator = null;
@ -163,7 +163,7 @@ public RevisionInfoConfigurationResult configure(Configuration cfg, YReflectionM
while (classes.hasNext()) {
PersistentClass pc = classes.next();
YClass clazz;
XClass clazz;
try {
clazz = reflectionManager.classForName(pc.getClassName(), this.getClass());
} catch (ClassNotFoundException e) {

View File

@ -30,11 +30,11 @@
import org.hibernate.envers.SecondaryAuditTable;
import org.hibernate.envers.*;
import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.tools.reflection.YClass;
import org.hibernate.envers.tools.reflection.YProperty;
import org.hibernate.envers.tools.reflection.YReflectionManager;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.mapping.PersistentClass;
/**
@ -44,7 +44,7 @@
*/
public final class AnnotationsMetadataReader {
private final GlobalConfiguration globalCfg;
private final YReflectionManager reflectionManager;
private final ReflectionManager reflectionManager;
private final PersistentClass pc;
/**
@ -53,7 +53,7 @@ public final class AnnotationsMetadataReader {
*/
private final PersistentClassVersioningData versioningData;
public AnnotationsMetadataReader(GlobalConfiguration globalCfg, YReflectionManager reflectionManager,
public AnnotationsMetadataReader(GlobalConfiguration globalCfg, ReflectionManager reflectionManager,
PersistentClass pc) {
this.globalCfg = globalCfg;
this.reflectionManager = reflectionManager;
@ -62,21 +62,21 @@ public AnnotationsMetadataReader(GlobalConfiguration globalCfg, YReflectionManag
versioningData = new PersistentClassVersioningData();
}
private void addPropertyVersioned(YProperty property) {
private void addPropertyVersioned(XProperty property) {
Audited ver = property.getAnnotation(Audited.class);
if (ver != null) {
versioningData.propertyStoreInfo.propertyStores.put(property.getName(), ver.modStore());
}
}
private void addPropertyMapKey(YProperty property) {
private void addPropertyMapKey(XProperty property) {
MapKey mapKey = property.getAnnotation(MapKey.class);
if (mapKey != null) {
versioningData.mapKeys.put(property.getName(), mapKey.name());
}
}
private void addPropertyUnversioned(YProperty property) {
private void addPropertyUnversioned(XProperty property) {
// check if a property is declared as unversioned to exclude it
// useful if a class is versioned but some properties should be excluded
NotAudited unVer = property.getAnnotation(NotAudited.class);
@ -94,15 +94,15 @@ private void addPropertyUnversioned(YProperty property) {
}
}
private void addPropertyJoinTables(YProperty property) {
private void addPropertyJoinTables(XProperty property) {
AuditJoinTable joinTable = property.getAnnotation(AuditJoinTable.class);
if (joinTable != null) {
versioningData.versionsJoinTables.put(property.getName(), joinTable);
}
}
private void addFromProperties(Iterable<YProperty> properties) {
for (YProperty property : properties) {
private void addFromProperties(Iterable<XProperty> properties) {
for (XProperty property : properties) {
addPropertyVersioned(property);
addPropertyUnversioned(property);
addPropertyJoinTables(property);
@ -110,8 +110,8 @@ private void addFromProperties(Iterable<YProperty> properties) {
}
}
private void addPropertiesFromClass(YClass clazz) {
YClass superclazz = clazz.getSuperclass();
private void addPropertiesFromClass(XClass clazz) {
XClass superclazz = clazz.getSuperclass();
if (!"java.lang.Object".equals(superclazz.getName())) {
addPropertiesFromClass(superclazz);
}
@ -120,7 +120,7 @@ private void addPropertiesFromClass(YClass clazz) {
addFromProperties(clazz.getDeclaredProperties("property"));
}
private void addDefaultVersioned(YClass clazz) {
private void addDefaultVersioned(XClass clazz) {
Audited defaultVersioned = clazz.getAnnotation(Audited.class);
if (defaultVersioned != null) {
@ -128,7 +128,7 @@ private void addDefaultVersioned(YClass clazz) {
}
}
private void addVersionsTable(YClass clazz) {
private void addVersionsTable(XClass clazz) {
AuditTable versionsTable = clazz.getAnnotation(AuditTable.class);
if (versionsTable != null) {
versioningData.versionsTable = versionsTable;
@ -137,7 +137,7 @@ private void addVersionsTable(YClass clazz) {
}
}
private void addVersionsSecondaryTables(YClass clazz) {
private void addVersionsSecondaryTables(XClass clazz) {
// Getting information on secondary tables
SecondaryAuditTable secondaryVersionsTable1 = clazz.getAnnotation(SecondaryAuditTable.class);
if (secondaryVersionsTable1 != null) {
@ -160,7 +160,7 @@ public PersistentClassVersioningData getVersioningData() {
}
try {
YClass clazz = reflectionManager.classForName(pc.getClassName(), this.getClass());
XClass clazz = reflectionManager.classForName(pc.getClassName(), this.getClass());
addDefaultVersioned(clazz);
addPropertiesFromClass(clazz);

View File

@ -1,98 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.tools.reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.envers.exception.AuditException;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class YClass {
private final YMethodsAndClasses ymc;
private final Object delegate;
public YClass(YMethodsAndClasses ymc, Object delegate) {
this.ymc = ymc;
this.delegate = delegate;
}
Object getDelegate() {
return delegate;
}
public String getName() {
try {
return (String) ymc.getXClass_getNameMethod().invoke(delegate);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
public YClass getSuperclass() {
try {
return new YClass(ymc, ymc.getXClass_getSuperclassMethod().invoke(delegate));
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
public List<YProperty> getDeclaredProperties(String accessMode) {
List delegates;
try {
delegates = (List) ymc.getXClass_getDeclaredPropertiesMethod().invoke(delegate, accessMode);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
List<YProperty> ret = new ArrayList<YProperty>();
for (Object delegate : delegates) {
ret.add(new YProperty(ymc, delegate));
}
return ret;
}
public <T extends Annotation> T getAnnotation(Class<T> annotation) {
try {
//noinspection unchecked
return (T) ymc.getXClass_getAnnotationMethod().invoke(delegate, annotation);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
}

View File

@ -1,121 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.tools.reflection;
import java.lang.reflect.Method;
import org.hibernate.envers.exception.AuditException;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class YMethodsAndClasses {
private final Method reflectionManager_classForNameMethod;
private final Method reflectionManager_equalsMethod;
private final Method xClass_getNameMethod;
private final Method xClass_getSuperclassMethod;
private final Method xClass_getDeclaredPropertiesMethod;
private final Method xClass_getAnnotationMethod;
private final Method xProperty_getNameMethod;
private final Method xProperty_getAnnotationMethod;
private final Method xProperty_getTypeMethod;
public YMethodsAndClasses(Class<?> delegateClass) throws Exception {
// Initializing classes
ClassLoader cl = YMethodsAndClasses.class.getClassLoader();
Class xClassClass;
try {
xClassClass = cl.loadClass("org.hibernate.annotations.common.reflection.XClass");
} catch (ClassNotFoundException e) {
try {
xClassClass = cl.loadClass("org.hibernate.reflection.XClass");
} catch (ClassNotFoundException e1) {
throw new AuditException("No XClass found.");
}
}
Class xPropertyClass;
try {
xPropertyClass = cl.loadClass("org.hibernate.annotations.common.reflection.XProperty");
} catch (ClassNotFoundException e) {
try {
xPropertyClass = cl.loadClass("org.hibernate.reflection.XProperty");
} catch (ClassNotFoundException e1) {
throw new AuditException("No XProperty found.");
}
}
// Initializing methods
reflectionManager_classForNameMethod = delegateClass.getMethod("classForName", String.class, Class.class);
reflectionManager_equalsMethod = delegateClass.getMethod("equals", xClassClass, Class.class);
xClass_getNameMethod = xClassClass.getMethod("getName");
xClass_getSuperclassMethod = xClassClass.getMethod("getSuperclass");
xClass_getDeclaredPropertiesMethod = xClassClass.getMethod("getDeclaredProperties", String.class);
xClass_getAnnotationMethod = xClassClass.getMethod("getAnnotation", Class.class);
xProperty_getNameMethod = xPropertyClass.getMethod("getName");
xProperty_getTypeMethod = xPropertyClass.getMethod("getType");
xProperty_getAnnotationMethod = xPropertyClass.getMethod("getAnnotation", Class.class);
}
public Method getXClass_getNameMethod() {
return xClass_getNameMethod;
}
public Method getXClass_getSuperclassMethod() {
return xClass_getSuperclassMethod;
}
public Method getXClass_getDeclaredPropertiesMethod() {
return xClass_getDeclaredPropertiesMethod;
}
public Method getXClass_getAnnotationMethod() {
return xClass_getAnnotationMethod;
}
public Method getXProperty_getNameMethod() {
return xProperty_getNameMethod;
}
public Method getXProperty_getAnnotationMethod() {
return xProperty_getAnnotationMethod;
}
public Method getXProperty_getTypeMethod() {
return xProperty_getTypeMethod;
}
public Method getReflectionManager_classForNameMethod() {
return reflectionManager_classForNameMethod;
}
public Method getReflectionManager_equalsMethod() {
return reflectionManager_equalsMethod;
}
}

View File

@ -1,73 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.tools.reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import org.hibernate.envers.exception.AuditException;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class YProperty {
private final YMethodsAndClasses ymc;
private final Object delegate;
public YProperty(YMethodsAndClasses ymc, Object delegate) {
this.ymc = ymc;
this.delegate = delegate;
}
public String getName() {
try {
return (String) ymc.getXProperty_getNameMethod().invoke(delegate);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
public <T extends Annotation> T getAnnotation(Class<T> annotation) {
try {
//noinspection unchecked
return (T) ymc.getXProperty_getAnnotationMethod().invoke(delegate, annotation);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
public YClass getType() {
try {
return new YClass(ymc, ymc.getXProperty_getTypeMethod().invoke(delegate));
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
}

View File

@ -1,83 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.tools.reflection;
import java.lang.reflect.InvocationTargetException;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
/**
* A reflection manager which proxies either to the old classes from package org.hibernate.reflection,
* or to the new classed from package org.hibernate.annotations.common.reflection.
* @author Adam Warski (adam at warski dot org)
*/
public class YReflectionManager {
private final Object delegate;
private final YMethodsAndClasses ymc;
public YReflectionManager(Configuration cfg) throws Exception {
Object delegateTemp;
try {
delegateTemp = cfg.getClass().getMethod("getReflectionManager").invoke(cfg);
} catch (NoSuchMethodException e) {
// TODO - what if there it's a pure Hibernate envirionment?
delegateTemp = ReflectionTools
.loadClass("org.hibernate.cfg.annotations.reflection.EJB3ReflectionManager")
.newInstance();
}
delegate = delegateTemp;
ymc = new YMethodsAndClasses(delegate.getClass());
}
public YClass classForName(String className, Class<?> caller) throws ClassNotFoundException {
try {
return new YClass(ymc, ymc.getReflectionManager_classForNameMethod().invoke(delegate, className, caller));
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
public <T> boolean equals(YClass class1, java.lang.Class<T> class2) {
try {
return (Boolean) ymc.getReflectionManager_equalsMethod().invoke(delegate, class1.getDelegate(), class2);
} catch (IllegalAccessException e) {
throw new AuditException(e);
} catch (InvocationTargetException e) {
throw new AuditException(e);
}
}
public static YReflectionManager get(Configuration cfg) {
try {
return new YReflectionManager(cfg);
} catch (Exception e) {
throw new MappingException(e);
}
}
}