Author: adamw
Date: 2009-11-25 02:45:45 -0500 (Wed, 25 Nov 2009)
New Revision: 18056
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
Log:
HHH-4608:
- options to specify default schema/catalog name for audit tables
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
---
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-11-25
06:06:17 UTC (rev 18055)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-11-25
07:45:45 UTC (rev 18056)
@@ -40,14 +40,11 @@
import org.hibernate.envers.entities.mapper.SubclassPropertyMapper;
import org.hibernate.envers.tools.StringTools;
import org.hibernate.envers.tools.Triple;
+import org.hibernate.envers.AuditTable;
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.Collection;
-import org.hibernate.mapping.Join;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Property;
-import org.hibernate.mapping.Value;
+import org.hibernate.mapping.*;
import org.hibernate.type.*;
/**
@@ -180,6 +177,38 @@
return true;
}
+ private String getSchema(AuditTable auditTable, Table table) {
+ // Get the schema from the annotation ...
+ String schema = auditTable.schema();
+ // ... if empty, try using the default ...
+ if (StringTools.isEmpty(schema)) {
+ schema = globalCfg.getDefaultSchemaName();
+
+ // ... if still empty, use the same as the normal table.
+ if (StringTools.isEmpty(schema)) {
+ schema = table.getSchema();
+ }
+ }
+
+ return schema;
+ }
+
+ private String getCatalog(AuditTable auditTable, Table table) {
+ // Get the catalog from the annotation ...
+ String catalog = auditTable.catalog();
+ // ... if empty, try using the default ...
+ if (StringTools.isEmpty(catalog)) {
+ catalog = globalCfg.getDefaultCatalogName();
+
+ // ... if still empty, use the same as the normal table.
+ if (StringTools.isEmpty(catalog)) {
+ catalog = table.getCatalog();
+ }
+ }
+
+ return catalog;
+ }
+
@SuppressWarnings({"unchecked"})
private void createJoins(PersistentClass pc, Element parent, ClassAuditingData
auditingData) {
Iterator<Join> joins = pc.getJoinIterator();
@@ -203,28 +232,9 @@
auditTableName = verEntCfg.getAuditEntityName(originalTableName);
}
- // Get the schema ...
- String schema = auditingData.getAuditTable().schema();
- // ... if empty, try using the default ...
- if (StringTools.isEmpty(schema)) {
- schema = globalCfg.getDefaultSchemaName();
+ String schema = getSchema(auditingData.getAuditTable(), join.getTable());
+ String catalog = getCatalog(auditingData.getAuditTable(), join.getTable());
- // ... if still empty, use the same as the normal table.
- if (StringTools.isEmpty(schema)) {
- schema = join.getTable().getSchema();
- }
- }
-
- // Same for catalogs
- String catalog = auditingData.getAuditTable().catalog();
- if (StringTools.isEmpty(catalog)) {
- catalog = globalCfg.getDefaultCatalogName();
-
- if (StringTools.isEmpty(catalog)) {
- catalog = join.getTable().getCatalog();
- }
- }
-
Element joinElement = MetadataTools.createJoin(parent, auditTableName,
schema, catalog);
joinElements.put(join, joinElement);
@@ -301,16 +311,9 @@
@SuppressWarnings({"unchecked"})
public void generateFirstPass(PersistentClass pc, ClassAuditingData auditingData,
EntityXmlMappingData xmlMappingData, boolean isAudited)
{
- String schema = auditingData.getAuditTable().schema();
- if (StringTools.isEmpty(schema)) {
- schema = pc.getTable().getSchema();
- }
+ String schema = getSchema(auditingData.getAuditTable(), pc.getTable());
+ String catalog = getCatalog(auditingData.getAuditTable(), pc.getTable());
- String catalog = auditingData.getAuditTable().catalog();
- if (StringTools.isEmpty(catalog)) {
- catalog = pc.getTable().getCatalog();
- }
-
if (!isAudited) {
String entityName = pc.getEntityName();
IdMappingData idMapper = idMetadataGenerator.addId(pc);