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.CallableStatement;
019    import java.sql.Connection;
020    import java.sql.Types;
021    import java.sql.SQLException;
022    
023    /**
024     * This class extends <code>PlatformDefaultImpl</code> and defines specific behavior for the
025     * Microsoft SQL Server platform.
026     * 
027     * @version $Id: PlatformMsSQLServerImpl.java,v 1.1 2007-08-24 22:17:35 ewestfal Exp $
028     */
029    public class PlatformMsSQLServerImpl extends PlatformDefaultImpl
030    {
031        /**
032         * Get join syntax type for this RDBMS - one on of the constants from JoinSyntaxType interface
033         * MBAIRD: MS SQL Server 2000 actually supports both types, but due to a problem with the sql
034         * generator, we opt to have no parens.
035         */
036        public byte getJoinSyntaxType()
037        {
038            return SQL92_NOPAREN_JOIN_SYNTAX;
039        }
040    
041        public CallableStatement prepareNextValProcedureStatement(Connection con, String procedureName,
042                String sequenceName) throws PlatformException
043        {
044            try
045            {
046                String sp = "{?= call " + procedureName + " (?)}";
047                CallableStatement cs = con.prepareCall(sp);
048                cs.registerOutParameter(1, Types.INTEGER);
049                cs.setString(2, sequenceName);
050                return cs;
051            }
052            catch (SQLException e)
053            {
054                throw new PlatformException(e);
055            }
056        }
057    
058        public String getLastInsertIdentityQuery(String tableName)
059        {
060            /*
061            More info about the used identity-query see JIRA OJB-77
062            http://issues.apache.org/jira/browse/OJB-77
063    
064            As suggested in OJB-77 the latest recommendation from MS was to
065            use function "SELECT SCOPE_IDENTITY()" to get the latest generated identity
066            for the current session and scope:
067            "SCOPE_IDENTITY and @@IDENTITY will return last identity values generated in
068            any table in the current session. However, SCOPE_IDENTITY returns values
069            inserted only within the current scope; @@IDENTITY is not limited to a
070            specific scope."
071            */
072            return "SELECT SCOPE_IDENTITY()";
073        }
074    
075        /**
076         * Answer the Character for Concatenation
077         */
078        protected String getConcatenationCharacter()
079        {
080            return "+";
081        }
082    
083    }