com.github.drinkjava2.jdialects.model
Class TableModel

java.lang.Object
  extended by com.github.drinkjava2.jdialects.model.TableModel

public class TableModel
extends Object

A TableModel definition represents a platform dependent Database Table, from 1.0.5 this class name changed from "Table" to "TableModel" to avoid naming conflict to JPA's "@Table" annotation

Since:
1.0.2
Author:
Yong Zhu

Constructor Summary
TableModel()
           
TableModel(String tableName)
           
 
Method Summary
 TableModel addColumn(ColumnModel column)
          Add a ColumnModel
 ColumnModel addColumn(String columnName)
          Add a column with given columnName to tableModel
 void addGenerator(IdGenerator generator)
          Add a "create table..." DDL to generate ID, similar like JPA's TableGen
 TableModel check(String check)
          Add the table check, note: not all database support table check
 ColumnModel column(String columnName)
          find column in tableModel by given columnName, if not found, add a new column with columnName
 TableModel comment(String comment)
          Add the table comment, note: not all database support table comment
 TableModel engineTail(String engineTail)
          If support engine like MySQL or MariaDB, add engineTail at the end of "create table..." DDL, usually used to set encode String like " DEFAULT CHARSET=utf8" for MySQL
 FKeyModel fkey()
          Start add a foreign key definition in DDL, detail usage see demo
 FKeyModel fkey(String fkeyName)
          Start add a foreign key definition in DDL, detail usage see demo
protected  void getAndSetters____________________________()
           
 String getCheck()
           
 ColumnModel getColumn(String colOrFieldName)
          Get ColumnModel by column Name or field name ignore case, if not found, return null
 ColumnModel getColumnByColName(String colName)
          Get ColumnModel by columnName ignore case, if not found, return null
 ColumnModel getColumnByFieldName(String fieldName)
          Get ColumnModel by entity field name ignore case, if not found, return null
 List<ColumnModel> getColumns()
           
 String getComment()
           
 String getDebugInfo()
           
 String getEngineTail()
           
 Class<?> getEntityClass()
           
 ColumnModel getFirstPKeyColumn()
           
 FKeyModel getFkey(String fkeyName)
          Get a FKeyModel by given fkeyName
 List<FKeyModel> getFkeyConstraints()
           
 IdGenerator getIdGenerator(GenerationType generationType)
          Get one of these IdGenerator instance by generationType: IDENTITY,AUTO,UUID25,UUID32,UUID36,TIMESTAMP
 IdGenerator getIdGenerator(GenerationType generationType, String name)
          Search and return the IdGenerator in this TableModel by its generationType and name
static IdGenerator getIdGenerator(GenerationType generationType, String name, List<IdGenerator> idGeneratorList)
          Get a IdGenerator by type, if not found, search by name
 IdGenerator getIdGenerator(String name)
          Search and return the IdGenerator in this TableModel by its name
static IdGenerator getIdGeneratorByType(GenerationType generationType)
          Get one of these IdGenerator instance by generationType: IDENTITY,AUTO,UUID25,UUID32,UUID36,TIMESTAMP, if not found , return null;
 List<IdGenerator> getIdGenerators()
           
 List<IndexModel> getIndexConsts()
           
 List<ColumnModel> getPKeyColsSortByColumnName()
          Get pkey columns sorted by column name
 int getPKeyCount()
           
 Boolean getReadOnly()
           
 ColumnModel getShardDatabaseColumn()
           
 ColumnModel getShardTableColumn()
           
 String getTableName()
           
 List<UniqueModel> getUniqueConsts()
           
 IndexModel index()
          Start add a Index in DDL, detail usage see demo
 IndexModel index(String indexName)
          Start add a Index in DDL, detail usage see demo
 TableModel newCopy()
           
 TableModel removeColumn(String columnName)
          Remove a ColumnModel by given columnName
 TableModel removeFKey(String fkeyName)
          Remove a FKey by given fkeyName
 void sequenceGenerator(String name, String sequenceName, Integer initialValue, Integer allocationSize)
          Add a sequence definition DDL, note: some dialects do not support sequence
 void setCheck(String check)
           
 void setColumns(List<ColumnModel> columns)
           
 void setComment(String comment)
           
 void setEngineTail(String engineTail)
           
 void setEntityClass(Class<?> entityClass)
           
 void setFkeyConstraints(List<FKeyModel> fkeyConstraints)
           
 void setIdGenerators(List<IdGenerator> idGenerators)
           
 void setIndexConsts(List<IndexModel> indexConsts)
           
 void setReadOnly(Boolean readOnly)
           
 void setTableName(String tableName)
           
 void setUniqueConsts(List<UniqueModel> uniqueConsts)
           
 void sortedUUIDGenerator(String name, Integer sortedLength, Integer uuidLength)
          Add a Sequence Generator, note: not all database support sequence
 void tableGenerator(String name, String tableName, String pkColumnName, String valueColumnName, String pkColumnValue, Integer initialValue, Integer allocationSize)
          Add a TableGenerator
 UniqueModel unique()
          Start add a unique constraint in DDL, detail usage see demo
 UniqueModel unique(String uniqueName)
          Start add a unique constraint in DDL, detail usage see demo
 void uuidAny(String name, Integer length)
          Add a UUIDAnyGenerator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableModel

public TableModel()

TableModel

public TableModel(String tableName)
Method Detail

newCopy

public TableModel newCopy()
Returns:
an editable copy of current TableModel

tableGenerator

public void tableGenerator(String name,
                           String tableName,
                           String pkColumnName,
                           String valueColumnName,
                           String pkColumnValue,
                           Integer initialValue,
                           Integer allocationSize)
Add a TableGenerator


uuidAny

public void uuidAny(String name,
                    Integer length)
Add a UUIDAnyGenerator


addGenerator

public void addGenerator(IdGenerator generator)
Add a "create table..." DDL to generate ID, similar like JPA's TableGen


sequenceGenerator

public void sequenceGenerator(String name,
                              String sequenceName,
                              Integer initialValue,
                              Integer allocationSize)
Add a sequence definition DDL, note: some dialects do not support sequence

Parameters:
name - The name of sequence Java object itself
sequenceName - the name of the sequence will created in database
initialValue - The initial value
allocationSize - The allocationSize

sortedUUIDGenerator

public void sortedUUIDGenerator(String name,
                                Integer sortedLength,
                                Integer uuidLength)
Add a Sequence Generator, note: not all database support sequence


check

public TableModel check(String check)
Add the table check, note: not all database support table check


comment

public TableModel comment(String comment)
Add the table comment, note: not all database support table comment


addColumn

public TableModel addColumn(ColumnModel column)
Add a ColumnModel


removeColumn

public TableModel removeColumn(String columnName)
Remove a ColumnModel by given columnName


removeFKey

public TableModel removeFKey(String fkeyName)
Remove a FKey by given fkeyName


column

public ColumnModel column(String columnName)
find column in tableModel by given columnName, if not found, add a new column with columnName


addColumn

public ColumnModel addColumn(String columnName)
Add a column with given columnName to tableModel

Parameters:
columnName -
Returns:
the Column object

getColumn

public ColumnModel getColumn(String colOrFieldName)
Get ColumnModel by column Name or field name ignore case, if not found, return null


getColumnByColName

public ColumnModel getColumnByColName(String colName)
Get ColumnModel by columnName ignore case, if not found, return null


getColumnByFieldName

public ColumnModel getColumnByFieldName(String fieldName)
Get ColumnModel by entity field name ignore case, if not found, return null


getShardTableColumn

public ColumnModel getShardTableColumn()
Returns:
First found ShardTable Column , if not found , return null

getShardDatabaseColumn

public ColumnModel getShardDatabaseColumn()
Returns:
First found ShardDatabase Column , if not found , return null

fkey

public FKeyModel fkey()
Start add a foreign key definition in DDL, detail usage see demo


fkey

public FKeyModel fkey(String fkeyName)
Start add a foreign key definition in DDL, detail usage see demo


getFkey

public FKeyModel getFkey(String fkeyName)
Get a FKeyModel by given fkeyName


index

public IndexModel index()
Start add a Index in DDL, detail usage see demo


index

public IndexModel index(String indexName)
Start add a Index in DDL, detail usage see demo


unique

public UniqueModel unique()
Start add a unique constraint in DDL, detail usage see demo


unique

public UniqueModel unique(String uniqueName)
Start add a unique constraint in DDL, detail usage see demo


engineTail

public TableModel engineTail(String engineTail)
If support engine like MySQL or MariaDB, add engineTail at the end of "create table..." DDL, usually used to set encode String like " DEFAULT CHARSET=utf8" for MySQL


getIdGenerator

public IdGenerator getIdGenerator(GenerationType generationType,
                                  String name)
Search and return the IdGenerator in this TableModel by its generationType and name


getIdGenerator

public IdGenerator getIdGenerator(GenerationType generationType)
Get one of these IdGenerator instance by generationType: IDENTITY,AUTO,UUID25,UUID32,UUID36,TIMESTAMP


getIdGenerator

public IdGenerator getIdGenerator(String name)
Search and return the IdGenerator in this TableModel by its name


getIdGeneratorByType

public static IdGenerator getIdGeneratorByType(GenerationType generationType)
Get one of these IdGenerator instance by generationType: IDENTITY,AUTO,UUID25,UUID32,UUID36,TIMESTAMP, if not found , return null;


getIdGenerator

public static IdGenerator getIdGenerator(GenerationType generationType,
                                         String name,
                                         List<IdGenerator> idGeneratorList)
Get a IdGenerator by type, if not found, search by name


getPKeyCount

public int getPKeyCount()

getFirstPKeyColumn

public ColumnModel getFirstPKeyColumn()

getPKeyColsSortByColumnName

public List<ColumnModel> getPKeyColsSortByColumnName()
Get pkey columns sorted by column name


getDebugInfo

public String getDebugInfo()

getAndSetters____________________________

protected void getAndSetters____________________________()

getTableName

public String getTableName()

setTableName

public void setTableName(String tableName)

getCheck

public String getCheck()

setCheck

public void setCheck(String check)

getComment

public String getComment()

setComment

public void setComment(String comment)

getColumns

public List<ColumnModel> getColumns()

setColumns

public void setColumns(List<ColumnModel> columns)

getFkeyConstraints

public List<FKeyModel> getFkeyConstraints()

setFkeyConstraints

public void setFkeyConstraints(List<FKeyModel> fkeyConstraints)

getEngineTail

public String getEngineTail()

setEngineTail

public void setEngineTail(String engineTail)

getIndexConsts

public List<IndexModel> getIndexConsts()

setIndexConsts

public void setIndexConsts(List<IndexModel> indexConsts)

getUniqueConsts

public List<UniqueModel> getUniqueConsts()

setUniqueConsts

public void setUniqueConsts(List<UniqueModel> uniqueConsts)

getIdGenerators

public List<IdGenerator> getIdGenerators()

setIdGenerators

public void setIdGenerators(List<IdGenerator> idGenerators)

getEntityClass

public Class<?> getEntityClass()

setEntityClass

public void setEntityClass(Class<?> entityClass)

getReadOnly

public Boolean getReadOnly()

setReadOnly

public void setReadOnly(Boolean readOnly)


Copyright © 2018. All rights reserved.