Clover Coverage Report - Liquibase Core 2.0.3-SNAPSHOT
Coverage timestamp: Sat Aug 6 2011 11:33:15 EDT
../../../img/srcFileCovDistChart1.png 62% of files have more coverage
55   164   30   3.24
22   128   0.55   17
17     1.76  
1    
 
  DB2Database       Line # 11 55 0% 30 86 8.5% 0.08510638
 
  (58)
 
1    package liquibase.database.core;
2   
3    import java.text.ParseException;
4    import java.text.SimpleDateFormat;
5   
6    import liquibase.database.AbstractDatabase;
7    import liquibase.database.DatabaseConnection;
8    import liquibase.exception.DatabaseException;
9    import liquibase.exception.DateParseException;
10   
 
11    public class DB2Database extends AbstractDatabase {
12   
 
13  0 toggle @Override
14    public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException {
15  0 return conn.getDatabaseProductName().startsWith("DB2");
16    }
17   
 
18  2 toggle @Override
19    public String getDefaultDriver(String url) {
20  2 if (url.startsWith("jdbc:db2")) {
21  1 return "com.ibm.db2.jcc.DB2Driver";
22    }
23  1 return null;
24    }
25   
 
26  0 toggle @Override
27    public int getPriority() {
28  0 return PRIORITY_DEFAULT;
29    }
30   
 
31  57 toggle @Override
32    public String getTypeName() {
33  57 return "db2";
34    }
35   
 
36  0 toggle @Override
37    protected String getDefaultDatabaseSchemaName() throws DatabaseException { // NOPMD
38  0 return super.getDefaultDatabaseSchemaName().toUpperCase();
39    }
40   
 
41  0 toggle @Override
42    public boolean supportsInitiallyDeferrableColumns() {
43  0 return false;
44    }
45   
 
46  0 toggle @Override
47    public String getAutoIncrementClause() {
48  0 return "GENERATED BY DEFAULT AS IDENTITY";
49    }
50   
 
51  0 toggle @Override
52    public String getCurrentDateTimeFunction() {
53  0 if (currentDateTimeFunction != null) {
54  0 return currentDateTimeFunction;
55    }
56   
57  0 return "CURRENT TIMESTAMP";
58    }
59   
60    /**
61    * Return an DB2 date literal with the same value as a string formatted using ISO 8601.
62    * <p/>
63    * Convert an ISO8601 date string to one of the following results: to_date('1995-05-23', 'YYYY-MM-DD')
64    * to_date('1995-05-23 09:23:59', 'YYYY-MM-DD HH24:MI:SS')
65    * <p/>
66    * Implementation restriction: Currently, only the following subsets of ISO8601 are supported: YYYY-MM-DD hh:mm:ss
67    * YYYY-MM-DDThh:mm:ss
68    */
 
69  0 toggle @Override
70    public String getDateLiteral(String isoDate) {
71  0 String normalLiteral = super.getDateLiteral(isoDate);
72   
73  0 if (isDateOnly(isoDate)) {
74  0 StringBuffer val = new StringBuffer();
75  0 val.append("DATE(");
76  0 val.append(normalLiteral);
77  0 val.append(')');
78  0 return val.toString();
79  0 } else if (isTimeOnly(isoDate)) {
80  0 StringBuffer val = new StringBuffer();
81  0 val.append("TIME(");
82  0 val.append(normalLiteral);
83  0 val.append(')');
84  0 return val.toString();
85  0 } else if (isDateTime(isoDate)) {
86  0 StringBuffer val = new StringBuffer();
87  0 val.append("TIMESTAMP(");
88  0 val.append(normalLiteral);
89  0 val.append(')');
90  0 return val.toString();
91    } else {
92  0 return "UNSUPPORTED:" + isoDate;
93    }
94    }
95   
 
96  0 toggle @Override
97    public boolean shouldQuoteValue(String value) {
98  0 return super.shouldQuoteValue(value) && !value.startsWith("\"SYSIBM\"");
99    }
100   
 
101  0 toggle @Override
102    public boolean supportsTablespaces() {
103  0 return true;
104    }
105   
 
106  0 toggle @Override
107    public String getViewDefinition(String schemaName, String name) throws DatabaseException {
108  0 return super.getViewDefinition(schemaName, name).replaceFirst("CREATE VIEW \\w+ AS ", ""); // db2 returns
109    // "create view....as
110    // select
111    }
112   
 
113  0 toggle @Override
114    public java.util.Date parseDate(String dateAsString) throws DateParseException {
115  0 try {
116  0 if (dateAsString.indexOf(' ') > 0) {
117  0 return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateAsString);
118  0 } else if (dateAsString.indexOf('.') > 0 && dateAsString.indexOf('-') > 0) {
119  0 return new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSSSSS").parse(dateAsString);
120   
121    } else {
122  0 if (dateAsString.indexOf(':') > 0) {
123  0 return new SimpleDateFormat("HH:mm:ss").parse(dateAsString);
124  0 } else if (dateAsString.indexOf('.') > 0) {
125  0 return new SimpleDateFormat("HH.mm.ss").parse(dateAsString);
126    } else {
127  0 return new SimpleDateFormat("yyyy-MM-dd").parse(dateAsString);
128    }
129    }
130    } catch (ParseException e) {
131  0 throw new DateParseException(dateAsString);
132    }
133    }
134   
 
135  0 toggle @Override
136    public String convertRequestedSchemaToSchema(String requestedSchema) throws DatabaseException {
137  0 if (requestedSchema == null) {
138  0 return getDefaultDatabaseSchemaName();
139    } else {
140  0 return requestedSchema.toUpperCase();
141    }
142    }
143   
 
144  0 toggle @Override
145    public String convertRequestedSchemaToCatalog(String requestedSchema) throws DatabaseException {
146  0 return null;
147    }
148   
 
149  0 toggle @Override
150    public String generatePrimaryKeyName(String tableName) {
151  0 String pkName = super.generatePrimaryKeyName(tableName);
152  0 if (pkName.length() > 18) {
153  0 pkName = pkName.substring(0, 17);
154    }
155  0 return pkName;
156    }
157   
 
158  0 toggle @Override
159    public String escapeIndexName(String schemaName, String indexName) {
160    // does not support the schema name for the index -
161  0 return super.escapeIndexName(null, indexName);
162    }
163   
164    }