com.silverpeas.mydb.control
Class TableManager

java.lang.Object
  extended by com.silverpeas.mydb.control.TableManager

public class TableManager
extends Object

Manager used to create or modify a database table, not its content but its description. For the moment, only creation mode is managed.

Author:
Antoine HEDIN

Field Summary
static int MODE_CREATION
           
static int MODE_UPDATE
           
 
Constructor Summary
TableManager(int mode, String originPage, ArrayList<String> keywords, DataTypeList dataTypeList)
           
 
Method Summary
 DataTypeList getDataTypeList()
           
 DbColumn getErrorColumn()
           
 String getErrorLabel()
           
 ForeignKeys getForeignKeys()
           
 String[] getForeignKeysQueries()
           
 String[][] getKeysImpacts()
          Each line of the returned table contains informations concerning a column of the table : - the name of the column - the names of the keys which would be modified if the column is removed - the names of the keys which would be removed if the column is removed
 int getMode()
           
 String getOriginPage()
           
 PrimaryKey getPrimaryKey()
           
 DbTable getTable()
           
 String getTableCreationQuery()
           
 UnicityKeys getUnicityKeys()
           
 String[] getUnicityKeysQueries()
           
 boolean hasErrorLabel()
           
 boolean isCreationMode()
           
 boolean isValidColumn(DbColumn column, com.stratelia.silverpeas.util.ResourcesWrapper resources, int exceptedIndex)
          Checks if the column is valid.
 boolean isValidKeyName(Object object, com.stratelia.silverpeas.util.ResourcesWrapper resources, int index)
          Checks the validity of the object's name :
- the name has to be valorized.
 boolean isValidTableName(String[] tableNames, com.stratelia.silverpeas.util.ResourcesWrapper resources)
          Checks if the current table's name is valid.
 void removeColumn(int index)
          Removes from the table the column corresponding to the index.
 void setErrorColumn(DbColumn errorColumn)
           
 void setErrorLabel(String errorLabel)
           
 void updateColumn(DbColumn column, int index)
          Updates the column corresponding to the column and the index given as parameters.
 void updateColumn(String name, int errorType, String value)
          Updates a column consecutively to an error detected in a foreign key which references it.
 void updatePrimaryKey(PrimaryKey newPrimaryKey)
          Updates the primary key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_CREATION

public static final int MODE_CREATION
See Also:
Constant Field Values

MODE_UPDATE

public static final int MODE_UPDATE
See Also:
Constant Field Values
Constructor Detail

TableManager

public TableManager(int mode,
                    String originPage,
                    ArrayList<String> keywords,
                    DataTypeList dataTypeList)
Method Detail

getMode

public int getMode()

getOriginPage

public String getOriginPage()

isCreationMode

public boolean isCreationMode()

getTable

public DbTable getTable()

setErrorColumn

public void setErrorColumn(DbColumn errorColumn)

getErrorColumn

public DbColumn getErrorColumn()

setErrorLabel

public void setErrorLabel(String errorLabel)

getErrorLabel

public String getErrorLabel()

hasErrorLabel

public boolean hasErrorLabel()

getDataTypeList

public DataTypeList getDataTypeList()

getPrimaryKey

public PrimaryKey getPrimaryKey()

getUnicityKeys

public UnicityKeys getUnicityKeys()

getForeignKeys

public ForeignKeys getForeignKeys()

updatePrimaryKey

public void updatePrimaryKey(PrimaryKey newPrimaryKey)
Updates the primary key. Forces the corresponding table's columns to be not nullable.

Parameters:
newPrimaryKey - The reference primary key.

updateColumn

public void updateColumn(DbColumn column,
                         int index)
Updates the column corresponding to the column and the index given as parameters. Updates the keys which reference it.

Parameters:
column - The reference column.
index - The index of the column to update.

removeColumn

public void removeColumn(int index)
Removes from the table the column corresponding to the index.

Parameters:
index - The index of the column to delete.

isValidTableName

public boolean isValidTableName(String[] tableNames,
                                com.stratelia.silverpeas.util.ResourcesWrapper resources)
Checks if the current table's name is valid. Fills the error label if an error is detected.

Parameters:
tableNames - The other tables names.
resources - The resources wrapper.
Returns:
True if the current table's name is valid.

isValidColumn

public boolean isValidColumn(DbColumn column,
                             com.stratelia.silverpeas.util.ResourcesWrapper resources,
                             int exceptedIndex)
Checks if the column is valid. Fills the error label if an error is detected. The following characteristics of the columns are checked : name, data type, default value.

Parameters:
column - The column to check.
resources - The resources wrapper.
exceptedIndex - The index of the column (to avoid comparing the column with itself).
Returns:
True if the column is valid.

isValidKeyName

public boolean isValidKeyName(Object object,
                              com.stratelia.silverpeas.util.ResourcesWrapper resources,
                              int index)
Checks the validity of the object's name :
- the name has to be valorized.
- it has to be different from the database keywords.
- it must not be the same of an other column or key of the table.

Parameters:
object - The object (column or key) to check.
resources - The resources wrapper.
index - The index of the object (to avoid comparing the object with itself).
Returns:
True if the name of the object is valid.

getTableCreationQuery

public String getTableCreationQuery()
Returns:
The SQL query to call to create the current table (columns and primary key).

getUnicityKeysQueries

public String[] getUnicityKeysQueries()
Returns:
The list of SQL queries to call to create the table's unicity keys.

getForeignKeysQueries

public String[] getForeignKeysQueries()
Returns:
The list of SQL queries to call to create the table's foreign keys.

updateColumn

public void updateColumn(String name,
                         int errorType,
                         String value)
Updates a column consecutively to an error detected in a foreign key which references it. The type or the size of the column is so modified to correspond to the description of the key.

Parameters:
name - the column's name.
errorType - The error type.
value - The new value, corresponding to the new type or size of the column.

getKeysImpacts

public String[][] getKeysImpacts()
Each line of the returned table contains informations concerning a column of the table : - the name of the column - the names of the keys which would be modified if the column is removed - the names of the keys which would be removed if the column is removed

Returns:
A list of the links which exist between the columns of the table and its different keys. This list is used to propose warning messages to the user when he decides to delete a column, to inform him about the consequences of deleting a column on table's keys (modification or deletion of them).


Copyright © 2016 Silverpeas. All Rights Reserved.