Class DatabaseUtil


  • public class DatabaseUtil
    extends java.lang.Object
    Utilities for Entity Database Maintenance
    • Field Detail

      • module

        public static final java.lang.String module
      • datasourceInfo

        protected Datasource datasourceInfo
      • connectionUrl

        protected java.lang.String connectionUrl
      • driverName

        protected java.lang.String driverName
      • userName

        protected java.lang.String userName
      • password

        protected java.lang.String password
    • Method Detail

      • 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 names
        messages - 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)
      • 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)