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
This commit is contained in:
parent
8855e85040
commit
49f7b49bdc
|
@ -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>
|
||||
|
|
|
@ -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 <operator> (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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,15 +203,27 @@ 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 = 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 = globalCfg.getDefaultCatalogName();
|
||||
|
||||
if (StringTools.isEmpty(catalog)) {
|
||||
catalog = join.getTable().getCatalog();
|
||||
}
|
||||
}
|
||||
|
||||
Element joinElement = MetadataTools.createJoin(parent, auditTableName, schema, catalog);
|
||||
joinElements.put(join, joinElement);
|
||||
|
|
Loading…
Reference in New Issue