From 49f7b49bdc367cc08075f47847179a6071295bb0 Mon Sep 17 00:00:00 2001 From: Adam Warski Date: Tue, 24 Nov 2009 16:19:58 +0000 Subject: [PATCH] HHH-4608: - options to specify default schema/catalog name for audit tables git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18035 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../docbook/en-US/content/configuration.xml | 26 +++++++++++++++++++ .../configuration/GlobalConfiguration.java | 17 ++++++++++++ .../metadata/AuditMetadataGenerator.java | 16 ++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/documentation/envers/src/main/docbook/en-US/content/configuration.xml b/documentation/envers/src/main/docbook/en-US/content/configuration.xml index e3030d6e8e..cd2186290d 100644 --- a/documentation/envers/src/main/docbook/en-US/content/configuration.xml +++ b/documentation/envers/src/main/docbook/en-US/content/configuration.xml @@ -148,6 +148,32 @@ stored twice). + + + org.hibernate.envers.defaultAuditTableSchemaName + + + null (same as normal tables) + + + The default schema name that should be used for audit tables. Can be overriden using the + @AuditTable(schema="...") annotation. If not present, the schema will + be the same as the schema of the normal tables. + + + + + org.hibernate.envers.defaultAuditTableCatalogName + + + null (same as normal tables) + + + The default catalog name that should be used for audit tables. Can be overriden using the + @AuditTable(catalog="...") annotation. If not present, the catalog will + be the same as the catalog of the normal tables. + + diff --git a/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java b/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java index 002021ea88..2560b67173 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java @@ -39,6 +39,12 @@ public class GlobalConfiguration { // 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 (select max(e2.p) where e2.p2 = e.p2 ...). @@ -59,6 +65,9 @@ public class GlobalConfiguration { 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 class GlobalConfiguration { public boolean isStoreDataAtDelete() { return storeDataAtDelete; } + + public String getDefaultSchemaName() { + return defaultSchemaName; + } + + public String getDefaultCatalogName() { + return defaultCatalogName; + } } diff --git a/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java b/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java index 4474b35082..b35c94b649 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java @@ -203,14 +203,26 @@ public final class AuditMetadataGenerator { 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);