01: package org.apache.ojb.broker.platforms;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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.sql.CallableStatement;
19: import java.sql.Connection;
20: import java.sql.Types;
21: import java.sql.SQLException;
22:
23: /**
24: * This class extends <code>PlatformDefaultImpl</code> and defines specific behavior for the
25: * Microsoft SQL Server platform.
26: *
27: * @version $Id: PlatformMsSQLServerImpl.java,v 1.8.2.3 2005/12/21 22:26:40 tomdz Exp $
28: */
29: public class PlatformMsSQLServerImpl extends PlatformDefaultImpl {
30: /**
31: * Get join syntax type for this RDBMS - one on of the constants from JoinSyntaxType interface
32: * MBAIRD: MS SQL Server 2000 actually supports both types, but due to a problem with the sql
33: * generator, we opt to have no parens.
34: */
35: public byte getJoinSyntaxType() {
36: return SQL92_NOPAREN_JOIN_SYNTAX;
37: }
38:
39: public CallableStatement prepareNextValProcedureStatement(
40: Connection con, String procedureName, String sequenceName)
41: throws PlatformException {
42: try {
43: String sp = "{?= call " + procedureName + " (?)}";
44: CallableStatement cs = con.prepareCall(sp);
45: cs.registerOutParameter(1, Types.INTEGER);
46: cs.setString(2, sequenceName);
47: return cs;
48: } catch (SQLException e) {
49: throw new PlatformException(e);
50: }
51: }
52:
53: public String getLastInsertIdentityQuery(String tableName) {
54: /*
55: More info about the used identity-query see JIRA OJB-77
56: http://issues.apache.org/jira/browse/OJB-77
57:
58: As suggested in OJB-77 the latest recommendation from MS was to
59: use function "SELECT SCOPE_IDENTITY()" to get the latest generated identity
60: for the current session and scope:
61: "SCOPE_IDENTITY and @@IDENTITY will return last identity values generated in
62: any table in the current session. However, SCOPE_IDENTITY returns values
63: inserted only within the current scope; @@IDENTITY is not limited to a
64: specific scope."
65: */
66: return "SELECT SCOPE_IDENTITY()";
67: }
68:
69: /**
70: * Answer the Character for Concatenation
71: */
72: protected String getConcatenationCharacter() {
73: return "+";
74: }
75:
76: }
|