Nix @Table, move its fields into @Entity.
This commit is contained in:
@@ -44,7 +44,6 @@ import com.samskivert.jdbc.depot.annotation.FullTextIndex;
|
|||||||
import com.samskivert.jdbc.depot.annotation.GeneratedValue;
|
import com.samskivert.jdbc.depot.annotation.GeneratedValue;
|
||||||
import com.samskivert.jdbc.depot.annotation.Id;
|
import com.samskivert.jdbc.depot.annotation.Id;
|
||||||
import com.samskivert.jdbc.depot.annotation.Index;
|
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.TableGenerator;
|
||||||
import com.samskivert.jdbc.depot.annotation.Transient;
|
import com.samskivert.jdbc.depot.annotation.Transient;
|
||||||
import com.samskivert.jdbc.depot.annotation.UniqueConstraint;
|
import com.samskivert.jdbc.depot.annotation.UniqueConstraint;
|
||||||
@@ -183,12 +182,12 @@ public class DepotMarshaller<T extends PersistentRecord>
|
|||||||
// generate our full list of fields/columns for use in queries
|
// generate our full list of fields/columns for use in queries
|
||||||
_allFields = fields.toArray(new String[fields.size()]);
|
_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;
|
Class<?> iterClass = pClass;
|
||||||
do {
|
do {
|
||||||
Table table = iterClass.getAnnotation(Table.class);
|
entity = iterClass.getAnnotation(Entity.class);
|
||||||
if (table != null) {
|
if (entity != null) {
|
||||||
for (UniqueConstraint constraint : table.uniqueConstraints()) {
|
for (UniqueConstraint constraint : entity.uniqueConstraints()) {
|
||||||
String[] conFields = constraint.fieldNames();
|
String[] conFields = constraint.fieldNames();
|
||||||
Set<String> colSet = new HashSet<String>();
|
Set<String> colSet = new HashSet<String>();
|
||||||
for (int ii = 0; ii < conFields.length; ii ++) {
|
for (int ii = 0; ii < conFields.length; ii ++) {
|
||||||
@@ -202,23 +201,20 @@ public class DepotMarshaller<T extends PersistentRecord>
|
|||||||
_uniqueConstraints.add(colSet);
|
_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()) {
|
for (Index index : entity.indices()) {
|
||||||
if (_indexes.containsKey(index.name())) {
|
if (_indexes.containsKey(index.name())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_indexes.put(index.name(), index);
|
_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();
|
iterClass = iterClass.getSuperclass();
|
||||||
|
|||||||
@@ -35,6 +35,14 @@ public @interface Entity
|
|||||||
/** The name of an entity. Defaults to the unqualified name of the entity class. */
|
/** The name of an entity. Defaults to the unqualified name of the entity class. */
|
||||||
String name () default "";
|
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 {};
|
Index[] indices () default {};
|
||||||
|
|
||||||
|
/** Full-text search indexes defined on this entity, if any. Defaults to none. */
|
||||||
|
FullTextIndex[] fullTextIndexes () default {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {};
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user