Coverage Report - liquibase.snapshot.jvm.InformixDatabaseSnapshotGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
InformixDatabaseSnapshotGenerator
0%
0/42
0%
0/8
2.75
 
 1  
 package liquibase.snapshot.jvm;
 2  
 
 3  
 import liquibase.database.Database;
 4  
 import liquibase.database.core.InformixDatabase;
 5  
 import liquibase.database.structure.Column;
 6  
 import liquibase.database.structure.ForeignKey;
 7  
 import liquibase.database.structure.ForeignKeyInfo;
 8  
 import liquibase.exception.DatabaseException;
 9  
 
 10  
 import java.sql.ResultSet;
 11  
 import java.sql.SQLException;
 12  
 import java.util.ArrayList;
 13  
 import java.util.HashMap;
 14  
 import java.util.List;
 15  
 import java.util.Map;
 16  
 
 17  0
 public class InformixDatabaseSnapshotGenerator extends JdbcDatabaseSnapshotGenerator {
 18  
 
 19  0
     private static final Map<Integer, String> qualifiers = new HashMap<Integer, String>();
 20  
 
 21  
     static {
 22  0
         qualifiers.put(0, "YEAR");
 23  0
         qualifiers.put(2, "MONTH");
 24  0
         qualifiers.put(4, "DAY");
 25  0
         qualifiers.put(6, "HOUR");
 26  0
         qualifiers.put(8, "MINUTE");
 27  0
         qualifiers.put(10, "SECOND");
 28  0
         qualifiers.put(11, "FRACTION(1)");
 29  0
         qualifiers.put(12, "FRACTION(2)");
 30  0
         qualifiers.put(13, "FRACTION(3)");
 31  0
         qualifiers.put(14, "FRACTION(4)");
 32  0
         qualifiers.put(15, "FRACTION(5)");
 33  0
     }
 34  
 
 35  
     public boolean supports(Database database) {
 36  0
         return database instanceof InformixDatabase;
 37  
     }
 38  
 
 39  
     public int getPriority(Database database) {
 40  0
         return PRIORITY_DATABASE;
 41  
     }
 42  
 
 43  
     @Override
 44  
     protected void getColumnTypeAndDefValue(Column columnInfo, ResultSet rs, Database database) throws SQLException,
 45  
             DatabaseException {
 46  
         // See http://publib.boulder.ibm.com/infocenter/idshelp/v115/topic/com.ibm.sqlr.doc/sqlr07.htm
 47  0
         String typeName = rs.getString("TYPE_NAME").toUpperCase();
 48  0
         if ("DATETIME".equals(typeName) || "INTERVAL".equals(typeName)) {
 49  0
             int collength = columnInfo.getColumnSize();
 50  
             // int positions = collength / 256;
 51  0
             int firstQualifierType = (collength % 256) / 16;
 52  0
             int lastQualifierType = (collength % 256) % 16;
 53  0
             String type = "DATETIME".equals(typeName) ? "DATETIME" : "INTERVAL";
 54  0
             String firstQualifier = qualifiers.get(firstQualifierType);
 55  0
             String lastQualifier = qualifiers.get(lastQualifierType);
 56  0
             columnInfo.setTypeName(type + " " + firstQualifier + " TO " + lastQualifier);
 57  0
             columnInfo.setLengthSemantics(Column.LengthSemantics.BYTE);
 58  0
         } else {
 59  0
             super.getColumnTypeAndDefValue(columnInfo, rs, database);
 60  
         }
 61  0
     }
 62  
 
 63  
     @Override
 64  
     public List<ForeignKey> getForeignKeys(String schemaName, String foreignKeyTableName, Database database)
 65  
             throws DatabaseException {
 66  0
         List<ForeignKey> fkList = new ArrayList<ForeignKey>();
 67  
         try {
 68  0
             String dbCatalog = database.convertRequestedSchemaToCatalog(schemaName);
 69  
             // Informix handles schema differently
 70  0
             String dbSchema = null;
 71  0
             ResultSet rs = getMetaData(database).getImportedKeys(dbCatalog, dbSchema,
 72  
                     convertTableNameToDatabaseTableName(foreignKeyTableName));
 73  
 
 74  
             try {
 75  0
                 while (rs.next()) {
 76  0
                     ForeignKeyInfo fkInfo = fillForeignKeyInfo(rs);
 77  
 
 78  0
                     fkList.add(generateForeignKey(fkInfo, database, fkList));
 79  0
                 }
 80  
             } finally {
 81  0
                 rs.close();
 82  0
             }
 83  
 
 84  0
             return fkList;
 85  
 
 86  0
         } catch (Exception e) {
 87  0
             throw new DatabaseException(e);
 88  
         }
 89  
     }
 90  
 }