Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PostgresqlExtensionsGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
24 changes: 15 additions & 9 deletions src/java/net/kaleidos/hibernate/PostgresqlExtensionsDialect.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}