Package com.exedio.cope
Class SchemaInfo
- java.lang.Object
-
- com.exedio.cope.SchemaInfo
-
public final class SchemaInfo extends Object
Returns information about the database schema accessed by cope - use with care!This information is needed only, if you want to access the database without cope. In this case you should really know, what you are doing. Any INSERT/UPDATE/DELETE on the database bypassing cope may lead to inconsistent caches. Please note, that the results of all methods may vary, if a cope model is configured for different databases. BEWARE: This class is not part of the stable API of cope. It may change its syntax and/or semantics in the future.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
getColumnName(Field<?> field)
Returns the name of database column for the field.static <E extends Enum<E>>
intgetColumnValue(EnumField<E> field, E value)
Deprecated.UsegetColumnValue(Enum)
instead.static int
getColumnValue(Enum<?> value)
Returns the value of database column for the field and the given enum value.static String
getConstraintName(UniqueConstraint constraint)
static String
getDefaultToNextSequenceName(IntegerField field)
Returns the name of the sequence for generating values for thedefaultToNext
mechanism of the field.static String
getForeignKeyConstraintName(ItemField<?> field)
static String
getModificationCounterColumnName(Type<?> type)
Deprecated.UsegetUpdateCounterColumnName(Type)
insteadstatic String
getPrimaryKeyColumnName(Type<?> type)
Returns the name of primary key column in the database for the type.static int
getPrimaryKeyColumnValue(Item item)
Deprecated.UsegetPrimaryKeyColumnValueL(Item)
instead.static long
getPrimaryKeyColumnValueL(Item item)
Returns the value of primary key column in the database for the item.static String
getPrimaryKeySequenceName(Type<?> type)
Returns the name of the sequence for generating values for theprimary key column
of the type.static String
getSequenceName(Sequence sequence)
Returns the name of the sequence for generating values viaSequence.next()
.static String
getTableName(Type<?> type)
Returns the name of database table for the type.static String
getTypeColumnName(ItemField<?> field)
Returns the name of type column in the database for the field.static String
getTypeColumnName(Type<?> type)
Returns the name of type column in the database for the type.static String
getTypeColumnValue(Type<?> type)
Returns the value to be put into a type column for the type.static String
getUpdateCounterColumnName(Type<?> type)
Returns the name of update counter column in the database for the type.static boolean
isConcurrentModificationDetectionEnabled(Model model)
Deprecated.UseisUpdateCounterEnabled(Model)
insteadstatic boolean
isUpdateCounterEnabled(Model model)
Deprecated.always returns truestatic Connection
newConnection(Model model)
Its your responsibility to close the returned connection.static String
quoteName(Model model, String name)
Quotes a database name.static String
search(Query<?> query)
static boolean
supportsCheckConstraints(Model model)
static boolean
supportsNativeDate(Model model)
static boolean
supportsNotNull(Model model)
Deprecated.Always returns true, because all databases are required to support not-null columns.static boolean
supportsSequences(Model model)
Deprecated.Always returns true, because all databases are required to support sequences.static boolean
supportsUniqueViolation(Model model)
Returns whether detectingUniqueViolationException
s fromSQLException
s is supported.static String
total(Query<?> query)
-
-
-
Method Detail
-
newConnection
public static Connection newConnection(Model model) throws SQLException
Its your responsibility to close the returned connection.- Throws:
SQLException
- See Also:
Connection.close()
-
quoteName
public static String quoteName(Model model, String name)
Quotes a database name. This prevents the name from being interpreted as a SQL keyword.
-
supportsCheckConstraints
public static boolean supportsCheckConstraints(Model model)
-
supportsNativeDate
public static boolean supportsNativeDate(Model model)
-
supportsUniqueViolation
public static boolean supportsUniqueViolation(Model model)
Returns whether detectingUniqueViolationException
s fromSQLException
s is supported. If not, then cope must issue explicit searches before any insert/update covering a unique constraint.
-
getTableName
public static String getTableName(Type<?> type)
Returns the name of database table for the type. If not configured otherwise or trimmed to fit into name length restrictions, the name equals theid
of the type.
-
getPrimaryKeyColumnName
public static String getPrimaryKeyColumnName(Type<?> type)
Returns the name of primary key column in the database for the type. If not configured otherwise the name equals "this".
-
getPrimaryKeyColumnValue
@Deprecated public static int getPrimaryKeyColumnValue(Item item)
Deprecated.UsegetPrimaryKeyColumnValueL(Item)
instead.Returns the value of primary key column in the database for the item.
-
getPrimaryKeyColumnValueL
public static long getPrimaryKeyColumnValueL(Item item)
Returns the value of primary key column in the database for the item.
-
getPrimaryKeySequenceName
public static String getPrimaryKeySequenceName(Type<?> type)
Returns the name of the sequence for generating values for theprimary key column
of the type.- Throws:
IllegalArgumentException
- if there is no such sequence for this type, because primary keys are generated otherwise.
-
getTypeColumnName
public static String getTypeColumnName(Type<?> type)
Returns the name of type column in the database for the type. If not configured otherwise the name equals "class". Values suitable for this column can be retrieved bygetTypeColumnValue(Type)
.- Throws:
IllegalArgumentException
- if there is no type column for this type, because
contains one type only.Type.getTypesOfInstances()
-
getTypeColumnValue
public static String getTypeColumnValue(Type<?> type)
Returns the value to be put into a type column for the type. Defaults toType.getID()
, but can be overridden byCopeSchemaName
.
-
getUpdateCounterColumnName
public static String getUpdateCounterColumnName(Type<?> type)
Returns the name of update counter column in the database for the type. If not configured otherwise the name equals "catch".- Throws:
IllegalArgumentException
- if there is no update counter column for this type, because there are no modifiable (non-final
) fields on the type or its subtypes.
-
getColumnName
public static String getColumnName(Field<?> field)
Returns the name of database column for the field. If not configured otherwise or trimmed to fit into name length restrictions, the name equals thename
of the field.
-
getTypeColumnName
public static String getTypeColumnName(ItemField<?> field)
Returns the name of type column in the database for the field. If not configured otherwise or trimmed to fit into name length restrictions, the name equals thename
of the field plus the appendix "Type". Values suitable for this column can be retrieved bygetTypeColumnValue(Type)
.- Throws:
IllegalArgumentException
- if there is no type column for this ItemField, because
contains one type only.getValueType()
.getTypesOfInstances()
-
getColumnValue
public static int getColumnValue(Enum<?> value)
Returns the value of database column for the field and the given enum value. Defaults to 10 * (Enum.ordinal()
+ 1 ), but can be overridden byCopeSchemaValue
.
-
getDefaultToNextSequenceName
public static String getDefaultToNextSequenceName(IntegerField field)
Returns the name of the sequence for generating values for thedefaultToNext
mechanism of the field.- Throws:
IllegalArgumentException
- if there is no such sequence for this field, because values are generated otherwise.
-
getSequenceName
public static String getSequenceName(Sequence sequence)
Returns the name of the sequence for generating values viaSequence.next()
.
-
getConstraintName
public static String getConstraintName(UniqueConstraint constraint)
-
getColumnValue
@Deprecated public static <E extends Enum<E>> int getColumnValue(EnumField<E> field, E value)
Deprecated.UsegetColumnValue(Enum)
instead.
-
isUpdateCounterEnabled
@Deprecated public static boolean isUpdateCounterEnabled(Model model)
Deprecated.always returns true- See Also:
getUpdateCounterColumnName(Type)
-
isConcurrentModificationDetectionEnabled
@Deprecated public static boolean isConcurrentModificationDetectionEnabled(Model model)
Deprecated.UseisUpdateCounterEnabled(Model)
instead
-
getModificationCounterColumnName
@Deprecated public static String getModificationCounterColumnName(Type<?> type)
Deprecated.UsegetUpdateCounterColumnName(Type)
instead
-
supportsSequences
@Deprecated public static boolean supportsSequences(Model model)
Deprecated.Always returns true, because all databases are required to support sequences.- Parameters:
model
- is ignored
-
supportsNotNull
@Deprecated public static boolean supportsNotNull(Model model)
Deprecated.Always returns true, because all databases are required to support not-null columns.
-
-