Package org.apache.ofbiz.entity.jdbc
Class DatabaseUtil
- java.lang.Object
-
- org.apache.ofbiz.entity.jdbc.DatabaseUtil
-
public class DatabaseUtil extends java.lang.Object
Utilities for Entity Database Maintenance
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DatabaseUtil.ColumnCheckInfo
static class
DatabaseUtil.ReferenceCheckInfo
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
connectionUrl
protected Datasource
datasourceInfo
protected java.lang.String
driverName
protected GenericHelperInfo
helperInfo
protected ModelFieldTypeReader
modelFieldTypeReader
static java.lang.String
module
protected java.lang.String
password
protected java.lang.String
userName
-
Constructor Summary
Constructors Constructor Description DatabaseUtil(GenericHelperInfo helperInfo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
addColumn(ModelEntity entity, ModelField field)
void
checkDb(java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> messages, boolean addMissing)
void
checkDb(java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> colWrongSize, java.util.List<java.lang.String> messages, boolean checkPks, boolean checkFks, boolean checkFkIdx, boolean addMissing)
int
checkPrimaryKeyInfo(java.sql.ResultSet rsPks, java.lang.String lookupSchemaName, boolean needsUpperCase, java.util.Map<java.lang.String,java.util.Map<java.lang.String,DatabaseUtil.ColumnCheckInfo>> colInfo, java.util.Collection<java.lang.String> messages)
java.lang.String
createDeclaredIndex(ModelEntity entity, ModelIndex modelIndex)
int
createDeclaredIndices(ModelEntity entity, java.util.List<java.lang.String> messages)
java.lang.String
createForeignKey(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, java.lang.String fkStyle, boolean useFkInitiallyDeferred)
java.lang.String
createForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
int
createForeignKeyIndices(ModelEntity entity, int constraintNameClipLength, java.util.List<java.lang.String> messages)
int
createForeignKeyIndices(ModelEntity entity, java.util.List<java.lang.String> messages)
int
createForeignKeys(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, int constraintNameClipLength, java.lang.String fkStyle, boolean useFkInitiallyDeferred, java.util.List<java.lang.String> messages)
int
createForeignKeys(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> messages)
java.lang.String
createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength)
void
createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, java.util.List<java.lang.String> messages)
void
createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, java.util.List<java.lang.String> messages)
void
createPrimaryKey(ModelEntity entity, java.util.List<java.lang.String> messages)
java.lang.String
createTable(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, boolean addFks)
java.lang.String
deleteDeclaredIndex(ModelEntity entity, ModelIndex modelIndex)
java.lang.String
deleteDeclaredIndices(ModelEntity entity)
void
deleteDeclaredIndices(ModelEntity entity, java.util.List<java.lang.String> messages)
java.lang.String
deleteForeignKey(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength)
java.lang.String
deleteForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
java.lang.String
deleteForeignKeyIndices(ModelEntity entity, int constraintNameClipLength)
void
deleteForeignKeyIndices(ModelEntity entity, java.util.List<java.lang.String> messages)
void
deleteForeignKeys(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, int constraintNameClipLength, java.util.List<java.lang.String> messages)
void
deleteForeignKeys(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> messages)
java.lang.String
deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength)
void
deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, java.util.List<java.lang.String> messages)
void
deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, java.util.List<java.lang.String> messages)
void
deletePrimaryKey(ModelEntity entity, java.util.List<java.lang.String> messages)
void
deleteTable(ModelEntity entity, java.util.List<java.lang.String> messages)
protected java.sql.Connection
getConnection()
protected java.sql.Connection
getConnectionLogged(java.util.Collection<java.lang.String> messages)
java.sql.DatabaseMetaData
getDatabaseMetaData(java.sql.Connection connection, java.util.Collection<java.lang.String> messages)
Datasource
getDatasource()
java.util.Map<java.lang.String,java.util.Set<java.lang.String>>
getIndexInfo(java.util.Set<java.lang.String> tableNames, java.util.Collection<java.lang.String> messages, boolean[] needsUpperCase)
java.util.Map<java.lang.String,java.util.Map<java.lang.String,DatabaseUtil.ReferenceCheckInfo>>
getReferenceInfo(java.util.Set<java.lang.String> tableNames, java.util.Collection<java.lang.String> messages)
Gets reference info.java.lang.String
getSchemaName(java.sql.DatabaseMetaData dbData)
java.util.TreeSet<java.lang.String>
getTableNames(java.util.Collection<java.lang.String> messages)
java.util.List<ModelEntity>
induceModelFromDb(java.util.Collection<java.lang.String> messages)
Creates a list of ModelEntity objects based on meta data from the databasejava.lang.String
makeFkConstraintClause(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, java.lang.String fkStyle, boolean useFkInitiallyDeferred)
java.lang.String
makeFkConstraintName(ModelRelation modelRelation, int constraintNameClipLength)
java.lang.String
makeFkIndexClause(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
java.lang.String
makeIndexClause(ModelEntity entity, ModelIndex modelIndex)
java.lang.String
makeIndexName(ModelIndex modelIndex, int constraintNameClipLength)
java.lang.String
makePkConstraintName(ModelEntity entity, int constraintNameClipLength)
void
printDbMiscData(java.sql.DatabaseMetaData dbData, java.sql.Connection con)
java.lang.String
renameColumn(ModelEntity entity, ModelField field, java.lang.String newName)
void
repairColumnSize(ModelEntity entity, ModelField field, java.util.List<java.lang.String> messages)
void
repairColumnSizeChanges(java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> fieldsWrongSize, java.util.List<java.lang.String> messages)
void
updateCharacterSetAndCollation(ModelEntity entity, java.util.List<java.lang.String> messages)
-
-
-
Field Detail
-
module
public static final java.lang.String module
-
modelFieldTypeReader
protected ModelFieldTypeReader modelFieldTypeReader
-
datasourceInfo
protected Datasource datasourceInfo
-
helperInfo
protected GenericHelperInfo helperInfo
-
connectionUrl
protected java.lang.String connectionUrl
-
driverName
protected java.lang.String driverName
-
userName
protected java.lang.String userName
-
password
protected java.lang.String password
-
-
Constructor Detail
-
DatabaseUtil
public DatabaseUtil(GenericHelperInfo helperInfo)
-
-
Method Detail
-
getConnection
protected java.sql.Connection getConnection() throws java.sql.SQLException, GenericEntityException
- Throws:
java.sql.SQLException
GenericEntityException
-
getConnectionLogged
protected java.sql.Connection getConnectionLogged(java.util.Collection<java.lang.String> messages)
-
getDatasource
public Datasource getDatasource()
-
checkDb
public void checkDb(java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> messages, boolean addMissing)
-
checkDb
public void checkDb(java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> colWrongSize, java.util.List<java.lang.String> messages, boolean checkPks, boolean checkFks, boolean checkFkIdx, boolean addMissing)
-
induceModelFromDb
public java.util.List<ModelEntity> induceModelFromDb(java.util.Collection<java.lang.String> messages)
Creates a list of ModelEntity objects based on meta data from the database
-
getDatabaseMetaData
public java.sql.DatabaseMetaData getDatabaseMetaData(java.sql.Connection connection, java.util.Collection<java.lang.String> messages)
-
printDbMiscData
public void printDbMiscData(java.sql.DatabaseMetaData dbData, java.sql.Connection con)
-
getTableNames
public java.util.TreeSet<java.lang.String> getTableNames(java.util.Collection<java.lang.String> messages)
-
checkPrimaryKeyInfo
public int checkPrimaryKeyInfo(java.sql.ResultSet rsPks, java.lang.String lookupSchemaName, boolean needsUpperCase, java.util.Map<java.lang.String,java.util.Map<java.lang.String,DatabaseUtil.ColumnCheckInfo>> colInfo, java.util.Collection<java.lang.String> messages) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
getReferenceInfo
public java.util.Map<java.lang.String,java.util.Map<java.lang.String,DatabaseUtil.ReferenceCheckInfo>> getReferenceInfo(java.util.Set<java.lang.String> tableNames, java.util.Collection<java.lang.String> messages)
Gets reference info.- Parameters:
tableNames
- the table namesmessages
- the messages- Returns:
- the reference info
-
getIndexInfo
public java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getIndexInfo(java.util.Set<java.lang.String> tableNames, java.util.Collection<java.lang.String> messages, boolean[] needsUpperCase)
-
createTable
public java.lang.String createTable(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, boolean addFks)
-
deleteTable
public void deleteTable(ModelEntity entity, java.util.List<java.lang.String> messages)
-
addColumn
public java.lang.String addColumn(ModelEntity entity, ModelField field)
-
renameColumn
public java.lang.String renameColumn(ModelEntity entity, ModelField field, java.lang.String newName)
-
repairColumnSize
public void repairColumnSize(ModelEntity entity, ModelField field, java.util.List<java.lang.String> messages)
-
repairColumnSizeChanges
public void repairColumnSizeChanges(java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> fieldsWrongSize, java.util.List<java.lang.String> messages)
-
makePkConstraintName
public java.lang.String makePkConstraintName(ModelEntity entity, int constraintNameClipLength)
-
makeFkConstraintName
public java.lang.String makeFkConstraintName(ModelRelation modelRelation, int constraintNameClipLength)
-
makeIndexName
public java.lang.String makeIndexName(ModelIndex modelIndex, int constraintNameClipLength)
-
createForeignKeys
public int createForeignKeys(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> messages)
-
createForeignKeys
public int createForeignKeys(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, int constraintNameClipLength, java.lang.String fkStyle, boolean useFkInitiallyDeferred, java.util.List<java.lang.String> messages)
-
createForeignKey
public java.lang.String createForeignKey(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, java.lang.String fkStyle, boolean useFkInitiallyDeferred)
-
makeFkConstraintClause
public java.lang.String makeFkConstraintClause(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, java.lang.String fkStyle, boolean useFkInitiallyDeferred)
-
deleteForeignKeys
public void deleteForeignKeys(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, java.util.List<java.lang.String> messages)
-
deleteForeignKeys
public void deleteForeignKeys(ModelEntity entity, java.util.Map<java.lang.String,ModelEntity> modelEntities, int constraintNameClipLength, java.util.List<java.lang.String> messages)
-
deleteForeignKey
public java.lang.String deleteForeignKey(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength)
-
createPrimaryKey
public void createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, java.util.List<java.lang.String> messages)
-
createPrimaryKey
public void createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, java.util.List<java.lang.String> messages)
-
createPrimaryKey
public void createPrimaryKey(ModelEntity entity, java.util.List<java.lang.String> messages)
-
createPrimaryKey
public java.lang.String createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength)
-
deletePrimaryKey
public void deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, java.util.List<java.lang.String> messages)
-
deletePrimaryKey
public void deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, java.util.List<java.lang.String> messages)
-
deletePrimaryKey
public void deletePrimaryKey(ModelEntity entity, java.util.List<java.lang.String> messages)
-
deletePrimaryKey
public java.lang.String deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength)
-
createDeclaredIndices
public int createDeclaredIndices(ModelEntity entity, java.util.List<java.lang.String> messages)
-
createDeclaredIndex
public java.lang.String createDeclaredIndex(ModelEntity entity, ModelIndex modelIndex)
-
makeIndexClause
public java.lang.String makeIndexClause(ModelEntity entity, ModelIndex modelIndex)
-
deleteDeclaredIndices
public void deleteDeclaredIndices(ModelEntity entity, java.util.List<java.lang.String> messages)
-
deleteDeclaredIndices
public java.lang.String deleteDeclaredIndices(ModelEntity entity)
-
deleteDeclaredIndex
public java.lang.String deleteDeclaredIndex(ModelEntity entity, ModelIndex modelIndex)
-
createForeignKeyIndices
public int createForeignKeyIndices(ModelEntity entity, java.util.List<java.lang.String> messages)
-
createForeignKeyIndices
public int createForeignKeyIndices(ModelEntity entity, int constraintNameClipLength, java.util.List<java.lang.String> messages)
-
createForeignKeyIndex
public java.lang.String createForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
-
makeFkIndexClause
public java.lang.String makeFkIndexClause(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
-
deleteForeignKeyIndices
public void deleteForeignKeyIndices(ModelEntity entity, java.util.List<java.lang.String> messages)
-
deleteForeignKeyIndices
public java.lang.String deleteForeignKeyIndices(ModelEntity entity, int constraintNameClipLength)
-
deleteForeignKeyIndex
public java.lang.String deleteForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
-
getSchemaName
public java.lang.String getSchemaName(java.sql.DatabaseMetaData dbData) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
updateCharacterSetAndCollation
public void updateCharacterSetAndCollation(ModelEntity entity, java.util.List<java.lang.String> messages)
-
-