|
From: <vga...@us...> - 2010-02-03 14:53:03
|
Revision: 482
http://treebase.svn.sourceforge.net/treebase/?rev=482&view=rev
Author: vgapeyev
Date: 2010-02-03 14:52:56 +0000 (Wed, 03 Feb 2010)
Log Message:
-----------
Changed to a custom ID generator, which relies on the naming convention to translate a table name XXX to the sequence name XXX_id_sequence.
Modified Paths:
--------------
trunk/treebase-core/src/main/java/org/cipres/treebase/domain/AbstractPersistedObject.java
Added Paths:
-----------
trunk/treebase-core/src/main/java/org/cipres/treebase/domain/TB2SequenceGenerator.java
Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/AbstractPersistedObject.java
===================================================================
--- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/AbstractPersistedObject.java 2010-02-02 20:54:48 UTC (rev 481)
+++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/AbstractPersistedObject.java 2010-02-03 14:52:56 UTC (rev 482)
@@ -15,6 +15,7 @@
import org.cipres.treebase.NamespacedGUID;
import org.cipres.treebase.PhyloWSPath;
import org.cipres.treebase.TreebaseIDString;
+import org.hibernate.annotations.GenericGenerator;
/**
* The abstract super class for all persisted domain objects.
@@ -53,8 +54,9 @@
* @see org.cipres.treebase.domain.TBPersistable#getId()
*/
@Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE)
- public Long getId() {
+ @GenericGenerator(name="TB2SEQGEN", strategy = "org.cipres.treebase.domain.TB2SequenceGenerator")
+ @GeneratedValue(generator="TB2SEQGEN")
+ public Long getId() {
return mId;
}
Added: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/TB2SequenceGenerator.java
===================================================================
--- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/TB2SequenceGenerator.java (rev 0)
+++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/TB2SequenceGenerator.java 2010-02-03 14:52:56 UTC (rev 482)
@@ -0,0 +1,34 @@
+package org.cipres.treebase.domain;
+
+import java.util.Properties;
+
+import org.hibernate.MappingException;
+import org.hibernate.type.Type;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.id.PersistentIdentifierGenerator;
+import org.hibernate.id.SequenceGenerator;
+
+
+
+/** Custom id generator that translates table name to the name of an appropriate sequence.
+ * Code taken from https://www.hibernate.org/296.html 2010-02-01, where it was attributed to Mr. Rob Hasselbaum.
+ * Usage is in AbstractPersistedObject.java.
+ * --VG
+ * */
+public class TB2SequenceGenerator extends SequenceGenerator {
+
+ /**
+ * If the parameters do not contain a {@link SequenceGenerator#SEQUENCE} name, we
+ * assign one based on the table name.
+ */
+ public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
+ if(params.getProperty(SEQUENCE) == null || params.getProperty(SEQUENCE).length() == 0) {
+ String tableName = params.getProperty(PersistentIdentifierGenerator.TABLE);
+ if(tableName != null) {
+ String seqName = tableName + "_id_sequence";
+ params.setProperty(SEQUENCE, seqName);
+ }
+ }
+ super.configure(type, params, dialect);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|