Class 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 Detail

      • 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".
      • 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.
      • 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().
      • search

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

        public static String total​(Query<?> query)
      • 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.