001    package org.apache.ojb.broker.platforms;
002    
003    /* Copyright 2002-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    import java.sql.PreparedStatement;
019    import java.sql.SQLException;
020    import java.sql.Types;
021    
022    /**
023     * This class defines specific behavior for the Derby platform.
024     */
025    public class PlatformDerbyImpl extends PlatformDefaultImpl
026    {
027        /**
028         * {@inheritDoc}
029         */
030        public byte getJoinSyntaxType()
031        {
032            return SQL92_NOPAREN_JOIN_SYNTAX;
033        }
034    
035        /**
036         * {@inheritDoc}
037         */
038        public boolean supportsMultiColumnCountDistinct()
039        {
040            // Currently Derby supports COUNT DISTINCT only for one column
041            return false;
042        }
043    
044        /**
045         * {@inheritDoc}
046         */
047        public void setObjectForStatement(PreparedStatement ps, int index, Object value, int jdbcType) throws SQLException
048        {
049            if (((jdbcType == Types.CHAR) || (jdbcType == Types.VARCHAR)) &&
050                (value instanceof Character))
051            {
052                // [tomdz]
053                // Currently, Derby doesn't like Character objects in the PreparedStatement
054                // when using PreparedStatement#setObject(index, value, jdbcType) method
055                // (see issue DERBY-773)
056                // So we make a String object out of the Character object and use that instead
057                super.setObjectForStatement(ps, index, value.toString(), jdbcType);
058            }
059            else
060            {
061                super.setObjectForStatement(ps, index, value, jdbcType);
062            }
063        }
064    
065        /**
066         * {@inheritDoc}
067         */
068        public String getLastInsertIdentityQuery(String tableName)
069        {
070            // matthias.roth@impart.ch
071            // the function is used by the org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl
072                    // this call must be made before commit the insert command, so you
073            // must turn off autocommit by seting the useAutoCommit="2"
074            // or use useAutoCommit="1" or use a connection with autoCommit set false
075            // by default (e.g. in managed environments)
076            // transaction demarcation is mandatory
077            return "values IDENTITY_VAL_LOCAL()";
078        }
079    }