public class DatabaseUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
DatabaseUtil.ColumnCheckInfo |
static class |
DatabaseUtil.ReferenceCheckInfo |
Modifier and Type | Field and Description |
---|---|
protected String |
connectionUrl |
protected Datasource |
datasourceInfo |
protected String |
driverName |
protected GenericHelperInfo |
helperInfo |
protected ModelFieldTypeReader |
modelFieldTypeReader |
static String |
module |
protected String |
password |
protected String |
userName |
Constructor and Description |
---|
DatabaseUtil(GenericHelperInfo helperInfo) |
Modifier and Type | Method and Description |
---|---|
String |
addColumn(ModelEntity entity,
ModelField field) |
void |
checkDb(Map<String,ModelEntity> modelEntities,
List<String> messages,
boolean addMissing) |
void |
checkDb(Map<String,ModelEntity> modelEntities,
List<String> colWrongSize,
List<String> messages,
boolean checkPks,
boolean checkFks,
boolean checkFkIdx,
boolean addMissing) |
int |
checkPrimaryKeyInfo(ResultSet rsPks,
String lookupSchemaName,
boolean needsUpperCase,
Map<String,Map<String,DatabaseUtil.ColumnCheckInfo>> colInfo,
Collection<String> messages) |
String |
createDeclaredIndex(ModelEntity entity,
ModelIndex modelIndex) |
int |
createDeclaredIndices(ModelEntity entity,
List<String> messages) |
String |
createForeignKey(ModelEntity entity,
ModelRelation modelRelation,
ModelEntity relModelEntity,
int constraintNameClipLength,
String fkStyle,
boolean useFkInitiallyDeferred) |
String |
createForeignKeyIndex(ModelEntity entity,
ModelRelation modelRelation,
int constraintNameClipLength) |
int |
createForeignKeyIndices(ModelEntity entity,
int constraintNameClipLength,
List<String> messages) |
int |
createForeignKeyIndices(ModelEntity entity,
List<String> messages) |
int |
createForeignKeys(ModelEntity entity,
Map<String,ModelEntity> modelEntities,
int constraintNameClipLength,
String fkStyle,
boolean useFkInitiallyDeferred,
List<String> messages) |
int |
createForeignKeys(ModelEntity entity,
Map<String,ModelEntity> modelEntities,
List<String> messages) |
String |
createPrimaryKey(ModelEntity entity,
boolean usePkConstraintNames,
int constraintNameClipLength) |
void |
createPrimaryKey(ModelEntity entity,
boolean usePkConstraintNames,
int constraintNameClipLength,
List<String> messages) |
void |
createPrimaryKey(ModelEntity entity,
boolean usePkConstraintNames,
List<String> messages) |
void |
createPrimaryKey(ModelEntity entity,
List<String> messages) |
String |
createTable(ModelEntity entity,
Map<String,ModelEntity> modelEntities,
boolean addFks) |
String |
deleteDeclaredIndex(ModelEntity entity,
ModelIndex modelIndex) |
String |
deleteDeclaredIndices(ModelEntity entity) |
void |
deleteDeclaredIndices(ModelEntity entity,
List<String> messages) |
String |
deleteForeignKey(ModelEntity entity,
ModelRelation modelRelation,
ModelEntity relModelEntity,
int constraintNameClipLength) |
String |
deleteForeignKeyIndex(ModelEntity entity,
ModelRelation modelRelation,
int constraintNameClipLength) |
String |
deleteForeignKeyIndices(ModelEntity entity,
int constraintNameClipLength) |
void |
deleteForeignKeyIndices(ModelEntity entity,
List<String> messages) |
void |
deleteForeignKeys(ModelEntity entity,
Map<String,ModelEntity> modelEntities,
int constraintNameClipLength,
List<String> messages) |
void |
deleteForeignKeys(ModelEntity entity,
Map<String,ModelEntity> modelEntities,
List<String> messages) |
String |
deletePrimaryKey(ModelEntity entity,
boolean usePkConstraintNames,
int constraintNameClipLength) |
void |
deletePrimaryKey(ModelEntity entity,
boolean usePkConstraintNames,
int constraintNameClipLength,
List<String> messages) |
void |
deletePrimaryKey(ModelEntity entity,
boolean usePkConstraintNames,
List<String> messages) |
void |
deletePrimaryKey(ModelEntity entity,
List<String> messages) |
void |
deleteTable(ModelEntity entity,
List<String> messages) |
protected Connection |
getConnection() |
protected Connection |
getConnectionLogged(Collection<String> messages) |
DatabaseMetaData |
getDatabaseMetaData(Connection connection,
Collection<String> messages) |
Datasource |
getDatasource() |
Map<String,Set<String>> |
getIndexInfo(Set<String> tableNames,
Collection<String> messages,
boolean[] needsUpperCase) |
Map<String,Map<String,DatabaseUtil.ReferenceCheckInfo>> |
getReferenceInfo(Set<String> tableNames,
Collection<String> messages) |
String |
getSchemaName(DatabaseMetaData dbData) |
TreeSet<String> |
getTableNames(Collection<String> messages) |
List<ModelEntity> |
induceModelFromDb(Collection<String> messages)
Creates a list of ModelEntity objects based on meta data from the database
|
String |
makeFkConstraintClause(ModelEntity entity,
ModelRelation modelRelation,
ModelEntity relModelEntity,
int constraintNameClipLength,
String fkStyle,
boolean useFkInitiallyDeferred) |
String |
makeFkConstraintName(ModelRelation modelRelation,
int constraintNameClipLength) |
String |
makeFkIndexClause(ModelEntity entity,
ModelRelation modelRelation,
int constraintNameClipLength) |
String |
makeIndexClause(ModelEntity entity,
ModelIndex modelIndex) |
String |
makeIndexName(ModelIndex modelIndex,
int constraintNameClipLength) |
String |
makePkConstraintName(ModelEntity entity,
int constraintNameClipLength) |
void |
printDbMiscData(DatabaseMetaData dbData,
Connection con) |
String |
renameColumn(ModelEntity entity,
ModelField field,
String newName) |
void |
repairColumnSize(ModelEntity entity,
ModelField field,
List<String> messages) |
void |
repairColumnSizeChanges(Map<String,ModelEntity> modelEntities,
List<String> fieldsWrongSize,
List<String> messages) |
void |
updateCharacterSetAndCollation(ModelEntity entity,
List<String> messages) |
public static final String module
protected ModelFieldTypeReader modelFieldTypeReader
protected Datasource datasourceInfo
protected GenericHelperInfo helperInfo
protected String connectionUrl
protected String driverName
protected String userName
protected String password
public DatabaseUtil(GenericHelperInfo helperInfo)
protected Connection getConnection() throws SQLException, GenericEntityException
SQLException
GenericEntityException
protected Connection getConnectionLogged(Collection<String> messages)
public Datasource getDatasource()
public void checkDb(Map<String,ModelEntity> modelEntities, List<String> messages, boolean addMissing)
public void checkDb(Map<String,ModelEntity> modelEntities, List<String> colWrongSize, List<String> messages, boolean checkPks, boolean checkFks, boolean checkFkIdx, boolean addMissing)
public List<ModelEntity> induceModelFromDb(Collection<String> messages)
public DatabaseMetaData getDatabaseMetaData(Connection connection, Collection<String> messages)
public void printDbMiscData(DatabaseMetaData dbData, Connection con)
public TreeSet<String> getTableNames(Collection<String> messages)
public int checkPrimaryKeyInfo(ResultSet rsPks, String lookupSchemaName, boolean needsUpperCase, Map<String,Map<String,DatabaseUtil.ColumnCheckInfo>> colInfo, Collection<String> messages) throws SQLException
SQLException
public Map<String,Map<String,DatabaseUtil.ReferenceCheckInfo>> getReferenceInfo(Set<String> tableNames, Collection<String> messages)
public Map<String,Set<String>> getIndexInfo(Set<String> tableNames, Collection<String> messages, boolean[] needsUpperCase)
public String createTable(ModelEntity entity, Map<String,ModelEntity> modelEntities, boolean addFks)
public void deleteTable(ModelEntity entity, List<String> messages)
public String addColumn(ModelEntity entity, ModelField field)
public String renameColumn(ModelEntity entity, ModelField field, String newName)
public void repairColumnSize(ModelEntity entity, ModelField field, List<String> messages)
public void repairColumnSizeChanges(Map<String,ModelEntity> modelEntities, List<String> fieldsWrongSize, List<String> messages)
public String makePkConstraintName(ModelEntity entity, int constraintNameClipLength)
public String makeFkConstraintName(ModelRelation modelRelation, int constraintNameClipLength)
public String makeIndexName(ModelIndex modelIndex, int constraintNameClipLength)
public int createForeignKeys(ModelEntity entity, Map<String,ModelEntity> modelEntities, List<String> messages)
public int createForeignKeys(ModelEntity entity, Map<String,ModelEntity> modelEntities, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred, List<String> messages)
public String createForeignKey(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred)
public String makeFkConstraintClause(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred)
public void deleteForeignKeys(ModelEntity entity, Map<String,ModelEntity> modelEntities, List<String> messages)
public void deleteForeignKeys(ModelEntity entity, Map<String,ModelEntity> modelEntities, int constraintNameClipLength, List<String> messages)
public String deleteForeignKey(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength)
public void createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, List<String> messages)
public void createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, List<String> messages)
public void createPrimaryKey(ModelEntity entity, List<String> messages)
public String createPrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength)
public void deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength, List<String> messages)
public void deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, List<String> messages)
public void deletePrimaryKey(ModelEntity entity, List<String> messages)
public String deletePrimaryKey(ModelEntity entity, boolean usePkConstraintNames, int constraintNameClipLength)
public int createDeclaredIndices(ModelEntity entity, List<String> messages)
public String createDeclaredIndex(ModelEntity entity, ModelIndex modelIndex)
public String makeIndexClause(ModelEntity entity, ModelIndex modelIndex)
public void deleteDeclaredIndices(ModelEntity entity, List<String> messages)
public String deleteDeclaredIndices(ModelEntity entity)
public String deleteDeclaredIndex(ModelEntity entity, ModelIndex modelIndex)
public int createForeignKeyIndices(ModelEntity entity, List<String> messages)
public int createForeignKeyIndices(ModelEntity entity, int constraintNameClipLength, List<String> messages)
public String createForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
public String makeFkIndexClause(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
public void deleteForeignKeyIndices(ModelEntity entity, List<String> messages)
public String deleteForeignKeyIndices(ModelEntity entity, int constraintNameClipLength)
public String deleteForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
public String getSchemaName(DatabaseMetaData dbData) throws SQLException
SQLException
public void updateCharacterSetAndCollation(ModelEntity entity, List<String> messages)