1 package org.apache.torque.adapter; 2 3 21 22 import java.sql.Connection ; 23 import java.sql.SQLException ; 24 25 import org.apache.torque.util.Query; 26 27 37 public class DBDB2App extends AbstractDBAdapter 38 { 39 42 private static final long serialVersionUID = -3097347241360840675L; 43 44 47 protected DBDB2App() 48 { 49 } 50 51 57 public String toUpperCase(String in) 58 { 59 String s = new StringBuffer ("UPPER(").append(in).append(")").toString(); 60 return s; 61 } 62 63 69 public String ignoreCase(String in) 70 { 71 String s = new StringBuffer ("UPPER(").append(in).append(")").toString(); 72 return s; 73 } 74 75 78 public String getIDMethodType() 79 { 80 return NO_ID_METHOD; 81 } 82 83 86 public String getIDMethodSQL(Object obj) 87 { 88 return null; 89 } 90 91 98 public void lockTable(Connection con, String table) throws SQLException 99 { 100 } 101 102 109 public void unlockTable(Connection con, String table) throws SQLException 110 { 111 } 112 113 120 public int getLimitStyle() 121 { 122 return DB.LIMIT_STYLE_DB2; 123 } 124 125 129 public boolean supportsNativeLimit() 130 { 131 return true; 132 } 133 134 138 public boolean supportsNativeOffset() 139 { 140 return true; 141 } 142 143 160 public void generateLimits(Query query, int offset, int limit) 161 { 162 StringBuffer preLimit = new StringBuffer () 163 .append("SELECT B.* FROM ( ") 164 .append("SELECT A.*, row_number() over() AS TORQUE$ROWNUM FROM ( "); 165 166 StringBuffer postLimit = new StringBuffer () 167 .append(" ) A ") 168 .append(" ) B WHERE "); 169 170 if (offset > 0) 171 { 172 postLimit.append(" B.TORQUE$ROWNUM > ") 173 .append(offset); 174 175 if (limit >= 0) 176 { 177 postLimit.append(" AND B.TORQUE$ROWNUM <= ") 178 .append(offset + limit); 179 } 180 } 181 else 182 { 183 postLimit.append(" B.TORQUE$ROWNUM <= ") 184 .append(limit); 185 } 186 187 query.setPreLimit(preLimit.toString()); 188 query.setPostLimit(postLimit.toString()); 189 query.setLimit(null); 190 } 191 } 192 | Popular Tags |