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.util.Date ; 26 import java.text.SimpleDateFormat ; 27 28 import org.apache.torque.util.Query; 29 30 45 public class DBMM extends AbstractDBAdapter 46 { 47 50 private static final long serialVersionUID = 7547291410802807010L; 51 52 53 private static final String DATE_FORMAT = "yyyyMMddHHmmss"; 54 55 58 protected DBMM() 59 { 60 } 61 62 68 public String toUpperCase(String in) 69 { 70 return in; 71 } 72 73 79 public String ignoreCase(String in) 80 { 81 return in; 82 } 83 84 87 public String getIDMethodType() 88 { 89 return AUTO_INCREMENT; 90 } 91 92 99 public String getIDMethodSQL(Object obj) 100 { 101 return "SELECT LAST_INSERT_ID()"; 102 } 103 104 112 public void lockTable(Connection con, String table) throws SQLException 113 { 114 Statement statement = con.createStatement(); 115 StringBuffer stmt = new StringBuffer (); 116 stmt.append("LOCK TABLE ").append(table).append(" WRITE"); 117 statement.executeUpdate(stmt.toString()); 118 } 119 120 128 public void unlockTable(Connection con, String table) throws SQLException 129 { 130 Statement statement = con.createStatement(); 131 statement.executeUpdate("UNLOCK TABLES"); 132 } 133 134 143 public void generateLimits(Query query, int offset, int limit) 144 { 145 StringBuffer limitStringBuffer = new StringBuffer (); 146 147 if (offset > 0) 148 { 149 limitStringBuffer.append(offset) 150 .append(", ") 151 .append(limit); 152 } 153 else 154 { 155 if (limit >= 0) 156 { 157 limitStringBuffer.append(limit); 158 } 159 } 160 161 query.setLimit(limitStringBuffer.toString()); 162 query.setPreLimit(null); 163 query.setPostLimit(null); 164 } 165 166 173 public int getLimitStyle() 174 { 175 return DB.LIMIT_STYLE_MYSQL; 176 } 177 178 182 public boolean supportsNativeLimit() 183 { 184 return true; 185 } 186 187 191 public boolean supportsNativeOffset() 192 { 193 return true; 194 } 195 196 204 public String getDateString(Date date) 205 { 206 char delim = getStringDelimiter(); 207 return (delim + new SimpleDateFormat (DATE_FORMAT).format(date) + delim); 208 } 209 } 210 | Popular Tags |