Package org.apache.ofbiz.entity.jdbc
Class DatabaseUtil
java.lang.Object
org.apache.ofbiz.entity.jdbc.DatabaseUtil
Utilities for Entity Database Maintenance
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddColumn
(ModelEntity entity, ModelField field) Add column string.void
Check db.void
checkDb
(Map<String, ModelEntity> modelEntities, List<String> colWrongSize, List<String> messages, boolean checkPks, boolean checkFks, boolean checkFkIdx, boolean addMissing) Check db.int
checkPrimaryKeyInfo
(ResultSet rsPks, String lookupSchemaName, boolean needsUpperCase, Map<String, Map<String, DatabaseUtil.ColumnCheckInfo>> colInfo, Collection<String> messages) Check primary key info int.createDeclaredIndex
(ModelEntity entity, ModelIndex modelIndex) create declared indexint
createDeclaredIndices
(ModelEntity entity, List<String> messages) create declared indicescreateForeignKey
(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred) Create foreign key string.createForeignKeyIndex
(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength) Create foreign key index string.int
createForeignKeyIndices
(ModelEntity entity, int constraintNameClipLength, List<String> messages) Create foreign key indices int.int
createForeignKeyIndices
(ModelEntity entity, List<String> messages) Create foreign key indices int.int
createForeignKeys
(ModelEntity entity, Map<String, ModelEntity> modelEntities, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred, List<String> messages) Create foreign keys int.int
createForeignKeys
(ModelEntity entity, Map<String, ModelEntity> modelEntities, List<String> messages) Create foreign keys int.createPrimaryKey
(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength) Create primary key string.void
createPrimaryKey
(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, List<String> messages) Create primary key.void
createPrimaryKey
(ModelEntity entity, boolean usePkConstraintNames, List<String> messages) Create primary key.void
createPrimaryKey
(ModelEntity entity, List<String> messages) Create primary key.createTable
(ModelEntity entity, Map<String, ModelEntity> modelEntities, boolean addFks) Create table string.deleteDeclaredIndex
(ModelEntity entity, ModelIndex modelIndex) Delete declared index string.deleteDeclaredIndices
(ModelEntity entity) Delete declared indices string.void
deleteDeclaredIndices
(ModelEntity entity, List<String> messages) Delete declared indices.deleteForeignKey
(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength) Delete foreign key string.deleteForeignKeyIndex
(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength) Delete foreign key index string.deleteForeignKeyIndices
(ModelEntity entity, int constraintNameClipLength) Delete foreign key indices string.void
deleteForeignKeyIndices
(ModelEntity entity, List<String> messages) Delete foreign key indices.void
deleteForeignKeys
(ModelEntity entity, Map<String, ModelEntity> modelEntities, int constraintNameClipLength, List<String> messages) Delete foreign keys.void
deleteForeignKeys
(ModelEntity entity, Map<String, ModelEntity> modelEntities, List<String> messages) Delete foreign keys.deletePrimaryKey
(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength) Delete primary key string.void
deletePrimaryKey
(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, List<String> messages) Delete primary key.void
deletePrimaryKey
(ModelEntity entity, boolean usePkConstraintNames, List<String> messages) Delete primary key.void
deletePrimaryKey
(ModelEntity entity, List<String> messages) Delete primary key.void
deleteTable
(ModelEntity entity, List<String> messages) Delete table.protected Connection
Gets connection.protected Connection
getConnectionLogged
(Collection<String> messages) Gets connection logged.getDatabaseMetaData
(Connection connection, Collection<String> messages) Gets database meta data.Gets datasource.getIndexInfo
(Set<String> tableNames, Collection<String> messages, boolean[] needsUpperCase) Gets index info.getReferenceInfo
(Set<String> tableNames, Collection<String> messages) Gets reference info.getSchemaName
(DatabaseMetaData dbData) Gets schema name.getTableNames
(Collection<String> messages) Gets table names.induceModelFromDb
(Collection<String> messages) Creates a list of ModelEntity objects based on meta data from the databasemakeFkConstraintClause
(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred) Make fk constraint clause string.makeFkConstraintName
(ModelRelation modelRelation, int constraintNameClipLength) Make fk constraint name string.makeFkIndexClause
(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength) Make fk index clause string.makeIndexClause
(ModelEntity entity, ModelIndex modelIndex) make index clausemakeIndexName
(ModelIndex modelIndex, int constraintNameClipLength) Make index name string.makePkConstraintName
(ModelEntity entity, int constraintNameClipLength) Make pk constraint name string.void
printDbMiscData
(DatabaseMetaData dbData, Connection con) Print db misc data.renameColumn
(ModelEntity entity, ModelField field, String newName) Rename column string.void
repairColumnSize
(ModelEntity entity, ModelField field, List<String> messages) Repair column size.void
repairColumnSizeChanges
(Map<String, ModelEntity> modelEntities, List<String> fieldsWrongSize, List<String> messages) Repair column size changes.void
updateCharacterSetAndCollation
(ModelEntity entity, List<String> messages) Update character set and collation.
-
Constructor Details
-
DatabaseUtil
-
-
Method Details
-
getConnection
Gets connection.- Returns:
- the connection
- Throws:
SQLException
- the sql exceptionGenericEntityException
- the generic entity exception
-
getConnectionLogged
Gets connection logged.- Parameters:
messages
- the messages- Returns:
- the connection logged
-
getDatasource
Gets datasource.- Returns:
- the datasource
-
checkDb
public void checkDb(Map<String, ModelEntity> modelEntities, List<String> messages, boolean addMissing) Check db.- Parameters:
modelEntities
- the model entitiesmessages
- the messagesaddMissing
- the add missing
-
checkDb
public void checkDb(Map<String, ModelEntity> modelEntities, List<String> colWrongSize, List<String> messages, boolean checkPks, boolean checkFks, boolean checkFkIdx, boolean addMissing) Check db.- Parameters:
modelEntities
- the model entitiescolWrongSize
- the col wrong sizemessages
- the messagescheckPks
- the check pkscheckFks
- the check fkscheckFkIdx
- the check fk idxaddMissing
- the add missing
-
induceModelFromDb
Creates a list of ModelEntity objects based on meta data from the database -
getDatabaseMetaData
Gets database meta data.- Parameters:
connection
- the connectionmessages
- the messages- Returns:
- the database meta data
-
printDbMiscData
Print db misc data.- Parameters:
dbData
- the db datacon
- the con
-
getTableNames
Gets table names.- Parameters:
messages
- the messages- Returns:
- the table names
-
checkPrimaryKeyInfo
public int checkPrimaryKeyInfo(ResultSet rsPks, String lookupSchemaName, boolean needsUpperCase, Map<String, Map<String, throws SQLExceptionDatabaseUtil.ColumnCheckInfo>> colInfo, Collection<String> messages) Check primary key info int.- Parameters:
rsPks
- the rs pkslookupSchemaName
- the lookup schema nameneedsUpperCase
- the needs upper casecolInfo
- the col infomessages
- the messages- Returns:
- the int
- Throws:
SQLException
- the sql exception
-
getReferenceInfo
public Map<String,Map<String, getReferenceInfoDatabaseUtil.ReferenceCheckInfo>> (Set<String> tableNames, Collection<String> messages) Gets reference info.- Parameters:
tableNames
- the table namesmessages
- the messages- Returns:
- the reference info
-
getIndexInfo
public Map<String,Set<String>> getIndexInfo(Set<String> tableNames, Collection<String> messages, boolean[] needsUpperCase) Gets index info.- Parameters:
tableNames
- the table namesmessages
- the messagesneedsUpperCase
- the needs upper case- Returns:
- the index info
-
createTable
public String createTable(ModelEntity entity, Map<String, ModelEntity> modelEntities, boolean addFks) Create table string.- Parameters:
entity
- the entitymodelEntities
- the model entitiesaddFks
- the add fks- Returns:
- the string
-
deleteTable
Delete table.- Parameters:
entity
- the entitymessages
- the messages
-
addColumn
Add column string.- Parameters:
entity
- the entityfield
- the field- Returns:
- the string
-
renameColumn
Rename column string.- Parameters:
entity
- the entityfield
- the fieldnewName
- the new name- Returns:
- the string
-
repairColumnSize
Repair column size.- Parameters:
entity
- the entityfield
- the fieldmessages
- the messages
-
repairColumnSizeChanges
public void repairColumnSizeChanges(Map<String, ModelEntity> modelEntities, List<String> fieldsWrongSize, List<String> messages) Repair column size changes.- Parameters:
modelEntities
- the model entitiesfieldsWrongSize
- the fields wrong sizemessages
- the messages
-
makePkConstraintName
Make pk constraint name string.- Parameters:
entity
- the entityconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
makeFkConstraintName
Make fk constraint name string.- Parameters:
modelRelation
- the model relationconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
makeIndexName
Make index name string.- Parameters:
modelIndex
- the model indexconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
createForeignKeys
public int createForeignKeys(ModelEntity entity, Map<String, ModelEntity> modelEntities, List<String> messages) Create foreign keys int.- Parameters:
entity
- the entitymodelEntities
- the model entitiesmessages
- the messages- Returns:
- the int
-
createForeignKeys
public int createForeignKeys(ModelEntity entity, Map<String, ModelEntity> modelEntities, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred, List<String> messages) Create foreign keys int.- Parameters:
entity
- the entitymodelEntities
- the model entitiesconstraintNameClipLength
- the constraint name clip lengthfkStyle
- the fk styleuseFkInitiallyDeferred
- the use fk initially deferredmessages
- the messages- Returns:
- the int
-
createForeignKey
public String createForeignKey(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred) Create foreign key string.- Parameters:
entity
- the entitymodelRelation
- the model relationrelModelEntity
- the rel model entityconstraintNameClipLength
- the constraint name clip lengthfkStyle
- the fk styleuseFkInitiallyDeferred
- the use fk initially deferred- Returns:
- the string
-
makeFkConstraintClause
public String makeFkConstraintClause(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred) Make fk constraint clause string.- Parameters:
entity
- the entitymodelRelation
- the model relationrelModelEntity
- the rel model entityconstraintNameClipLength
- the constraint name clip lengthfkStyle
- the fk styleuseFkInitiallyDeferred
- the use fk initially deferred- Returns:
- the string
-
deleteForeignKeys
public void deleteForeignKeys(ModelEntity entity, Map<String, ModelEntity> modelEntities, List<String> messages) Delete foreign keys.- Parameters:
entity
- the entitymodelEntities
- the model entitiesmessages
- the messages
-
deleteForeignKeys
public void deleteForeignKeys(ModelEntity entity, Map<String, ModelEntity> modelEntities, int constraintNameClipLength, List<String> messages) Delete foreign keys.- Parameters:
entity
- the entitymodelEntities
- the model entitiesconstraintNameClipLength
- the constraint name clip lengthmessages
- the messages
-
deleteForeignKey
public String deleteForeignKey(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength) Delete foreign key string.- Parameters:
entity
- the entitymodelRelation
- the model relationrelModelEntity
- the rel model entityconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
createPrimaryKey
public void createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, List<String> messages) Create primary key.- Parameters:
entity
- the entityusePkConstraintNames
- the use pk constraint namesconstraintNameClipLength
- the constraint name clip lengthmessages
- the messages
-
createPrimaryKey
public void createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, List<String> messages) Create primary key.- Parameters:
entity
- the entityusePkConstraintNames
- the use pk constraint namesmessages
- the messages
-
createPrimaryKey
Create primary key.- Parameters:
entity
- the entitymessages
- the messages
-
createPrimaryKey
public String createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength) Create primary key string.- Parameters:
entity
- the entityusePkConstraintNames
- the use pk constraint namesconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
deletePrimaryKey
public void deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, List<String> messages) Delete primary key.- Parameters:
entity
- the entityusePkConstraintNames
- the use pk constraint namesconstraintNameClipLength
- the constraint name clip lengthmessages
- the messages
-
deletePrimaryKey
public void deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, List<String> messages) Delete primary key.- Parameters:
entity
- the entityusePkConstraintNames
- the use pk constraint namesmessages
- the messages
-
deletePrimaryKey
Delete primary key.- Parameters:
entity
- the entitymessages
- the messages
-
deletePrimaryKey
public String deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength) Delete primary key string.- Parameters:
entity
- the entityusePkConstraintNames
- the use pk constraint namesconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
createDeclaredIndices
create declared indices -
createDeclaredIndex
create declared index -
makeIndexClause
make index clause -
deleteDeclaredIndices
Delete declared indices.- Parameters:
entity
- the entitymessages
- the messages
-
deleteDeclaredIndices
Delete declared indices string.- Parameters:
entity
- the entity- Returns:
- the string
-
deleteDeclaredIndex
Delete declared index string.- Parameters:
entity
- the entitymodelIndex
- the model index- Returns:
- the string
-
createForeignKeyIndices
Create foreign key indices int.- Parameters:
entity
- the entitymessages
- the messages- Returns:
- the int
-
createForeignKeyIndices
public int createForeignKeyIndices(ModelEntity entity, int constraintNameClipLength, List<String> messages) Create foreign key indices int.- Parameters:
entity
- the entityconstraintNameClipLength
- the constraint name clip lengthmessages
- the messages- Returns:
- the int
-
createForeignKeyIndex
public String createForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength) Create foreign key index string.- Parameters:
entity
- the entitymodelRelation
- the model relationconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
makeFkIndexClause
public String makeFkIndexClause(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength) Make fk index clause string.- Parameters:
entity
- the entitymodelRelation
- the model relationconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
deleteForeignKeyIndices
Delete foreign key indices.- Parameters:
entity
- the entitymessages
- the messages
-
deleteForeignKeyIndices
Delete foreign key indices string.- Parameters:
entity
- the entityconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
deleteForeignKeyIndex
public String deleteForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength) Delete foreign key index string.- Parameters:
entity
- the entitymodelRelation
- the model relationconstraintNameClipLength
- the constraint name clip length- Returns:
- the string
-
getSchemaName
Gets schema name.- Parameters:
dbData
- the db data- Returns:
- the schema name
- Throws:
SQLException
- the sql exception
-
updateCharacterSetAndCollation
Update character set and collation.- Parameters:
entity
- the entitymessages
- the messages
-