1 package org.apache.torque.adapter; 2 3 21 22 import java.sql.Connection ; 23 import java.sql.SQLException ; 24 import java.sql.Statement ; 25 import java.text.SimpleDateFormat ; 26 import java.util.Date ; 27 28 import org.apache.torque.TorqueException; 29 import org.apache.torque.util.Criteria; 30 import org.apache.torque.util.Query; 31 import org.apache.torque.util.SqlExpression; 32 33 44 public class DBSybase extends AbstractDBAdapter 45 { 46 49 private static final long serialVersionUID = 4782996646843056810L; 50 51 52 private static final String DATE_FORMAT = "yyyyMMdd HH:mm:ss"; 53 54 57 protected DBSybase() 58 { 59 } 60 61 67 public String toUpperCase(String in) 68 { 69 return new StringBuffer ("UPPER(").append(in).append(")").toString(); 70 } 71 72 78 public String ignoreCase(String in) 79 { 80 return new StringBuffer ("UPPER(").append(in).append(")").toString(); 81 } 82 83 86 public String getIDMethodType() 87 { 88 return AUTO_INCREMENT; 89 } 90 91 98 public String getIDMethodSQL(Object unused) 99 { 100 return "select @@identity"; 101 } 102 103 110 public void lockTable(Connection con, String table) throws SQLException 111 { 112 Statement statement = con.createStatement(); 113 114 StringBuffer stmt = new StringBuffer (); 115 stmt.append("SELECT next_id FROM ") 116 .append(table) 117 .append(" FOR UPDATE"); 118 119 statement.executeQuery(stmt.toString()); 120 } 121 122 129 public void unlockTable(Connection con, String table) throws SQLException 130 { 131 con.commit(); 134 } 135 136 143 public int getLimitStyle() 144 { 145 return DB.LIMIT_STYLE_SYBASE; 146 } 147 148 152 public boolean supportsNativeLimit() 153 { 154 return true; 155 } 156 157 166 public void generateLimits(Query query, int offset, int limit) 167 throws TorqueException 168 { 169 if (limit + offset > 0) 170 { 171 query.setRowcount(String.valueOf(limit + offset)); 172 } 173 else if (limit + offset == 0) 174 { 175 query.getWhereClause().add(SqlExpression.build("1", new Integer (0), Criteria.EQUAL)); 177 } 178 } 179 180 188 public String getDateString(Date date) 189 { 190 char delim = getStringDelimiter(); 191 return (delim + new SimpleDateFormat (DATE_FORMAT).format(date) + delim); 192 } 193 194 205 public boolean escapeText() 206 { 207 return false; 208 } 209 210 219 public boolean useEscapeClauseForLike() 220 { 221 return true; 222 } 223 } 224 | Popular Tags |