From 79c8d020c3122955778bb62333505d4d3b65b78a Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 21 Dec 2006 18:06:59 +0000 Subject: [PATCH] Added Entity.postamble, wired it and Entity.name up properly. --- .../com/samskivert/jdbc/depot/DepotMarshaller.java | 13 +++++++++++-- .../samskivert/jdbc/depot/annotation/Entity.java | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java index 645a62a..62e6ce5 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java +++ b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java @@ -38,6 +38,7 @@ import java.util.Set; import java.util.logging.Level; import com.samskivert.jdbc.depot.annotation.Computed; +import com.samskivert.jdbc.depot.annotation.Entity; import com.samskivert.jdbc.depot.annotation.GeneratedValue; import com.samskivert.jdbc.depot.annotation.Id; import com.samskivert.jdbc.depot.annotation.TableGenerator; @@ -76,6 +77,15 @@ public class DepotMarshaller // if not, this class has a corresponding SQL table _tableName = _pclass.getName(); _tableName = _tableName.substring(_tableName.lastIndexOf(".")+1); + + // see if there are Entity values specified + Entity entity = pclass.getAnnotation(Entity.class); + if (entity != null) { + if (entity.name().length() > 0) { + _tableName = entity.name(); + } + _postamble = entity.postamble(); + } } // if the entity defines a new TableGenerator, map that in our static table as those are @@ -211,7 +221,6 @@ public class DepotMarshaller _columnDefinitions = ArrayUtil.append( _columnDefinitions, "PRIMARY KEY (" + StringUtil.join(indices, ", ") + ")"); } - _postamble = ""; // TODO: add annotations for the postamble // if we did not find a schema version field, complain if (_schemaVersion < 0) { @@ -689,7 +698,7 @@ public class DepotMarshaller protected String[] _columnDefinitions; /** Used when creating and migrating our table schema. */ - protected String _postamble; + protected String _postamble = ""; /** The name of the table we use to track schema versions. */ protected static final String SCHEMA_VERSION_TABLE = "DepotSchemaVersion"; diff --git a/src/java/com/samskivert/jdbc/depot/annotation/Entity.java b/src/java/com/samskivert/jdbc/depot/annotation/Entity.java index 93d6758..7530265 100644 --- a/src/java/com/samskivert/jdbc/depot/annotation/Entity.java +++ b/src/java/com/samskivert/jdbc/depot/annotation/Entity.java @@ -34,4 +34,8 @@ public @interface Entity { /** The name of an entity. Defaults to the unqualified name of the entity class. */ String name () default ""; + + /** Additional SQL to be added when creating this entity's table for the first time. You can + * specify additional indices here or supply a MySQL table storage type for example. */ + String postamble () default ""; }