1 10 11 package com.triactive.jdo.store; 12 13 import java.math.BigInteger ; 14 import java.sql.Connection ; 15 import java.sql.DatabaseMetaData ; 16 import java.sql.ResultSet ; 17 import java.sql.Statement ; 18 import java.sql.SQLException ; 19 import java.util.ArrayList ; 20 import javax.jdo.JDOFatalDataStoreException; 21 22 23 31 32 class DB2Adapter extends DatabaseAdapter 33 { 34 39 40 protected DB2Adapter(DatabaseMetaData metadata) 41 { 42 super(metadata); 43 44 maxConstraintNameLength = 18; 45 maxIndexNameLength = 18; 46 } 47 48 public String getVendorID() 49 { 50 return "db2"; 51 } 52 53 public String getSchemaName(Connection conn) throws SQLException 54 { 55 Statement stmt = conn.createStatement(); 56 57 try 58 { 59 String stmtText = "VALUES (CURRENT SCHEMA)"; 60 ResultSet rs = stmt.executeQuery(stmtText); 61 62 try 63 { 64 if (!rs.next()) 65 throw new JDOFatalDataStoreException("No result returned from " + stmtText); 66 67 return rs.getString(1).trim(); 68 } 69 finally 70 { 71 rs.close(); 72 } 73 } 74 finally 75 { 76 stmt.close(); 77 } 78 } 79 80 public boolean supportsBooleanComparison() 81 { 82 return false; 83 } 84 85 public boolean supportsDeferredConstraints() 86 { 87 return false; 88 } 89 90 public boolean supportsNullsInCandidateKeys() 91 { 92 return false; 93 } 94 95 public ColumnInfo newColumnInfo(ResultSet rs) 96 { 97 return new DB2ColumnInfo(rs); 98 } 99 100 public TableExpression newTableExpression(QueryStatement qs, Table table, SQLIdentifier rangeVar) 101 { 102 return new TableExprAsSubquery(qs, table, rangeVar); 103 } 104 105 public int getUnlimitedLengthPrecisionValue(TypeInfo typeInfo) 106 { 107 if (typeInfo.dataType == java.sql.Types.BLOB || typeInfo.dataType == java.sql.Types.CLOB) 108 return 1 << 30; 109 else 110 return super.getUnlimitedLengthPrecisionValue(typeInfo); 111 } 112 113 public String getDropTableStatement(BaseTable table) 114 { 115 return "DROP TABLE " + table.getName(); 116 } 117 118 public NumericExpression lengthMethod(CharacterExpression str) 119 { 120 ArrayList args = new ArrayList (); 121 args.add(str); 122 123 return new NumericExpression("LENGTH", args); 124 } 125 126 public CharacterExpression substringMethod(CharacterExpression str, 127 NumericExpression begin) 128 { 129 ArrayList args = new ArrayList (); 130 args.add(str); 131 args.add(begin.add(new IntegerLiteral(str.getQueryStatement(), BigInteger.ONE))); 132 133 return new CharacterExpression("SUBSTR", args); 134 } 135 136 public CharacterExpression substringMethod(CharacterExpression str, 137 NumericExpression begin, 138 NumericExpression end) 139 { 140 ArrayList args = new ArrayList (); 141 args.add(str); 142 args.add(begin.add(new IntegerLiteral(str.getQueryStatement(), BigInteger.ONE))); 143 args.add(end.sub(begin)); 144 145 return new CharacterExpression("SUBSTR", args); 146 } 147 } 148 | Popular Tags |