|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lapetus_ltd._2009.xml.types.XLptsDBCreateColumnConstraintType
com.lapetus_ltd.api.db.xml.types.TLptsDBCreateColumnConstraintType
public class TLptsDBCreateColumnConstraintType
Class Description : Initialisation class for CREATE statement constraints.
CREATE TABLE `myTable` ( myTableID INT PRIMARY KEY, myName VARCHAR(50) REFERENCES `clients` (`FirstName`), hasChild CHAR(1) CHECK (hasChild IN ('Y','N')), mySalary DECIMAL(10,2) NOT NULL, myInsuranceID VARCHAR(50) UNIQUE )
TLptsStatement createStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.CREATE); TLptsDBCreateStatementRootType rootType = new TLptsDBCreateStatementRootType(); rootType.setTitle("root"); TLptsDBCreateStatementTableType table = new TLptsDBCreateStatementTableType(); table.setTable("myTable"); rootType.setTable(table); TLptsDBCreateStatementColumnType myTableID = new TLptsDBCreateStatementColumnType(); myTableID.setColumn("myTableID"); TLptsDBCreateStatementColumnSqlType myTableIdSqlType = new TLptsDBCreateStatementColumnSqlType(myTableID); myTableIdSqlType.setSqlType(java.sql.Types.INTEGER); myTableID.setSqlType(myTableIdSqlType); TLptsDBCreateColumnConstraintType myTableIdColumnConstraintType = new TLptsDBCreateColumnConstraintType(); myTableIdColumnConstraintType.setColumnId(myTableID.getId()); myTableIdColumnConstraintType.setConstraintType(XLptsDBCreateColumnConstraintParameterType.PRIMARY_KEY); myTableID.addConstraint(myTableIdColumnConstraintType); table.addColumn(myTableID); TLptsDBCreateStatementColumnType myName = new TLptsDBCreateStatementColumnType(); myName.setColumn("myName"); TLptsDBCreateStatementColumnSqlType myNameSqlType = new TLptsDBCreateStatementColumnSqlType(myName); myNameSqlType.setSqlType(java.sql.Types.VARCHAR); myName.setSqlType(myNameSqlType); TLptsDBCreateStatementColumnSizeType myNameSize = new TLptsDBCreateStatementColumnSizeType(myName); myNameSize.setSize1("50"); myName.setSizes(myNameSize); TLptsDBCreateColumnConstraintType myNameColumnConstraintType = new TLptsDBCreateColumnConstraintType(); myNameColumnConstraintType.setColumnId(myName.getId()); myNameColumnConstraintType.setConstraintType(XLptsDBCreateColumnConstraintParameterType.REFERENCES); myNameColumnConstraintType.setTable("clients"); myNameColumnConstraintType.setColumn("FirstName"); myName.addConstraint(myNameColumnConstraintType); table.addColumn(myName); TLptsDBCreateStatementColumnType hasChild = new TLptsDBCreateStatementColumnType(); hasChild.setColumn("hasChild"); TLptsDBCreateStatementColumnSqlType hasChildSqlType = new TLptsDBCreateStatementColumnSqlType(hasChild); hasChildSqlType.setSqlType(java.sql.Types.CHAR); hasChild.setSqlType(hasChildSqlType); TLptsDBCreateStatementColumnSizeType hasChildSize = new TLptsDBCreateStatementColumnSizeType(hasChild); hasChildSize.setSize1("1"); hasChild.setSizes(hasChildSize); TLptsDBCreateColumnConstraintType hasChildColumnConstraintType = new TLptsDBCreateColumnConstraintType(); hasChildColumnConstraintType.setColumnId(hasChild.getId()); hasChildColumnConstraintType.setConstraintType(XLptsDBCreateColumnConstraintParameterType.CHECK); hasChildColumnConstraintType.setConstraint("(hasChild IN ('Y','N'))"); hasChild.addConstraint(hasChildColumnConstraintType); table.addColumn(hasChild); TLptsDBCreateStatementColumnType mySalary = new TLptsDBCreateStatementColumnType(); mySalary.setColumn("mySalary"); TLptsDBCreateStatementColumnSqlType mySalarySqlType = new TLptsDBCreateStatementColumnSqlType(mySalary); mySalarySqlType.setSqlType(java.sql.Types.DECIMAL); mySalary.setSqlType(mySalarySqlType); TLptsDBCreateStatementColumnSizeType mySalarySize = new TLptsDBCreateStatementColumnSizeType(mySalary); mySalarySize.setSize1("10"); mySalarySize.setSize2("2"); mySalary.setSizes(mySalarySize); TLptsDBCreateColumnConstraintType mySalaryColumnConstraintType = new TLptsDBCreateColumnConstraintType(); mySalaryColumnConstraintType.setColumnId(mySalary.getId()); mySalaryColumnConstraintType.setConstraintType(XLptsDBCreateColumnConstraintParameterType.NOT_NULL); mySalary.addConstraint(mySalaryColumnConstraintType); table.addColumn(mySalary); TLptsDBCreateStatementColumnType myInsuranceId = new TLptsDBCreateStatementColumnType(); myInsuranceId.setColumn("myInsuranceId"); TLptsDBCreateStatementColumnSqlType myInsuranceIdSqlType = new TLptsDBCreateStatementColumnSqlType(myInsuranceId); myInsuranceIdSqlType.setSqlType(java.sql.Types.VARCHAR); myInsuranceId.setSqlType(myInsuranceIdSqlType); TLptsDBCreateStatementColumnSizeType myInsuranceIdSize = new TLptsDBCreateStatementColumnSizeType(myInsuranceId); myInsuranceIdSize.setSize1("50"); myInsuranceId.setSizes(myInsuranceIdSize); TLptsDBCreateColumnConstraintType myInsuranceIdColumnConstraintType = new TLptsDBCreateColumnConstraintType(); myInsuranceIdColumnConstraintType.setColumnId(myInsuranceId.getId()); myInsuranceIdColumnConstraintType.setConstraintType(XLptsDBCreateColumnConstraintParameterType.UNIQUE); myInsuranceId.addConstraint(myInsuranceIdColumnConstraintType); table.addColumn(myInsuranceId); createStatement.setCreateRootItem(rootType);
TLptsStatement.setSqlStatementUser(java.lang.String)
XLptsDBStatementType.setSqlStatementModified(boolean)
to true.
Field Summary |
---|
Fields inherited from class com.lapetus_ltd._2009.xml.types.XLptsDBCreateColumnConstraintType |
---|
column, columnId, constraint, constraintType, id, name, onDelete, onUpdate, table |
Constructor Summary | |
---|---|
TLptsDBCreateColumnConstraintType()
This constructor initiates the Column Constraint Type. |
|
TLptsDBCreateColumnConstraintType(java.lang.String columnId)
This constructor initiates the Column Constraint Type with a column id. |
|
TLptsDBCreateColumnConstraintType(XLptsDBCreateColumnConstraintType ct)
This constructor creates a new column constraint class from an existing XLptsDBCreateColumnConstraintType. |
Method Summary | |
---|---|
boolean |
equals(java.lang.Object obj)
Overrides the Object equals function for TLptsDBCreateColumnConstraintType objects. |
Methods inherited from class com.lapetus_ltd._2009.xml.types.XLptsDBCreateColumnConstraintType |
---|
getColumn, getColumnId, getConstraint, getConstraintType, getId, getName, getOnDelete, getOnUpdate, getTable, setColumn, setColumnId, setConstraint, setConstraintType, setId, setName, setOnDelete, setOnUpdate, setTable |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TLptsDBCreateColumnConstraintType()
This constructor initiates the Column Constraint Type.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never.
Notes :
Default Constructor sets constraintType to NOT_NULL, onDelete and onUpdate to NO_ACTION and the other variables as empty stings.
Example :
//Create the statement and set the Type of Statement to CREATE. TLptsStatement createStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.CREATE); //Get the rootType TLptsDBCreateStatementRootType rootType = new TLptsDBCreateStatementRootType(); ... //Some DB's allow column Constraints. A column can have more than one constraint TLptsDBCreateColumnConstraintType columnConstraintType = new TLptsDBCreateColumnConstraintType(); //Set column Parameters columnConstraintType.setColumnId(idColumn.getId()); //Set the name of the Constraint columnConstraintType.setName("prim_key"); 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);
public TLptsDBCreateColumnConstraintType(java.lang.String columnId)
This constructor initiates the Column Constraint Type with a column id.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never.
Notes : Use this constructor to set Column id in a new constraint.
Example :
//Create the statement and set the Type of Statement to CREATE. TLptsStatement createStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.CREATE); //Get the rootType TLptsDBCreateStatementRootType rootType = new TLptsDBCreateStatementRootType(); ... //Some DB's allow column Constraints. A column can have more than one constraint TLptsDBCreateColumnConstraintType columnConstraintType = new TLptsDBCreateColumnConstraintType(idColumn.getId()); //Set the name of the Constraint columnConstraintType.setName("prim_key"); 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);
columnId
- the column id of the constraintpublic TLptsDBCreateColumnConstraintType(XLptsDBCreateColumnConstraintType ct)
This constructor creates a new column constraint class from an existing XLptsDBCreateColumnConstraintType.
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 XLptsDBCreateColumnConstraintType class.
Example :
public void example(XLptsDBCreateColumnConstraintType ct) { TLptsDBCreateColumnConstraintType constraint = new TLptsDBCreateColumnConstraintType(ct); }
ct
- the class object to copy.Method Detail |
---|
public boolean equals(java.lang.Object obj)
Overrides the Object equals function for TLptsDBCreateColumnConstraintType objects.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : n/a
Notes : compares this class to another TLptsDBCreateColumnConstraintType.
Example :
TLptsDBCreateColumnConstraintType cct1 = new TLptsDBCreateColumnConstraintType(); ... TLptsDBCreateColumnConstraintType cct2 = new TLptsDBCreateColumnConstraintType(); ... return cct1.equals(cct2);
equals
in class java.lang.Object
obj
- the column constraint
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |