01: //** Copyright Statement ***************************************************
02: //The Salmon Open Framework for Internet Applications (SOFIA)
03: // Copyright (C) 1999 - 2002, Salmon LLC
04: //
05: // This program is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU General Public License version 2
07: // as published by the Free Software Foundation;
08: //
09: // This program is distributed in the hope that it will be useful,
10: // but WITHOUT ANY WARRANTY; without even the implied warranty of
11: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: // GNU General Public License for more details.
13: //
14: // You should have received a copy of the GNU General Public License
15: // along with this program; if not, write to the Free Software
16: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: //
18: // For more information please visit http://www.salmonllc.com
19: //** End Copyright Statement ***************************************************
20: package com.salmonllc.sql;
21:
22: import com.salmonllc.util.MessageLog;
23:
24: import java.sql.*;
25:
26: /**
27: * This type was created in VisualAge.
28: */
29: class DSDataSourceMSSQL extends DSDataSourceSybase {
30:
31: /**
32: * DSSybaseDataSource constructor comment.
33: */
34: public DSDataSourceMSSQL() {
35: super ();
36: }
37:
38: protected void populateAutoIncrementValue(DataStoreRow row,
39: DBConnection conn, int colNo) {
40: try {
41: Statement st = conn.createStatement();
42: ResultSet r = st
43: .executeQuery("SELECT @@IDENTITY AS New_ID");
44: if (r.next()) {
45: int colStat = row.getDSDataRow().getColumnStatus(colNo);
46: int rowStat = row.getDSDataRow().getRowStatus();
47: Object val = null;
48: if (row.getDataType(colNo) == DataStore.DATATYPE_LONG)
49: val = new Long(r.getLong(1));
50: else if (row.getDataType(colNo) == DataStore.DATATYPE_INT)
51: val = new Integer(r.getInt(1));
52: else if (row.getDataType(colNo) == DataStore.DATATYPE_SHORT)
53: val = new Short(r.getShort(1));
54:
55: row.setData(colNo, val);
56: row.getDSDataRow().setColumnStatus(colNo, colStat);
57: row.getDSDataRow().setRowStatus(rowStat);
58: }
59: r.close();
60: st.close();
61: } catch (Exception e) {
62: MessageLog.writeErrorMessage(
63: "Error getting last auto increment value", e, this);
64: }
65: }
66: }
|