From 3f2615803147826049965f72acea8622f1a80e25 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 1 Apr 2008 21:27:20 +0000 Subject: [PATCH] Nix @Table, move its fields into @Entity. --- .../jdbc/depot/DepotMarshaller.java | 28 +++++------ .../jdbc/depot/annotation/Entity.java | 12 ++++- .../jdbc/depot/annotation/Table.java | 48 ------------------- 3 files changed, 22 insertions(+), 66 deletions(-) delete mode 100644 src/java/com/samskivert/jdbc/depot/annotation/Table.java diff --git a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java index 356ee50..fcde2b2 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java +++ b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java @@ -44,7 +44,6 @@ import com.samskivert.jdbc.depot.annotation.FullTextIndex; import com.samskivert.jdbc.depot.annotation.GeneratedValue; import com.samskivert.jdbc.depot.annotation.Id; import com.samskivert.jdbc.depot.annotation.Index; -import com.samskivert.jdbc.depot.annotation.Table; import com.samskivert.jdbc.depot.annotation.TableGenerator; import com.samskivert.jdbc.depot.annotation.Transient; import com.samskivert.jdbc.depot.annotation.UniqueConstraint; @@ -183,12 +182,12 @@ public class DepotMarshaller // generate our full list of fields/columns for use in queries _allFields = fields.toArray(new String[fields.size()]); - // now check for @Entity and @Table annotations on the entire superclass chain + // now check for @Entity annotations on the entire superclass chain Class iterClass = pClass; do { - Table table = iterClass.getAnnotation(Table.class); - if (table != null) { - for (UniqueConstraint constraint : table.uniqueConstraints()) { + entity = iterClass.getAnnotation(Entity.class); + if (entity != null) { + for (UniqueConstraint constraint : entity.uniqueConstraints()) { String[] conFields = constraint.fieldNames(); Set colSet = new HashSet(); for (int ii = 0; ii < conFields.length; ii ++) { @@ -202,23 +201,20 @@ public class DepotMarshaller _uniqueConstraints.add(colSet); } - // if there are FTS indexes in the Table, map those out here for future use - for (FullTextIndex fti : table.fullTextIndexes()) { - if (_fullTextIndexes.containsKey(fti.name())) { - continue; - } - _fullTextIndexes.put(fti.name(), fti); - } - } - - entity = iterClass.getAnnotation(Entity.class); - if (entity != null) { for (Index index : entity.indices()) { if (_indexes.containsKey(index.name())) { continue; } _indexes.put(index.name(), index); } + + // if there are FTS indexes in the Table, map those out here for future use + for (FullTextIndex fti : entity.fullTextIndexes()) { + if (_fullTextIndexes.containsKey(fti.name())) { + continue; + } + _fullTextIndexes.put(fti.name(), fti); + } } iterClass = iterClass.getSuperclass(); diff --git a/src/java/com/samskivert/jdbc/depot/annotation/Entity.java b/src/java/com/samskivert/jdbc/depot/annotation/Entity.java index 1efc315..842b644 100644 --- a/src/java/com/samskivert/jdbc/depot/annotation/Entity.java +++ b/src/java/com/samskivert/jdbc/depot/annotation/Entity.java @@ -3,7 +3,7 @@ // // samskivert library - useful routines for java programs // Copyright (C) 2006-2007 Michael Bayne, Pär Winzell -// +// // This library is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License as published // by the Free Software Foundation; either version 2.1 of the License, or @@ -35,6 +35,14 @@ public @interface Entity /** The name of an entity. Defaults to the unqualified name of the entity class. */ String name () default ""; - /** Defines indices to add to this entity's table. */ + /** Unique constraints that are to be placed on this entity's table. These constraints apply in + * addition to any constraints specified by the Column annotation and constraints entailed by + * primary key mappings. Defaults to no additional constraints. */ + UniqueConstraint[] uniqueConstraints () default {}; + + /** Indices to add to this entity's table. */ Index[] indices () default {}; + + /** Full-text search indexes defined on this entity, if any. Defaults to none. */ + FullTextIndex[] fullTextIndexes () default {}; } diff --git a/src/java/com/samskivert/jdbc/depot/annotation/Table.java b/src/java/com/samskivert/jdbc/depot/annotation/Table.java deleted file mode 100644 index b74bb6c..0000000 --- a/src/java/com/samskivert/jdbc/depot/annotation/Table.java +++ /dev/null @@ -1,48 +0,0 @@ -// -// $Id$ -// -// samskivert library - useful routines for java programs -// Copyright (C) 2006-2007 Michael Bayne, Pär Winzell -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.samskivert.jdbc.depot.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation specifies the primary table for the annotated entity. If no Table - * annotation is specified for an entity class, the default values apply. - */ -@Target(value=ElementType.TYPE) -@Retention(value=RetentionPolicy.RUNTIME) -public @interface Table -{ - /** - * Unique constraints that are to be placed on the table. - * These constraints apply in addition to any constraints specified by the Column - * annotation and constraints entailed by primary key mappings. - * Defaults to no additional constraints. - */ - public UniqueConstraint[] uniqueConstraints () default {}; - - /** - * Full-text search indexes defined on this entity, if any. Defaults to none. - */ - public FullTextIndex[] fullTextIndexes () default {}; -}