Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)

com.lapetus_ltd.api.db.xml.types
Class TLptsDBCreateStatementColumnType

java.lang.Object
  extended by com.lapetus_ltd._2009.xml.types.XLptsDBCreateStatementColumnType
      extended by com.lapetus_ltd.api.db.xml.types.TLptsDBCreateStatementColumnType

public class TLptsDBCreateStatementColumnType
extends XLptsDBCreateStatementColumnType

Class Description : Initialisation class for the column type of a CREATE statement.

This class is part of the settings required by the CREATE statement (as below).

$LastChangedRevision: 1165 $
$LastChangedDate:: 2010-11-03 10:37:03#$


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

TLptsDBCreateStatementColumnType

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);
   ...

 


TLptsDBCreateStatementColumnType

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);
 }

 

Parameters:
cct - the class object to copy.
Method Detail

addConstraint

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);
     }
   }
 

Parameters:
item - the constraint to add.

equals

public boolean equals(java.lang.Object obj)
Overrides the Object equals function.

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 :


 

Overrides:
equals in class java.lang.Object
Parameters:
obj - the create column type
Returns:
true if they are equal, false otherwise.

getConstraintTypeList

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);
     }
   }
 

Overrides:
getConstraintTypeList in class XLptsDBCreateStatementColumnType
Returns:
Returns a list of constraints.

getConstraintTypeListSize

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);
     }
   }
 

Returns:
Returns the number of constraints on this column.

removeConstraint

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);
     }
   }
 

Parameters:
item - the constraint to remove from list.


Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)