View Javadoc
1 package org.apache.torque.adapter; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>. 55 */ 56 57 import java.sql.Connection; 58 import java.sql.SQLException; 59 import java.sql.Statement; 60 import java.util.Date; 61 import java.text.SimpleDateFormat; 62 63 /*** 64 * This is used in order to connect to a MySQL database using the MM 65 * drivers. Simply comment the above and uncomment this code below and 66 * fill in the appropriate values for DB_NAME, DB_HOST, DB_USER, 67 * DB_PASS. 68 * 69 * <P><A HREF="http://www.worldserver.com/mm.mysql/"> 70 * http://www.worldserver.com/mm.mysql/</A> 71 * <p>"jdbc:mysql://" + DB_HOST + "/" + DB_NAME + "?user=" + 72 * DB_USER + "&password=" + DB_PASS; 73 * 74 * @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a> 75 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a> 76 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> 77 * @version $Id: DBMM.java,v 1.11 2002/09/13 05:06:38 stephenh Exp $ 78 */ 79 public class DBMM extends DB 80 { 81 82 /*** A specialized date format for MySQL. */ 83 private static final String DATE_FORMAT = "yyyyMMddHHmmss"; 84 85 /*** 86 * Empty protected constructor. 87 */ 88 protected DBMM() 89 { 90 } 91 92 /*** 93 * This method is used to ignore case. 94 * 95 * @param in The string to transform to upper case. 96 * @return The upper case string. 97 */ 98 public String toUpperCase(String in) 99 { 100 return in; 101 } 102 103 /*** 104 * This method is used to ignore case. 105 * 106 * @param in The string whose case to ignore. 107 * @return The string in a case that can be ignored. 108 */ 109 public String ignoreCase(String in) 110 { 111 return in; 112 } 113 114 /*** 115 * @see org.apache.torque.adapter.DB#getIDMethodType() 116 */ 117 public String getIDMethodType() 118 { 119 return AUTO_INCREMENT; 120 } 121 122 /*** 123 * Returns the SQL to get the database key of the last row 124 * inserted, which in this case is <code>SELECT 125 * LAST_INSERT_ID()</code>. 126 * 127 * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj) 128 */ 129 public String getIDMethodSQL(Object obj) 130 { 131 return "SELECT LAST_INSERT_ID()"; 132 } 133 134 /*** 135 * Locks the specified table. 136 * 137 * @param con The JDBC connection to use. 138 * @param table The name of the table to lock. 139 * @exception SQLException No Statement could be created or 140 * executed. 141 */ 142 public void lockTable(Connection con, String table) throws SQLException 143 { 144 Statement statement = con.createStatement(); 145 StringBuffer stmt = new StringBuffer(); 146 stmt.append("LOCK TABLE ").append(table).append(" WRITE"); 147 statement.executeUpdate(stmt.toString()); 148 } 149 150 /*** 151 * Unlocks the specified table. 152 * 153 * @param con The JDBC connection to use. 154 * @param table The name of the table to unlock. 155 * @exception SQLException No Statement could be created or 156 * executed. 157 */ 158 public void unlockTable(Connection con, String table) throws SQLException 159 { 160 Statement statement = con.createStatement(); 161 statement.executeUpdate("UNLOCK TABLES"); 162 } 163 164 /*** 165 * This method is used to chek whether the database natively 166 * supports limiting the size of the resultset. 167 * 168 * @return True. 169 */ 170 public boolean supportsNativeLimit() 171 { 172 return true; 173 } 174 175 /*** 176 * This method is used to chek whether the database natively 177 * supports returning results starting at an offset position other 178 * than 0. 179 * 180 * @return True. 181 */ 182 public boolean supportsNativeOffset() 183 { 184 return true; 185 } 186 187 /*** 188 * This method is used to chek whether the database supports 189 * limiting the size of the resultset. 190 * 191 * @return LIMIT_STYLE_MYSQL. 192 */ 193 public int getLimitStyle() 194 { 195 return DB.LIMIT_STYLE_MYSQL; 196 } 197 198 /*** 199 * This method overrides the JDBC escapes used to format dates 200 * using a <code>DateFormat</code>. As of version 2.0.11, the MM 201 * JDBC driver does not implement JDBC 3.0 escapes. 202 * 203 * @param date the date to format 204 * @return The properly formatted date String. 205 */ 206 public String getDateString(Date date) 207 { 208 char delim = getStringDelimiter(); 209 return (delim + new SimpleDateFormat(DATE_FORMAT).format(date) + delim); 210 } 211 }

This page was automatically generated by Maven