Author: adamw
Date: 2008-09-22 05:48:53 -0400 (Mon, 22 Sep 2008)
New Revision: 158
Added:
trunk/src/main/org/jboss/envers/VersionsJoinTable.java
Modified:
trunk/src/main/org/jboss/envers/VersionsTable.java
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java
Log:
ENVERS-26: adding reading of the VersionsJoinTable annotation, restructuring
AnnotationMetadataReader from stateless to stateful
Copied: trunk/src/main/org/jboss/envers/VersionsJoinTable.java (from rev 148,
trunk/src/main/org/jboss/envers/SecondaryVersionsTable.java)
===================================================================
--- trunk/src/main/org/jboss/envers/VersionsJoinTable.java (rev
0)
+++ trunk/src/main/org/jboss/envers/VersionsJoinTable.java 2008-09-22 09:48:53 UTC (rev
158)
@@ -0,0 +1,57 @@
+/*
+ * Envers.
http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers;
+
+import javax.persistence.JoinColumn;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.FIELD, ElementType.METHOD})
+public @interface VersionsJoinTable {
+ /**
+ * @return Name of the join table. Defaults to a concatenation of the names of the
primary table of the entity
+ * owning the association and of the primary table of the entity referenced by the
association.
+ */
+ String name() default "";
+
+ /**
+ * @return The schema of the join table. Defaults to the schema of the entity owning
the association.
+ */
+ String schema() default "";
+
+ /**
+ * @return The catalog of the join table. Defaults to the catalog of the entity
owning the association.
+ */
+ String catalog() default "";
+
+ /**
+ * @return The foreign key columns of the join table which reference the primary
table of the entity owning the
+ * association (i.e. the owning side of the association).
+ */
+ JoinColumn[] joinColumns() default {};
+}
\ No newline at end of file
Property changes on: trunk/src/main/org/jboss/envers/VersionsJoinTable.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/src/main/org/jboss/envers/VersionsTable.java
===================================================================
--- trunk/src/main/org/jboss/envers/VersionsTable.java 2008-09-22 09:12:36 UTC (rev 157)
+++ trunk/src/main/org/jboss/envers/VersionsTable.java 2008-09-22 09:48:53 UTC (rev 158)
@@ -29,19 +29,18 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-@SuppressWarnings({"JavaDoc"})
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface VersionsTable {
String value();
/**
- * The schema of the table. Defaults to the schema of the annotated entity.
+ * @return The schema of the table. Defaults to the schema of the annotated entity.
*/
String schema() default "";
/**
- * The catalog of the table. Defaults to the catalog of the annotated entity.
+ * @return The catalog of the table. Defaults to the catalog of the annotated
entity.
*/
String catalog() default "";
}
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-22
09:12:36 UTC (rev 157)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-22
09:48:53 UTC (rev 158)
@@ -65,12 +65,12 @@
Map<PersistentClass, EntityXmlMappingData> xmlMappings = new
HashMap<PersistentClass, EntityXmlMappingData>();
// First pass
- AnnotationsMetadataReader annotationsMetadataReader = new
AnnotationsMetadataReader();
while (classes.hasNext()) {
PersistentClass pc = classes.next();
// Collecting information from annotations on the persistent class pc
- PersistentClassVersioningData versioningData =
- annotationsMetadataReader.getVersioningData(pc, reflectionManager,
globalCfg);
+ AnnotationsMetadataReader annotationsMetadataReader =
+ new AnnotationsMetadataReader(globalCfg, reflectionManager, pc);
+ PersistentClassVersioningData versioningData =
annotationsMetadataReader.getVersioningData();
if (versioningData.isVersioned()) {
pcDatas.put(pc, versioningData);
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-09-22
09:12:36 UTC (rev 157)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-09-22
09:48:53 UTC (rev 158)
@@ -32,87 +32,126 @@
import org.hibernate.MappingException;
/**
- * A helper class to read versioning meta-data from annotations on persistent classes.
+ * A helper class to read versioning meta-data from annotations on a persistent class.
* @author Adam Warski (adam at warski dot org)
* @author Sebastian Komander
*/
-public class AnnotationsMetadataReader {
- private void addFromProperties(Iterable<YProperty> properties,
PersistentClassVersioningData versioningData,
- GlobalConfiguration globalCfg) {
- for (YProperty property : properties) {
- Versioned ver = property.getAnnotation(Versioned.class);
- if (ver != null) {
- versioningData.propertyStoreInfo.propertyStores.put(property.getName(),
ver.modStore());
- }
+public final class AnnotationsMetadataReader {
+ private final GlobalConfiguration globalCfg;
+ private final YReflectionManager reflectionManager;
+ private final PersistentClass pc;
- // check if a property is declared as unversioned to exclude it
- // useful if a class is versioned but some properties should be excluded
- Unversioned unVer = property.getAnnotation(Unversioned.class);
- if (unVer != null) {
- versioningData.unversionedProperties.add(property.getName());
- } else {
- // if the optimistic locking field has to be unversioned and the current
property
- // is the optimistic locking field, add it to the unversioned properties
list
- if (globalCfg.isUnversionedOptimisticLockingField()) {
- Version jpaVer = property.getAnnotation(Version.class);
- if (jpaVer != null) {
- versioningData.unversionedProperties.add(property.getName());
- }
- }
+ /**
+ * This object is filled with information read from annotations and returned by the
<code>getVersioningData</code>
+ * method.
+ */
+ private final PersistentClassVersioningData versioningData;
+
+ public AnnotationsMetadataReader(GlobalConfiguration globalCfg, YReflectionManager
reflectionManager,
+ PersistentClass pc) {
+ this.globalCfg = globalCfg;
+ this.reflectionManager = reflectionManager;
+ this.pc = pc;
+
+ versioningData = new PersistentClassVersioningData();
+ }
+
+ private void addPropertyVersioned(YProperty property) {
+ Versioned ver = property.getAnnotation(Versioned.class);
+ if (ver != null) {
+ versioningData.propertyStoreInfo.propertyStores.put(property.getName(),
ver.modStore());
+ }
+ }
+
+ private void addPropertyUnversioned(YProperty property) {
+ // check if a property is declared as unversioned to exclude it
+ // useful if a class is versioned but some properties should be excluded
+ Unversioned unVer = property.getAnnotation(Unversioned.class);
+ if (unVer != null) {
+ versioningData.unversionedProperties.add(property.getName());
+ } else {
+ // if the optimistic locking field has to be unversioned and the current
property
+ // is the optimistic locking field, add it to the unversioned properties
list
+ if (globalCfg.isUnversionedOptimisticLockingField()) {
+ Version jpaVer = property.getAnnotation(Version.class);
+ if (jpaVer != null) {
+ versioningData.unversionedProperties.add(property.getName());
+ }
}
}
}
- private void addPropertiesFromClass(YClass clazz, PersistentClassVersioningData
versioningData,
- GlobalConfiguration globalCfg) {
+ private void addPropertyJoinTables(YProperty property) {
+ VersionsJoinTable joinTable = property.getAnnotation(VersionsJoinTable.class);
+ if (joinTable != null) {
+ versioningData.versionsJoinTables.put(property.getName(), joinTable);
+ }
+ }
+
+ private void addFromProperties(Iterable<YProperty> properties) {
+ for (YProperty property : properties) {
+ addPropertyVersioned(property);
+ addPropertyUnversioned(property);
+ addPropertyJoinTables(property);
+ }
+ }
+
+ private void addPropertiesFromClass(YClass clazz) {
YClass superclazz = clazz.getSuperclass();
if (!"java.lang.Object".equals(superclazz.getName())) {
- addPropertiesFromClass(superclazz, versioningData, globalCfg);
+ addPropertiesFromClass(superclazz);
}
- addFromProperties(clazz.getDeclaredProperties("field"), versioningData,
globalCfg);
- addFromProperties(clazz.getDeclaredProperties("property"),
versioningData, globalCfg);
+ addFromProperties(clazz.getDeclaredProperties("field"));
+ addFromProperties(clazz.getDeclaredProperties("property"));
}
- public PersistentClassVersioningData getVersioningData(PersistentClass pc,
YReflectionManager reflectionManager,
- GlobalConfiguration globalCfg) {
- PersistentClassVersioningData versioningData = new
PersistentClassVersioningData();
+ private void addDefaultVersioned(YClass clazz) {
+ Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
+ if (defaultVersioned != null) {
+ versioningData.propertyStoreInfo.defaultStore = defaultVersioned.modStore();
+ }
+ }
+
+ private void addVersionsTable(YClass clazz) {
+ VersionsTable versionsTable = clazz.getAnnotation(VersionsTable.class);
+ if (versionsTable != null) {
+ versioningData.versionsTableName = versionsTable.value();
+ versioningData.schema = versionsTable.schema();
+ versioningData.catalog = versionsTable.catalog();
+ }
+ }
+
+ private void addVersionsSecondaryTables(YClass clazz) {
+ // Getting information on secondary tables
+ SecondaryVersionsTable secondaryVersionsTable1 =
clazz.getAnnotation(SecondaryVersionsTable.class);
+ if (secondaryVersionsTable1 != null) {
+
versioningData.secondaryTableDictionary.put(secondaryVersionsTable1.secondaryTableName(),
+ secondaryVersionsTable1.secondaryVersionsTableName());
+ }
+
+ SecondaryVersionsTables secondaryVersionsTables =
clazz.getAnnotation(SecondaryVersionsTables.class);
+ if (secondaryVersionsTables != null) {
+ for (SecondaryVersionsTable secondaryVersionsTable2 :
secondaryVersionsTables.value()) {
+
versioningData.secondaryTableDictionary.put(secondaryVersionsTable2.secondaryTableName(),
+ secondaryVersionsTable2.secondaryVersionsTableName());
+ }
+ }
+ }
+
+ public PersistentClassVersioningData getVersioningData() {
if (pc.getClassName() == null) {
return versioningData;
}
try {
YClass clazz = reflectionManager.classForName(pc.getClassName(),
this.getClass());
- Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
- if (defaultVersioned != null) {
- versioningData.propertyStoreInfo.defaultStore =
defaultVersioned.modStore();
- }
-
- addPropertiesFromClass(clazz, versioningData, globalCfg);
-
- VersionsTable versionsTable = clazz.getAnnotation(VersionsTable.class);
- if (versionsTable != null) {
- versioningData.versionsTableName = versionsTable.value();
- versioningData.schema = versionsTable.schema();
- versioningData.catalog = versionsTable.catalog();
- }
-
- // Getting information on secondary tables
- SecondaryVersionsTable secondaryVersionsTable1 =
clazz.getAnnotation(SecondaryVersionsTable.class);
- if (secondaryVersionsTable1 != null) {
-
versioningData.secondaryTableDictionary.put(secondaryVersionsTable1.secondaryTableName(),
- secondaryVersionsTable1.secondaryVersionsTableName());
- }
-
- SecondaryVersionsTables secondaryVersionsTables =
clazz.getAnnotation(SecondaryVersionsTables.class);
- if (secondaryVersionsTables != null) {
- for (SecondaryVersionsTable secondaryVersionsTable2 :
secondaryVersionsTables.value()) {
-
versioningData.secondaryTableDictionary.put(secondaryVersionsTable2.secondaryTableName(),
- secondaryVersionsTable2.secondaryVersionsTableName());
- }
- }
+ addDefaultVersioned(clazz);
+ addPropertiesFromClass(clazz);
+ addVersionsTable(clazz);
+ addVersionsSecondaryTables(clazz);
} catch (ClassNotFoundException e) {
throw new MappingException(e);
}
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java 2008-09-22
09:12:36 UTC (rev 157)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java 2008-09-22
09:48:53 UTC (rev 158)
@@ -22,6 +22,7 @@
package org.jboss.envers.configuration.metadata;
import org.jboss.envers.ModificationStore;
+import org.jboss.envers.VersionsJoinTable;
import java.util.HashMap;
import java.util.Map;
@@ -37,6 +38,7 @@
propertyStoreInfo = new PropertyStoreInfo(new HashMap<String,
ModificationStore>());
secondaryTableDictionary = new HashMap<String, String>();
unversionedProperties = new ArrayList<String>();
+ versionsJoinTables = new HashMap<String, VersionsJoinTable>();
}
public PropertyStoreInfo propertyStoreInfo;
@@ -45,6 +47,10 @@
public String catalog;
public Map<String, String> secondaryTableDictionary;
public List<String> unversionedProperties;
+ /**
+ * A map from property names to custom join tables definitions.
+ */
+ public Map<String, VersionsJoinTable> versionsJoinTables;
public boolean isVersioned() {
if (propertyStoreInfo.propertyStores.size() > 0) { return true; }