| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PlatformMsAccessImpl |
|
| 3.0;3 |
| 1 | package org.apache.ojb.broker.platforms; | |
| 2 | ||
| 3 | /* Copyright 2002-2005 The Apache Software Foundation | |
| 4 | * | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | ||
| 18 | import java.io.ByteArrayInputStream; | |
| 19 | import java.math.BigDecimal; | |
| 20 | import java.sql.PreparedStatement; | |
| 21 | import java.sql.ResultSet; | |
| 22 | import java.sql.SQLException; | |
| 23 | import java.sql.Statement; | |
| 24 | import java.sql.Types; | |
| 25 | ||
| 26 | import org.apache.ojb.broker.query.LikeCriteria; | |
| 27 | import org.apache.ojb.broker.util.logging.LoggerFactory; | |
| 28 | ||
| 29 | /** | |
| 30 | * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a> | |
| 31 | * @version $Id: PlatformMsAccessImpl.java,v 1.1 2007-08-24 22:17:35 ewestfal Exp $ | |
| 32 | */ | |
| 33 | public class PlatformMsAccessImpl extends PlatformDefaultImpl | |
| 34 | { | |
| 35 | /** | |
| 36 | * @see Platform#setObjectForStatement(PreparedStatement, int, Object, int) | |
| 37 | */ | |
| 38 | public void setObjectForStatement(PreparedStatement ps, int index, Object value, int sqlType) | |
| 39 | throws SQLException | |
| 40 | { | |
| 41 | if (sqlType == Types.DECIMAL) | |
| 42 | { | |
| 43 | ps.setBigDecimal(index, (BigDecimal) value); | |
| 44 | } | |
| 45 | else if (sqlType == Types.FLOAT) | |
| 46 | { | |
| 47 | // this is because in repository_junit.xml price field is a double in the Article class | |
| 48 | // but repository maps it to a sql type of FLOAT (any my ODBC/JDBC bridge/driver cannot | |
| 49 | // cope with this conversion...possibility of a truncation error heer as well... | |
| 50 | if (value instanceof Double) | |
| 51 | { | |
| 52 | ps.setDouble(index, ((Double) value).doubleValue()); | |
| 53 | } | |
| 54 | else | |
| 55 | { | |
| 56 | super.setObjectForStatement(ps, index, value, sqlType); | |
| 57 | } | |
| 58 | } | |
| 59 | // patch by Ralph Brandes to allow writing to memo fields | |
| 60 | else if (sqlType == Types.LONGVARCHAR) | |
| 61 | { | |
| 62 | if (value instanceof String) | |
| 63 | { | |
| 64 | String s = (String) value; | |
| 65 | // ps.setCharacterStream(index, new StringReader(s), s.length()); | |
| 66 | // for MSACCESS : | |
| 67 | byte[] bytes = s.getBytes(); | |
| 68 | ByteArrayInputStream bais = new ByteArrayInputStream(bytes); | |
| 69 | ps.setAsciiStream(index, bais, bytes.length); | |
| 70 | } | |
| 71 | else | |
| 72 | { | |
| 73 | super.setObjectForStatement(ps, index, value, sqlType); | |
| 74 | } | |
| 75 | } | |
| 76 | // patch by Tino Sch�llhorn | |
| 77 | // Current ODBC-Implementation for Access (I use ODBC 4.0.xxxx) does not | |
| 78 | // support the conversion of LONG values. | |
| 79 | // Error is : "Optional feature not implemented" | |
| 80 | // So I try to pass the LONG-value as an Integer even though it might be possible | |
| 81 | // that the conversion fails - but I don't think that is an issues with Access anyway. | |
| 82 | else if (value instanceof Long) | |
| 83 | { | |
| 84 | ps.setInt(index,((Long)value).intValue()); | |
| 85 | } | |
| 86 | else | |
| 87 | { | |
| 88 | super.setObjectForStatement(ps, index, value, sqlType); | |
| 89 | } | |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * @see Platform#beforeStatementClose(Statement stmt, ResultSet rs) | |
| 94 | */ | |
| 95 | public void beforeStatementClose(Statement stmt, ResultSet rs) throws PlatformException | |
| 96 | { | |
| 97 | if (rs != null) | |
| 98 | { | |
| 99 | try | |
| 100 | { | |
| 101 | rs.close(); | |
| 102 | } | |
| 103 | catch (SQLException e) | |
| 104 | { | |
| 105 | LoggerFactory.getDefaultLogger().warn( | |
| 106 | "Resultset closing failed (can be ignored for MsAccess)"); | |
| 107 | } | |
| 108 | } | |
| 109 | } | |
| 110 | ||
| 111 | /** | |
| 112 | * Answer the Character for Concatenation | |
| 113 | */ | |
| 114 | protected String getConcatenationCharacter() | |
| 115 | { | |
| 116 | return "&"; | |
| 117 | } | |
| 118 | ||
| 119 | /** | |
| 120 | * @see org.apache.ojb.broker.platforms.Platform#getEscapeClause(org.apache.ojb.broker.query.LikeCriteria) | |
| 121 | */ | |
| 122 | public String getEscapeClause(LikeCriteria aCriteria) | |
| 123 | { | |
| 124 | // TODO: implement ms-access escaping | |
| 125 | return ""; | |
| 126 | } | |
| 127 | } |