モジュール org.nkjmlab.sorm4j

クラス TableDefinition


  • public final class TableDefinition
    extends Object
    This class represent a table schema. This class is a utility for users to define tables and indexes. It should be noted that there is no guarantee that this object will match the table definition in the database.
    作成者:
    nkjm
    • メソッドの詳細

      • toUpperSnakeCase

        public static String toUpperSnakeCase​(String compoundName)
        Given a field or class name in the form CompoundName (for classes) or compoundName (for fields) will return a set of guessed names such as [COMPOUND_NAME].
      • getColumnNames

        public List<String> getColumnNames()
      • getCreateIndexIfNotExistsStatements

        public List<String> getCreateIndexIfNotExistsStatements()
        Gets create index if not exists statements. Example.
         TableDefinition.builder("reports") .addColumnDefinition("id", VARCHAR,
         PRIMARY_KEY).addColumnDefinition("score", INT)
         .addIndexDefinition("score").addIndexDefinition("id",
         "score").build().getCreateIndexIfNotExistsStatements();
        
         generates
        
         "[create index if not exists index_reports_score on reports(score), create index if not exists
         index_reports_id_score on reports(id, score)]"
        戻り値:
      • getCreateTableIfNotExistsStatement

        public String getCreateTableIfNotExistsStatement()
        Returns a String object representing this TableDefinition's value.
         TableDefinition.builder("reports").addColumnDefinition("id", VARCHAR, PRIMARY_KEY)
         .addColumnDefinition("score", INT).build().getTableSchema();
        
         generates
        
         "create table if not exists reports(id varchar primary key, score int)"
        戻り値:
      • getDropTableIfExistsStatement

        public String getDropTableIfExistsStatement()
        Gets drop table if exists statement.
        戻り値:
      • getTableName

        public String getTableName()
      • getTableNameAndColumnDefinitions

        public String getTableNameAndColumnDefinitions()
        Returns a String object representing this TableDefinition's value.
         TableDefinition.builder("reports").addColumnDefinition("id", VARCHAR, PRIMARY_KEY)
         .addColumnDefinition("score", INT).build().getTableSchema();
        
         generates
        
         "reports(id varchar primary key, score int)"
        戻り値:
      • toSqlDataType

        public static String toSqlDataType​(Class<?> type)