Coverage Report - org.apache.ojb.broker.platforms.PlatformMySQLImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PlatformMySQLImpl
0%
0/55
0%
0/22
2.636
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.ojb.broker.platforms;
 17  
 
 18  
 import java.io.ByteArrayInputStream;
 19  
 import java.io.InputStreamReader;
 20  
 import java.io.Reader;
 21  
 import java.io.StringReader;
 22  
 import java.sql.CallableStatement;
 23  
 import java.sql.Connection;
 24  
 import java.sql.PreparedStatement;
 25  
 import java.sql.SQLException;
 26  
 import java.sql.Types;
 27  
 
 28  
 import org.apache.ojb.broker.query.LikeCriteria;
 29  
 
 30  
 /**
 31  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 32  
  */
 33  0
 public class PlatformMySQLImpl extends PlatformDefaultImpl
 34  
 {
 35  
     private static final String LAST_INSERT = "SELECT LAST_INSERT_ID() FROM ";
 36  
     private static final String LIMIT = " LIMIT 1";
 37  
     
 38  
     /*
 39  
          * @see DatabasePlatform#setObjectForStatement(PreparedStatement, int, Object, int)
 40  
          */
 41  
     public void setObjectForStatement(PreparedStatement ps, int index, Object value, int sqlType) throws SQLException
 42  
     {
 43  0
         switch (sqlType)
 44  
         {
 45  
             case Types.BIT :
 46  0
                 ps.setObject(index, value);
 47  0
                 break;
 48  
 
 49  
             case Types.BLOB :
 50  
             case Types.LONGVARBINARY :
 51  
             case Types.VARBINARY :
 52  0
                 if (value instanceof byte[])
 53  
                 {
 54  0
                     byte buf[] = (byte[]) value;
 55  0
                     ByteArrayInputStream inputStream = new ByteArrayInputStream(buf);
 56  0
                     ps.setBinaryStream(index, inputStream, buf.length);
 57  
 
 58  0
                     break;
 59  
                 }
 60  
 
 61  
             case Types.CLOB :
 62  0
                 Reader reader = null;
 63  0
                 int length = 0;
 64  
 
 65  0
                 if (value instanceof String)
 66  
                 {
 67  0
                     reader = new StringReader((String) value);
 68  0
                     length = (((String) value)).length();
 69  
                 }
 70  0
                 else if (value instanceof char[])
 71  
                 {
 72  0
                     String string = new String((char[])value);
 73  0
                     reader = new StringReader(string);
 74  0
                     length = string.length();
 75  0
                 }
 76  0
                 else if (value instanceof byte[])
 77  
                 {
 78  0
                     byte buf[] = (byte[]) value;
 79  0
                     ByteArrayInputStream inputStream = new ByteArrayInputStream(buf);
 80  0
                     reader = new InputStreamReader(inputStream);
 81  
                 }
 82  
 
 83  0
                 ps.setCharacterStream(index, reader, length);
 84  0
                 break;
 85  
 
 86  
             default :
 87  0
                 super.setObjectForStatement(ps, index, value, sqlType);
 88  
 
 89  
         }
 90  0
     }
 91  
     /**
 92  
          * Get join syntax type for this RDBMS - one on of the constants from
 93  
          * JoinSyntaxType interface
 94  
          */
 95  
     public byte getJoinSyntaxType()
 96  
     {
 97  0
         return SQL92_NOPAREN_JOIN_SYNTAX;
 98  
     }
 99  
 
 100  
     public String getLastInsertIdentityQuery(String tableName)
 101  
     {
 102  0
         return LAST_INSERT + tableName + LIMIT;
 103  
     }
 104  
 
 105  
     /*
 106  
          * (non-Javadoc)
 107  
          * 
 108  
          * @see org.apache.ojb.broker.platforms.Platform#addPagingSql(java.lang.StringBuffer)
 109  
          */
 110  
     public void addPagingSql(StringBuffer anSqlString)
 111  
     {
 112  0
         anSqlString.append(" LIMIT ?,?");
 113  0
     }
 114  
 
 115  
     /* (non-Javadoc)
 116  
      * @see org.apache.ojb.broker.platforms.Platform#createSequenceQuery(String)
 117  
      */
 118  
     public String createSequenceQuery(String sequenceName)
 119  
     {
 120  0
         return "insert into ojb_nextval_seq (seq_name) " + 
 121  
                         "values ('" + sequenceName + "')";
 122  
     }
 123  
 
 124  
     /* (non-Javadoc)
 125  
      * @see org.apache.ojb.broker.platforms.Platform#nextSequenceQuery(String)
 126  
      */
 127  
     public String nextSequenceQuery(String sequenceName)
 128  
     {
 129  0
         return "select ojb_nextval_func ('" + sequenceName + "')";
 130  
     }
 131  
 
 132  
     /* (non-Javadoc)
 133  
      * @see org.apache.ojb.broker.platforms.Platform#dropSequenceQuery(String)
 134  
      */
 135  
     public String dropSequenceQuery(String sequenceName)
 136  
     {
 137  0
         return "delete from ojb_nextval_seq where seq_name='" + 
 138  
                         sequenceName + "'";
 139  
     }
 140  
     
 141  
     /* (non-Javadoc)
 142  
      * Copied over from the OJB implementations for Informix
 143  
      */
 144  
     public CallableStatement prepareNextValProcedureStatement (Connection con,
 145  
                                                             String procedureName, String sequenceName) throws
 146  
                                                             PlatformException
 147  
     {
 148  
             try {
 149  0
                     String sp = " { call " + procedureName + " (?,?) } ";                    
 150  0
                     CallableStatement cs = con.prepareCall(sp);
 151  0
                 cs.registerOutParameter(1, Types.BIGINT);
 152  0
                 cs.setString(2, sequenceName);
 153  0
                     return cs;
 154  0
             } catch (Exception e) {
 155  0
                     throw new PlatformException(e);
 156  
             }
 157  
     }
 158  
     
 159  
     /*
 160  
          * (non-Javadoc)
 161  
          * 
 162  
          * @see org.apache.ojb.broker.platforms.Platform#supportsPaging()
 163  
          */
 164  
     public boolean supportsPaging()
 165  
     {
 166  0
         return true;
 167  
     }
 168  
 
 169  
     /**
 170  
      * @see org.apache.ojb.broker.platforms.Platform#concatenate(java.lang.String[])
 171  
      */
 172  
     public String concatenate(String[] theColumns)
 173  
     {
 174  0
         if (theColumns.length == 1)
 175  
         {
 176  0
             return theColumns[0];
 177  
         }
 178  
         
 179  0
         StringBuffer buf = new StringBuffer();
 180  
         
 181  0
         buf.append("concat(");
 182  0
         for (int i = 0; i < theColumns.length; i++)
 183  
         {
 184  0
             if (i > 0)
 185  
             {
 186  0
                 buf.append(",");
 187  
             }
 188  0
             buf.append(theColumns[i]);
 189  
         }
 190  
 
 191  0
         buf.append(")");
 192  0
         return buf.toString();
 193  
     }    
 194  
     
 195  
     /**
 196  
      * @see org.apache.ojb.broker.platforms.Platform#getEscapeClause(org.apache.ojb.broker.query.LikeCriteria)
 197  
      */
 198  
     public String getEscapeClause(LikeCriteria aCriteria)
 199  
     {
 200  0
         if (LikeCriteria.getEscapeCharacter() != LikeCriteria.DEFAULT_ESCPAPE_CHARACTER)  
 201  
         {
 202  
             // the default escape character is \, so there's no need for an escape clause
 203  0
             return super.getEscapeClause(aCriteria);
 204  
         }
 205  0
         return "";
 206  
     }    
 207  
 }