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 DatasourceInfo |
datasourceInfo |
protected String |
helperName |
protected ModelFieldTypeReader |
modelFieldTypeReader |
static String |
module |
| Constructor and Description |
|---|
DatabaseUtil(String helperName)
Constructs with the name of a helper that is used to load
DatasourceInfo from
EntityConfigUtil and uses the static ConnectionFactory for connections. |
| Modifier and Type | Method and Description |
|---|---|
String |
addColumn(ModelEntity entity,
ModelField field) |
void |
checkDb(Map<String,? extends ModelEntity> modelEntities,
Collection<String> messages,
boolean addMissing)
Does a gzillion things to upgrade the database to the entitymodel by adding tables etc.
|
void |
checkDb(Map<String,? extends ModelEntity> modelEntities,
Collection<String> messages,
boolean addMissing,
boolean promote,
boolean widen)
Does a gzillion things to upgrade the database to the entitymodel by adding tables etc.
|
String |
createDeclaredIndex(ModelEntity entity,
ModelIndex modelIndex) |
String |
createDeclaredIndices(ModelEntity entity)
Creates a database index for every declared index on the given entity.
|
String |
createForeignKey(ModelEntity entity,
ModelRelation modelRelation,
ModelEntity relModelEntity,
int constraintNameClipLength,
String fkStyle,
boolean useFkInitiallyDeferred) |
String |
createForeignKeyIndex(ModelEntity entity,
ModelRelation modelRelation,
int constraintNameClipLength) |
String |
createForeignKeyIndices(ModelEntity entity,
int constraintNameClipLength) |
String |
createForeignKeys(ModelEntity entity,
Map<String,? extends ModelEntity> modelEntities,
int constraintNameClipLength,
String fkStyle,
boolean useFkInitiallyDeferred) |
String |
createTable(ModelEntity entity,
Map<String,? extends ModelEntity> modelEntities,
boolean addFks,
boolean usePkConstraintNames,
int constraintNameClipLength,
String fkStyle,
boolean useFkInitiallyDeferred) |
String |
deleteDeclaredIndex(ModelEntity entity,
ModelIndex modelIndex) |
String |
deleteDeclaredIndices(ModelEntity entity) |
String |
deleteForeignKey(ModelEntity entity,
ModelRelation modelRelation,
ModelEntity relModelEntity,
int constraintNameClipLength) |
String |
deleteForeignKeyIndex(ModelEntity entity,
ModelRelation modelRelation,
int constraintNameClipLength) |
String |
deleteForeignKeyIndices(ModelEntity entity,
int constraintNameClipLength) |
String |
deleteForeignKeys(ModelEntity entity,
Map<String,? extends ModelEntity> modelEntities,
int constraintNameClipLength) |
Map<String,List<DatabaseUtil.ColumnCheckInfo>> |
getColumnInfo(Set<String> tableNames,
Collection<String> messages) |
Connection |
getConnection()
Uses the configured
ConnectionProvider to get a Connection based on
the configured helper name. |
Map<String,Set<String>> |
getIndexInfo(Set<String> tableNames,
Collection<String> messages) |
Map<String,Set<String>> |
getIndexInfo(Set<String> tableNames,
Collection<String> messages,
boolean includeUnique)
Gets index information from the database for the given table names only, optionally including unique indexes.
|
Map<String,Map<String,DatabaseUtil.ReferenceCheckInfo>> |
getReferenceInfo(Set<String> tableNames,
Collection<String> messages) |
static String |
getSchemaPattern(DatabaseMetaData dbData,
String schemaName)
Lookup schema name according do database metadata
see JIRA-28526 this method needs to be coherent with
convertToSchemaTableName(String, java.sql.DatabaseMetaData) and
ModelEntity.getTableName(org.ofbiz.core.entity.config.DatasourceInfo) |
TreeSet<String> |
getTableNames(Collection<String> messages) |
List<ModelEntity> |
induceModelFromDb(Collection<String> messages)
Creates a list of ModelEntity objects based on metadata 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) |
public static final String module
protected final String helperName
protected final ModelFieldTypeReader modelFieldTypeReader
protected final DatasourceInfo datasourceInfo
public DatabaseUtil(String helperName)
DatasourceInfo from
EntityConfigUtil and uses the static ConnectionFactory for connections.helperName - public Connection getConnection() throws SQLException, GenericEntityException
ConnectionProvider to get a Connection based on
the configured helper name.ConnectionSQLExceptionGenericEntityExceptionpublic void checkDb(Map<String,? extends ModelEntity> modelEntities, Collection<String> messages, boolean addMissing)
modelEntities - Model entity names to ModelEntity objects.messages - a thing to collect errors.addMissing - if true, will attempt to add tables and columns, fks, indices etc are added always.public void checkDb(Map<String,? extends ModelEntity> modelEntities, Collection<String> messages, boolean addMissing, boolean promote, boolean widen)
modelEntities - Model entity names to ModelEntity objects.messages - a thing to collect errors.addMissing - if true, will attempt to add tables and columns, fks, indices etc are added always.promote - if true, will attempt to promote types to wider types, as defined in allowedFieldTypePromotions.widen - if true, will attempt to widen types with size (only widen, never shorten)public List<ModelEntity> induceModelFromDb(Collection<String> messages)
public TreeSet<String> getTableNames(Collection<String> messages)
public static String getSchemaPattern(DatabaseMetaData dbData, String schemaName) throws SQLException
convertToSchemaTableName(String, java.sql.DatabaseMetaData) and
ModelEntity.getTableName(org.ofbiz.core.entity.config.DatasourceInfo)SQLExceptionpublic Map<String,List<DatabaseUtil.ColumnCheckInfo>> getColumnInfo(Set<String> tableNames, Collection<String> messages)
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)
public Map<String,Set<String>> getIndexInfo(Set<String> tableNames, Collection<String> messages, boolean includeUnique)
tableNames - the names of tables to get indexes for.messages - a collector of errors.includeUnique - if true, the index info will include unique indexes which could include pk indexes.public String createTable(ModelEntity entity, Map<String,? extends ModelEntity> modelEntities, boolean addFks, boolean usePkConstraintNames, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred)
public String addColumn(ModelEntity entity, ModelField field)
public String makeFkConstraintName(ModelRelation modelRelation, int constraintNameClipLength)
public String createForeignKeys(ModelEntity entity, Map<String,? extends ModelEntity> modelEntities, int constraintNameClipLength, String fkStyle, boolean useFkInitiallyDeferred)
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 String deleteForeignKeys(ModelEntity entity, Map<String,? extends ModelEntity> modelEntities, int constraintNameClipLength)
public String deleteForeignKey(ModelEntity entity, ModelRelation modelRelation, ModelEntity relModelEntity, int constraintNameClipLength)
public String createDeclaredIndices(ModelEntity entity)
entity - public String createDeclaredIndex(ModelEntity entity, ModelIndex modelIndex)
public String makeIndexClause(ModelEntity entity, ModelIndex modelIndex)
public String deleteDeclaredIndices(ModelEntity entity)
public String deleteDeclaredIndex(ModelEntity entity, ModelIndex modelIndex)
public String createForeignKeyIndices(ModelEntity entity, int constraintNameClipLength)
public String createForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
public String makeFkIndexClause(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
public String deleteForeignKeyIndices(ModelEntity entity, int constraintNameClipLength)
public String deleteForeignKeyIndex(ModelEntity entity, ModelRelation modelRelation, int constraintNameClipLength)
Copyright © 2015 Atlassian. All rights reserved.