diff --git a/PostgresqlExtensionsGrailsPlugin.groovy b/PostgresqlExtensionsGrailsPlugin.groovy index f88c92a..5d20930 100644 --- a/PostgresqlExtensionsGrailsPlugin.groovy +++ b/PostgresqlExtensionsGrailsPlugin.groovy @@ -4,7 +4,7 @@ import net.kaleidos.hibernate.postgresql.criteria.JsonCriterias class PostgresqlExtensionsGrailsPlugin { // the plugin version - def version = "4.2.0" + def version = "4.3.0" // the version or versions of Grails the plugin is designed for def grailsVersion = "2.0 > *" // the other plugins this plugin depends on diff --git a/README.md b/README.md index 77eae21..4313024 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,18 @@ development { If you just only add the dialect, hibernate will create a new sequence for every table to generate the sequential ids instead of a global sequence for all your tables. +You can also deactive this behaviour and create only one sequence for all the tables with the following property in your datasource definition: + +```groovy +development { + dataSource { + ... + postgresql.extensions.sequence_per_table = false + ... + } +} +``` + ## Native Types @@ -514,6 +526,7 @@ Collaborations are appreciated :-) Release Notes ------------- +* 4.3.0 - 17/Aug/2014 - Hibernate 4.x. Fix #49. Configure sequence per table or a global sequence for all tables. * 3.2.0 - 02/Aug/2014 - Hiberate 3.x. PgJsonHasFieldValue criteria. * 4.2.0 - 28/Jul/2014 - Hiberate 4.x. PgJsonHasFieldValue criteria. * 3.1.0 - 25/Jul/2014 - Add JSON support for Hibernate 3.x. It's now possible to store and read domain classes with map types persisted to json. diff --git a/src/java/net/kaleidos/hibernate/PostgresqlExtensionsDialect.java b/src/java/net/kaleidos/hibernate/PostgresqlExtensionsDialect.java index aea299d..bf6ae89 100644 --- a/src/java/net/kaleidos/hibernate/PostgresqlExtensionsDialect.java +++ b/src/java/net/kaleidos/hibernate/PostgresqlExtensionsDialect.java @@ -1,5 +1,6 @@ package net.kaleidos.hibernate; +import grails.util.Holders; import net.kaleidos.hibernate.usertype.ArrayType; import net.kaleidos.hibernate.usertype.HstoreType; import net.kaleidos.hibernate.usertype.JsonMapType; @@ -53,17 +54,22 @@ public static class TableNameSequenceGenerator extends SequenceGenerator { */ @Override public void configure(final Type type, final Properties params, final Dialect dialect) { - if (params.getProperty(SEQUENCE) == null || params.getProperty(SEQUENCE).length() == 0) { - String tableName = params.getProperty(PersistentIdentifierGenerator.TABLE); - String schemaName = params.getProperty("schemaName"); - if (schemaName != null) { - params.setProperty(PersistentIdentifierGenerator.SCHEMA, schemaName); - } - if (tableName != null) { - params.setProperty(SEQUENCE, "seq_" + tableName); + + Boolean sequencePerTable = (Boolean) Holders.getFlatConfig().get("dataSource.postgresql.extensions.sequence_per_table"); + + if ((sequencePerTable == null) || sequencePerTable) { + if (params.getProperty(SEQUENCE) == null || params.getProperty(SEQUENCE).length() == 0) { + String tableName = params.getProperty(PersistentIdentifierGenerator.TABLE); + String schemaName = params.getProperty("schemaName"); + if (schemaName != null) { + params.setProperty(PersistentIdentifierGenerator.SCHEMA, schemaName); + } + if (tableName != null) { + params.setProperty(SEQUENCE, "seq_" + tableName); + } } } super.configure(type, params, dialect); } } -} +} \ No newline at end of file