|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lapetus_ltd._2009.xml.types.XLptsDBCreateStatementColumnType
com.lapetus_ltd.api.db.xml.types.TLptsDBCreateStatementColumnType
public class TLptsDBCreateStatementColumnType
Class Description : Initialisation class for the column type of a CREATE statement.
Field Summary |
---|
Fields inherited from class com.lapetus_ltd._2009.xml.types.XLptsDBCreateStatementColumnType |
---|
_default, collate, column, constraintTypeList, id, sizes, sqlType |
Constructor Summary | |
---|---|
TLptsDBCreateStatementColumnType()
This constructor initiates the Create Column Type and the constraint list. |
|
TLptsDBCreateStatementColumnType(XLptsDBCreateStatementColumnType cct)
This constructor copies the driver information from an XLptsDBCreateStatementColumnType. |
Method Summary | |
---|---|
void |
addConstraint(XLptsDBCreateColumnConstraintType item)
Adds the constraint to the constraint list. |
boolean |
equals(java.lang.Object obj)
Overrides the Object equals function. |
java.util.List<XLptsDBCreateColumnConstraintType> |
getConstraintTypeList()
Returns a copy of the constraint type list. |
int |
getConstraintTypeListSize()
Returns the size of the constraint list. |
void |
removeConstraint(XLptsDBCreateColumnConstraintType item)
Removes the constraint from the constraint list. |
Methods inherited from class com.lapetus_ltd._2009.xml.types.XLptsDBCreateStatementColumnType |
---|
getCollate, getColumn, getDefault, getId, getSizes, getSqlType, setCollate, setColumn, setDefault, setId, setSizes, setSqlType |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TLptsDBCreateStatementColumnType()
This constructor initiates the Create Column Type and the constraint list.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never.
Notes : Default Constructor initiate variable and initialize the driver list.
Example :
// Create the statement and set the Type of Statement to Update. TLptsStatement createStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.CREATE); TLptsDBCreateStatementRootType rootType = new TLptsDBCreateStatementRootType(); rootType.setTitle("root"); // Set a table TLptsDBCreateStatementTableType table = new TLptsDBCreateStatementTableType(); // Set the name of the table table.setTable("newTable"); // set the table in the root type rootType.setTable(table); // In some DBs the tables can be temporary TLptsDBCreateStatementTableTemporaryType temporary = new TLptsDBCreateStatementTableTemporaryType(); temporary.setTemporary(false); // Set other parameters on the temporary type XLptsDBCreateStatementTableGlobalLocal globalLocal = new XLptsDBCreateStatementTableGlobalLocal(); // Temporary table can be global, local or nothing specific globalLocal.setGlobalLocal(XLptsDBCreateStatementTableGlobalLocalType.GLOBAL); temporary.setGlobalLocal(globalLocal); table.setTemporary(temporary); // Create the columns TLptsDBCreateStatementColumnType idColumn = new TLptsDBCreateStatementColumnType(); // Set the column name idColumn.setColumn("id"); XLptsDBCreateStatementColumnSqlType sqlType = new XLptsDBCreateStatementColumnSqlType(); sqlType.setSqlType(java.sql.Types.INTEGER); idColumn.setSqlType(sqlType); // Some types like varchar require a size. Some types like decimal have two sizes. // The first is the integer digits and the second is the decimal places. // XLptsDBCreateStatementColumnSizeType size = new XLptsDBCreateStatementColumnSizeType(); // size.setSize1("10"); // total length // size.setSize2("2"); // decimal places // idColumn.setSizes(size); // Text type columns can have Collation. Collation is not available in all DBs and the values are not consistent across DBs. // XLptsDBCreateStatementColumnCollateType collate = new XLptsDBCreateStatementColumnCollateType(); // collate.setCollate("SQL_Latin1_General_CP1253_CI_AS"); // idColumn.setCollate(collate); // XLptsDBCreateStatementColumnDefaultType defaultValue = new XLptsDBCreateStatementColumnDefaultType(); // defaultValue.setDefault("10"); // idColumn.setDefault(defaultValue); // Some DB's allows column Constraints. A column can have more than one constraint. TLptsDBCreateColumnConstraintType columnConstraintType = new TLptsDBCreateColumnConstraintType(); // Set column Parameters columnConstraintType.setColumnId(idColumn.getId()); // Constraint values are NOT NULL, UNIQUE, PRIMARY KEY, REFERENCES, CHECK // The following needs to be noted for each type: // NOT NULL and UNIQUE cannot have a name. setConstraint, onDelete and onUpdate cannot be set // PRIMARY KEY can have a name but setConstraint, onDelete and onUpdate cannot be set // CHECK can have a name and setConstraint should be set. onDelete and onUpdate cannot be set // REFERENCES can have a name. The table and column names must be set to the referenced column/table. columnConstraintType.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); // columnConstraintType.setName("ID_PRI_CONSTRAINT"); // columnConstraintType.setConstraint("id"); // columnConstraintType.setColumn("id_of_refTable"); // columnConstraintType.setTable("refTable"); // columnConstraintType.setOnDelete(XLptsDBCreateColumnConstraintOnDeleteUpdateType.CASCADE); // columnConstraintType.setOnUpdate(XLptsDBCreateColumnConstraintOnDeleteUpdateType.RESTRICT); // At last we add the columnConstraint to the constraint list of the column idColumn.addConstraint(columnConstraintType); table.addColumn(idColumn); ...
public TLptsDBCreateStatementColumnType(XLptsDBCreateStatementColumnType cct)
This constructor copies the driver information from an XLptsDBCreateStatementColumnType.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never.
Notes : Use this function every time you need to copy or instantiate a type XLptsDBCreateStatementColumnType class.
Example :
public void example(XLptsDBCreateStatementColumnType cct) { TLptsDBCreateStatementColumnType column = new TLptsDBCreateStatementColumnType(cct); }
cct
- the class object to copy.Method Detail |
---|
public void addConstraint(XLptsDBCreateColumnConstraintType item)
Adds the constraint to the constraint list.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : n/a
Notes : Use this to add to the list. Getting the list with getConstraintTypeList and
then adding does not have any affect.
Example :
// Some Databases do not support a column that has both PRIMARY_KEY and NOT_NULL constraints, due to the fact that // PRIMARY implies NOT_NULL. // In this case we check if there is a NOT_NULL constraint, we remove it and then set the PRIMARY_KEY constraint. for(XLptsDBCreateStatementColumnType column : createStatement.getrootTypeItem().getTable().getColumnList()) if(column.getColumn().equals("id") && column instanceof TLptsDBCreateStatementColumnType) { if (((TLptsDBCreateStatementColumnType)column).getConstraintTypeListSize()>0) { boolean isPrimary = false; for(XLptsDBCreateColumnConstraintType constraint : ((TLptsDBCreateStatementColumnType)column).getConstraintTypeList()) { if(constraint.getConstraintType().equals(XLptsDBCreateColumnConstraintParameterType.NOT_NULL)) { ((TLptsDBCreateStatementColumnType)column).removeConstraint(constraint); isPrimary = true; } } if(!isPrimary) { TLptsDBCreateColumnConstraintType columnConstraint = new TLptsDBCreateColumnConstraintType(column.getId()); columnConstraint.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); ((TLptsDBCreateStatementColumnType) column).addConstraint(columnConstraint); } } else { TLptsDBCreateColumnConstraintType columnConstraint = new TLptsDBCreateColumnConstraintType(column.getId()); columnConstraint.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); ((TLptsDBCreateStatementColumnType) column).addConstraint(columnConstraint); } }
item
- the constraint to add.public boolean equals(java.lang.Object obj)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : n/a
Notes : Use this to compare this object to another TLptsDBCreateStatementColumnType or XLptsDBCreateStatementColumnType object.
Example :
equals
in class java.lang.Object
obj
- the create column type
public java.util.List<XLptsDBCreateColumnConstraintType> getConstraintTypeList()
Returns a copy of the constraint type list.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never. The result may be an empty list.
Notes : Do not add to this list as there is no result. Use the addConstraint function.
Example :
// Some Databases do not support a column that has both PRIMARY_KEY and NOT_NULL constraints, due to the fact that // PRIMARY implies NOT_NULL. // In this case we check if there is a NOT_NULL constraint, we remove it and then set the PRIMARY_KEY constraint. for(XLptsDBCreateStatementColumnType column : createStatement.getrootTypeItem().getTable().getColumnList()) if(column.getColumn().equals("id") && column instanceof TLptsDBCreateStatementColumnType) { if (((TLptsDBCreateStatementColumnType)column).getConstraintTypeListSize()>0) { boolean isPrimary = false; for(XLptsDBCreateColumnConstraintType constraint : ((TLptsDBCreateStatementColumnType)column).getConstraintTypeList()) { if(constraint.getConstraintType().equals(XLptsDBCreateColumnConstraintParameterType.NOT_NULL)) { ((TLptsDBCreateStatementColumnType)column).removeConstraint(constraint); isPrimary = true; } } if(!isPrimary) { TLptsDBCreateColumnConstraintType columnConstraint = new TLptsDBCreateColumnConstraintType(column.getId()); columnConstraint.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); ((TLptsDBCreateStatementColumnType) column).addConstraint(columnConstraint); } } else { TLptsDBCreateColumnConstraintType columnConstraint = new TLptsDBCreateColumnConstraintType(column.getId()); columnConstraint.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); ((TLptsDBCreateStatementColumnType) column).addConstraint(columnConstraint); } }
getConstraintTypeList
in class XLptsDBCreateStatementColumnType
public int getConstraintTypeListSize()
Returns the size of the constraint list.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never. The result may be an empty list.
Notes : Do not use getConstraintTypeList().size() as it is not efficient.
Example :
// Some Databases do not support a column that has both PRIMARY_KEY and NOT_NULL constraints, due to the fact that // PRIMARY implies NOT_NULL. // In this case we check if there is a NOT_NULL constraint, we remove it and then set the PRIMARY_KEY constraint. for(XLptsDBCreateStatementColumnType column : createStatement.getrootTypeItem().getTable().getColumnList()) if(column.getColumn().equals("id") && column instanceof TLptsDBCreateStatementColumnType) { if (((TLptsDBCreateStatementColumnType)column).getConstraintTypeListSize()>0) { boolean isPrimary = false; for(XLptsDBCreateColumnConstraintType constraint : ((TLptsDBCreateStatementColumnType)column).getConstraintTypeList()) { if(constraint.getConstraintType().equals(XLptsDBCreateColumnConstraintParameterType.NOT_NULL)) { ((TLptsDBCreateStatementColumnType)column).removeConstraint(constraint); isPrimary = true; } } if(!isPrimary) { TLptsDBCreateColumnConstraintType columnConstraint = new TLptsDBCreateColumnConstraintType(column.getId()); columnConstraint.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); ((TLptsDBCreateStatementColumnType) column).addConstraint(columnConstraint); } } else { TLptsDBCreateColumnConstraintType columnConstraint = new TLptsDBCreateColumnConstraintType(column.getId()); columnConstraint.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); ((TLptsDBCreateStatementColumnType) column).addConstraint(columnConstraint); } }
public void removeConstraint(XLptsDBCreateColumnConstraintType item)
Removes the constraint from the constraint list.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : n/a
Notes : Use this to remove from the list. Getting the list with getConstraintTypeList and
then removing does not have any affect.
Example :
// Some Databases do not support a column that has both PRIMARY_KEY and NOT_NULL constraints, due to the fact that // PRIMARY implies NOT_NULL. // In this case we check if there is a NOT_NULL constraint, we remove it and then set the PRIMARY_KEY constraint. for(XLptsDBCreateStatementColumnType column : createStatement.getrootTypeItem().getTable().getColumnList()) if(column.getColumn().equals("id") && column instanceof TLptsDBCreateStatementColumnType) { if (((TLptsDBCreateStatementColumnType)column).getConstraintTypeListSize()>0) { boolean isPrimary = false; for(XLptsDBCreateColumnConstraintType constraint : ((TLptsDBCreateStatementColumnType)column).getConstraintTypeList()) { if(constraint.getConstraintType().equals(XLptsDBCreateColumnConstraintParameterType.NOT_NULL)) { ((TLptsDBCreateStatementColumnType)column).removeConstraint(constraint); isPrimary = true; } } if(!isPrimary) { TLptsDBCreateColumnConstraintType columnConstraint = new TLptsDBCreateColumnConstraintType(column.getId()); columnConstraint.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); ((TLptsDBCreateStatementColumnType) column).addConstraint(columnConstraint); } } else { TLptsDBCreateColumnConstraintType columnConstraint = new TLptsDBCreateColumnConstraintType(column.getId()); columnConstraint.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); ((TLptsDBCreateStatementColumnType) column).addConstraint(columnConstraint); } }
item
- the constraint to remove from list.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |