Switched to our own set of annotation classes, provided by Zell. This removes
the dependency on the EJB3 persistence library.
This commit is contained in:
@@ -37,10 +37,11 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.TableGenerator;
|
||||
import javax.persistence.Transient;
|
||||
import com.samskivert.jdbc.depot.annotation.Computed;
|
||||
import com.samskivert.jdbc.depot.annotation.GeneratedValue;
|
||||
import com.samskivert.jdbc.depot.annotation.Id;
|
||||
import com.samskivert.jdbc.depot.annotation.TableGenerator;
|
||||
import com.samskivert.jdbc.depot.annotation.Transient;
|
||||
|
||||
import com.samskivert.jdbc.JDBCUtil;
|
||||
import com.samskivert.jdbc.depot.clause.Where;
|
||||
|
||||
@@ -31,10 +31,11 @@ import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import com.samskivert.jdbc.depot.annotation.Column;
|
||||
import com.samskivert.jdbc.depot.annotation.Computed;
|
||||
import com.samskivert.jdbc.depot.annotation.GeneratedValue;
|
||||
import com.samskivert.jdbc.depot.annotation.GenerationType;
|
||||
import com.samskivert.jdbc.depot.annotation.Id;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.samskivert.jdbc.depot;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.persistence.TableGenerator;
|
||||
import com.samskivert.jdbc.depot.annotation.TableGenerator;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.samskivert.io.PersistenceException;
|
||||
import com.samskivert.jdbc.depot.annotation.Computed;
|
||||
import com.samskivert.jdbc.depot.clause.FieldOverride;
|
||||
import com.samskivert.jdbc.depot.clause.ForUpdate;
|
||||
import com.samskivert.jdbc.depot.clause.FromOverride;
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.persistence.TableGenerator;
|
||||
import com.samskivert.jdbc.depot.annotation.TableGenerator;
|
||||
|
||||
import com.samskivert.jdbc.JDBCUtil;
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2006 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;
|
||||
|
||||
/**
|
||||
* Is used to specify a mapped column for a persistent property or field. If no Column annotation
|
||||
* is specified, the default values are applied.
|
||||
*/
|
||||
@Target(value=ElementType.FIELD)
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
public @interface Column
|
||||
{
|
||||
/**
|
||||
* The name of the column. Defaults to the field name.
|
||||
*/
|
||||
String name () default "";
|
||||
|
||||
/**
|
||||
* Whether the property is a unique key. This is a shortcut for the UniqueConstraint annotation
|
||||
* at the table level and is useful for when the unique key constraint is only a single
|
||||
* field. This constraint applies in addition to any constraint entailed by primary key mapping
|
||||
* and to constraints specified at the table level.
|
||||
*/
|
||||
boolean unique () default false;
|
||||
|
||||
/**
|
||||
* Whether the database column is nullable. <em>Note:</em> this default differs from the value
|
||||
* used by the EJB3 persistence framework.
|
||||
*/
|
||||
boolean nullable () default false;
|
||||
|
||||
/**
|
||||
* The SQL fragment that is used when generating the DDL for the column. Defaults to the
|
||||
* generated SQL to create a column of the inferred type.
|
||||
*/
|
||||
String columnDefinition () default "";
|
||||
|
||||
/**
|
||||
* The column length. (Applies to String and byte[] columns.)
|
||||
*/
|
||||
int length () default 255;
|
||||
}
|
||||
+8
-6
@@ -18,24 +18,26 @@
|
||||
// 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;
|
||||
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;
|
||||
|
||||
import com.samskivert.jdbc.depot.Query;
|
||||
|
||||
/**
|
||||
* Marks a field as computed, meaning it's ignored for schema purposes, it does not directly
|
||||
* correspond to a column in a table, and thus its value must be overridden in the {@link Query}.
|
||||
* Marks a field as computed, meaning it is ignored for schema purposes and it does not directly
|
||||
* correspond to a column in a table, thus its value must be overridden in the {@link Query}.
|
||||
*/
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.FIELD, ElementType.TYPE })
|
||||
public @interface Computed
|
||||
{
|
||||
/** If this value is false, the field is not populated by Depot at all. */
|
||||
boolean required() default true;
|
||||
/** If this value is false, the field is not populated at all. */
|
||||
boolean required () default true;
|
||||
|
||||
/** A non-empty value here is taken as literal SQL and used to populate the computed field. */
|
||||
String fieldDefinition() default "";
|
||||
String fieldDefinition () default "";
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2006 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;
|
||||
|
||||
/**
|
||||
* Specifies the primary field(s) of an entity.
|
||||
*/
|
||||
@Target(value=ElementType.TYPE)
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
public @interface Entity
|
||||
{
|
||||
/** The name of an entity. Defaults to the unqualified name of the entity class. */
|
||||
String name () default "";
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2006 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;
|
||||
|
||||
/**
|
||||
* Provides for the specification of generation strategies for the values of primary keys. The
|
||||
* GeneratedValue annotation may be applied to a primary field in conjunction with the {@link Id}
|
||||
* annotation.
|
||||
*/
|
||||
@Target(value=ElementType.FIELD)
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
public @interface GeneratedValue
|
||||
{
|
||||
/** Identifies which generator should be used to generate this value when using a table or
|
||||
* sequence generator. */
|
||||
String generator () default "";
|
||||
|
||||
/** Identifies the strategy to be used to generate this value. */
|
||||
GenerationType strategy () default GenerationType.AUTO;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2006 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;
|
||||
|
||||
/**
|
||||
* Defines the types of primary key generation.
|
||||
*/
|
||||
public enum GenerationType
|
||||
{
|
||||
/**
|
||||
* Indicates that the persistence provider must assign primary keys for the entity using an
|
||||
* underlying database table to ensure uniqueness.
|
||||
*/
|
||||
TABLE,
|
||||
|
||||
/**
|
||||
* Indicates that the persistence provider must assign primary keys for the entity using
|
||||
* database sequences.
|
||||
*/
|
||||
SEQUENCE,
|
||||
|
||||
/**
|
||||
* Indicates that the persistence provider must assign primary keys for the entity using
|
||||
* database identity column.
|
||||
*/
|
||||
IDENTITY,
|
||||
|
||||
/**
|
||||
* Indicates that the persistence provider should pick an appropriate strategy for the
|
||||
* particular database.
|
||||
*/
|
||||
AUTO;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2006 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;
|
||||
|
||||
/**
|
||||
* Specifies the primary key property or field of an entity.
|
||||
*/
|
||||
@Target(value=ElementType.FIELD)
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
public @interface Id
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2006 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 {};
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2006 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 defines a primary key generator that may be referenced by name when a generator
|
||||
* element is specified for the GeneratedValue annotation. A table generator may be specified on
|
||||
* the entity class or on the primary key field. The scope of the generator name is global to the
|
||||
* persistence unit (across all generator types).
|
||||
*/
|
||||
@Target(value={ElementType.TYPE, ElementType.FIELD})
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
public @interface TableGenerator
|
||||
{
|
||||
/**
|
||||
* A unique generator name that can be referenced by one or more classes to be the
|
||||
* generator for id values.
|
||||
*/
|
||||
String name ();
|
||||
|
||||
/**
|
||||
* Name of table that stores the generated id values. Defaults to a name chosen by persistence
|
||||
* provider.
|
||||
*/
|
||||
String table () default "";
|
||||
|
||||
/**
|
||||
* Name of the primary key column in the table Defaults to a provider-chosen name.
|
||||
*/
|
||||
String pkColumnName () default "";
|
||||
|
||||
/**
|
||||
* Name of the column that stores the last value generated Defaults to a provider-chosen name.
|
||||
*/
|
||||
String valueColumnName () default "";
|
||||
|
||||
/**
|
||||
* The primary key value in the generator table that distinguishes this set of generated values
|
||||
* from others that may be stored in the table Defaults to a provider-chosen value to store in
|
||||
* the primary key column of the generator table
|
||||
*/
|
||||
String pkColumnValue () default "";
|
||||
|
||||
/**
|
||||
* The initial value to be used when allocating id numbers from the generator. The default
|
||||
* initial value is 1. <em>Note:</em> this default differs from the value used by the EJB3
|
||||
* persistence framework.
|
||||
*/
|
||||
int initialValue () default 1;
|
||||
|
||||
/**
|
||||
* The amount to increment by when allocating id numbers from the generator. The default
|
||||
* allocation size is 1. <em>Note:</em> this default differs from the value used by the EJB3
|
||||
* persistence framework.
|
||||
*/
|
||||
int allocationSize () default 1;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2006 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 that the property or field is not persistent. It is used to annotate
|
||||
* a property or field of an entity class, mapped superclass, or embeddable class.
|
||||
*/
|
||||
@Target(value=ElementType.FIELD)
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
public @interface Transient
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2006 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.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to specify that a unique constraint is to be included in the
|
||||
* generated DDL for a table.
|
||||
*/
|
||||
@Target(value={})
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
public @interface UniqueConstraint
|
||||
{
|
||||
/**
|
||||
* An array of the column names that make up the constraint
|
||||
*/
|
||||
public String[] columnNames () default {};
|
||||
}
|
||||
Reference in New Issue
Block a user