[hibernate-commits] Hibernate SVN: r18035 - in core/trunk: envers/src/main/java/org/hibernate/envers/configuration and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Nov 24 11:19:59 EST 2009


Author: adamw
Date: 2009-11-24 11:19:58 -0500 (Tue, 24 Nov 2009)
New Revision: 18035

Modified:
   core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml
   core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
   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/documentation/envers/src/main/docbook/en-US/content/configuration.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml	2009-11-24 16:12:57 UTC (rev 18034)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml	2009-11-24 16:19:58 UTC (rev 18035)
@@ -148,6 +148,32 @@
                         stored twice).
                     </entry>
                 </row>
+                <row>
+                    <entry>
+                        <property>org.hibernate.envers.defaultAuditTableSchemaName</property>
+                    </entry>
+                    <entry>
+                        null (same as normal tables)
+                    </entry>
+                    <entry>
+                        The default schema name that should be used for audit tables. Can be overriden using the
+                        <literal>@AuditTable(schema="...")</literal> annotation. If not present, the schema will
+                        be the same as the schema of the normal tables.
+                    </entry>
+                </row>
+                <row>
+                    <entry>
+                        <property>org.hibernate.envers.defaultAuditTableCatalogName</property>
+                    </entry>
+                    <entry>
+                        null (same as normal tables)
+                    </entry>
+                    <entry>
+                        The default catalog name that should be used for audit tables. Can be overriden using the
+                        <literal>@AuditTable(catalog="...")</literal> annotation. If not present, the catalog will
+                        be the same as the catalog of the normal tables.                        
+                    </entry>
+                </row>
             </tbody>
         </tgroup>
     </table>

Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java	2009-11-24 16:12:57 UTC (rev 18034)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java	2009-11-24 16:19:58 UTC (rev 18035)
@@ -39,6 +39,12 @@
 	// Should entity data be stored when it is deleted
 	private final boolean storeDataAtDelete;
 
+    // The default name of the schema of audit tables.
+    private final String defaultSchemaName;
+
+    // The default name of the catalog of the audit tables.
+    private final String defaultCatalogName;
+
     /*
      Which operator to use in correlated subqueries (when we want a property to be equal to the result of
      a correlated subquery, for example: e.p <operator> (select max(e2.p) where e2.p2 = e.p2 ...).
@@ -59,6 +65,9 @@
 		String storeDataDeletedEntityStr = properties.getProperty("org.hibernate.envers.storeDataAtDelete", "false");
 		storeDataAtDelete = Boolean.parseBoolean(storeDataDeletedEntityStr);
 
+        defaultSchemaName = properties.getProperty("org.hibernate.envers.defaultAuditTableSchemaName", null);
+        defaultCatalogName = properties.getProperty("org.hibernate.envers.defaultAuditTableCatalogName", null);
+
         correlatedSubqueryOperator = "org.hibernate.dialect.HSQLDialect".equals(
                 properties.getProperty("hibernate.dialect")) ? "in" : "=";
     }
@@ -78,4 +87,12 @@
 	public boolean isStoreDataAtDelete() {
 		return storeDataAtDelete;
 	}
+
+    public String getDefaultSchemaName() {
+        return defaultSchemaName;
+    }
+
+    public String getDefaultCatalogName() {
+        return defaultCatalogName;
+    }
 }

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-24 16:12:57 UTC (rev 18034)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java	2009-11-24 16:19:58 UTC (rev 18035)
@@ -203,14 +203,26 @@
                 auditTableName = verEntCfg.getAuditEntityName(originalTableName);
             }
 
+            // Get the schema ...
             String schema = auditingData.getAuditTable().schema();
+            // ... if empty, try using the default ...
             if (StringTools.isEmpty(schema)) {
-                schema = join.getTable().getSchema();
+                schema = globalCfg.getDefaultSchemaName();
+
+                // ... 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 = join.getTable().getCatalog();
+                catalog = globalCfg.getDefaultCatalogName();
+
+                if (StringTools.isEmpty(catalog)) {
+                    catalog = join.getTable().getCatalog();
+                }
             }
 
             Element joinElement = MetadataTools.createJoin(parent, auditTableName, schema, catalog);



More information about the hibernate-commits mailing list