KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > dbms > microsoft > SQS2000Connection


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mapper.dbms.microsoft;
24
25 import java.sql.*;
26
27 import org.xquark.jdbc.typing.DBMSInfo;
28 import org.xquark.mapper.RepositoryException;
29 import org.xquark.mapper.dbms.JDBC2Connection;
30
31 /**
32  * Implementation of AbstractConnection for Microsoft SQL Server 2000.
33  *
34  */

35 public class SQS2000Connection extends JDBC2Connection
36 {
37     private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
38     private static final String JavaDoc RCSName = "$Name: $";
39
40     
41     /** Creates new SQS2000Connection */
42     public SQS2000Connection(Connection connection, short dbms, DBMSInfo dbmsInfo)
43     throws SQLException
44     {
45         super(connection, dbms, dbmsInfo);
46     }
47
48     protected void setSchemaName() throws SQLException
49     {
50         Statement stmt = null;
51         try {
52             stmt = connection.createStatement();
53             ResultSet rs = stmt.executeQuery("select CURRENT_USER"); // user_name() works too
54
if (rs.next())
55                 schemaName = rs.getString(1);
56             rs.close();
57         }
58         finally {
59             stmt.close();
60         }
61     }
62
63     ///////////////////////////////////////////////////////////////
64
// Table methods
65
///////////////////////////////////////////////////////////////
66
public void dropTemporaryTable(String JavaDoc tableName) throws SQLException
67     {
68         super.dropTemporaryTable("#" + tableName);
69     }
70     
71     public String JavaDoc getDeleteUserTableRowsStatement(String JavaDoc tableName, String JavaDoc documentRowsSelectionClause)
72     throws SQLException, RepositoryException
73     {
74         StringBuffer JavaDoc deletionStmt = new StringBuffer JavaDoc();
75         deletionStmt.append("DELETE ");
76         deletionStmt.append(tableName);
77         deletionStmt.append(' ');
78         deletionStmt.append(documentRowsSelectionClause);
79         // IF PROBLEM, USE the syntax DELETE A FROM A INNER JOIN B ON A.ID=B.ID WHERE B BETWEEN X AND Y
80

81         return deletionStmt.toString();
82     }
83     
84     // TO IMPLEMENT ? public String getPathIndexStatement()
85

86     public boolean useStringDelimitor()
87     {
88         return false;
89         // COULD BE FALSE IF "SET ANSI_DEFAULTS ON" was called : TO DO
90
// COULD be controlled for generic and extra (user data (mapping) does not use this flag)
91
}
92
93     public void onInitConnection() throws SQLException
94     {
95         executeUpdate("SET ANSI_DEFAULTS ON");
96     }
97
98     ///////////////////////////////////////////////////////////////
99
// Private utilities
100
///////////////////////////////////////////////////////////////
101
// TO IMPLEMENT ? public void updateStatistics(String tableName) throws SQLException
102

103 }
104
Popular Tags