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 Details

    • newConnection

      public static Connection newConnection(Model model) throws SQLException
      Its your responsibility to close the returned connection.
      Throws:
      SQLException
      See Also:
    • 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 detecting UniqueViolationExceptions from SQLExceptions 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 the id 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.
      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 the primary 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 by getTypeColumnValue(Type).
      Throws:
      IllegalArgumentException - if there is no type column for this type, because Type.getTypesOfInstances() contains one type only.
    • getTypeColumnValue

      public static String getTypeColumnValue(Type<?> type)
      Returns the value to be put into a type column for the type. Defaults to Type.getID(), but can be overridden by CopeSchemaName.
      See Also:
    • 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 the name 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 the name of the field plus the appendix "Type". Values suitable for this column can be retrieved by getTypeColumnValue(Type).
      Throws:
      IllegalArgumentException - if there is no type column for this ItemField, because getValueType().getTypesOfInstances() contains one type only.
    • getForeignKeyConstraintName

      public static String getForeignKeyConstraintName(ItemField<?> field)
    • 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 by CopeSchemaValue.
    • getDefaultToNextSequenceName

      public static String getDefaultToNextSequenceName(IntegerField field)
      Returns the name of the sequence for generating values for the defaultToNext 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 via Sequence.next().
    • getConstraintName

      public static String getConstraintName(UniqueConstraint constraint)
    • search

      public static String search(Query<?> query)
    • total

      public static String total(Query<?> query)
    • getColumnValue

      @Deprecated public static <E extends Enum<E>> int getColumnValue(EnumField<E> field, E value)
      Deprecated.
    • isUpdateCounterEnabled

      @Deprecated public static boolean isUpdateCounterEnabled(Model model)
      Deprecated.
      always returns true
      See Also:
    • isConcurrentModificationDetectionEnabled

      @Deprecated public static boolean isConcurrentModificationDetectionEnabled(Model model)
      Deprecated.
    • getModificationCounterColumnName

      @Deprecated public static String getModificationCounterColumnName(Type<?> type)
      Deprecated.
    • 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.