001: /*
002: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package org.mandarax.jdbc.client;
020:
021: import java.sql.*;
022: import java.util.Map;
023:
024: import org.mandarax.jdbc.*;
025: import org.mandarax.jdbc.rpc.*;
026:
027: /**
028: * The mandarax jdbc client side connection implementation.
029: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
030: * @version 3.3.2 <29 December 2004>
031: * @since 3.0
032: */
033:
034: public class ConnectionImpl extends AbstractConnectionImpl implements
035: ClientObject {
036: private String id = null;
037: private Transport transport = null;
038: private DatabaseMetaData metaData = null;
039:
040: /**
041: * Constructor.
042: * @param url the database url
043: * @param transport the transport used
044: */
045: ConnectionImpl(String url, Transport transport) throws SQLException {
046: super (url);
047: this .transport = transport;
048: Call call = new Call(null, "CreateConnection",
049: new Object[] { url });
050: String serverId = (String) transport.perform(call);
051: id = serverId;
052: }
053:
054: /**
055: * Creates a Statement object for sending SQL statements to the database.
056: */
057: public Statement createStatement() throws SQLException {
058: Call call = new Call(id, "Connection_createStatement");
059: String id = (String) transport.perform(call);
060: StatementImpl stmnt = new StatementImpl(this , transport);
061: stmnt.setId(id);
062: return stmnt;
063: }
064:
065: /**
066: * Creates a PreparedStatement object for sending parameterized SQL statements to the database.
067: * @param sql an SQL statement that may contain one or more '?' IN parameter placeholders
068: */
069: public PreparedStatement prepareStatement(String sql)
070: throws SQLException {
071: Call call = new Call(id, "Connection_prepareStatement",
072: new Object[] { sql });
073: String id = (String) transport.perform(call);
074: PreparedStatementImpl stmnt = new PreparedStatementImpl(this ,
075: transport);
076: stmnt.setId(id);
077: return stmnt;
078: }
079:
080: /**
081: * Retrieves a DatabaseMetaData object that contains metadata about
082: * the database.
083: * @return the database meta data
084: */
085: public DatabaseMetaData getMetaData() throws SQLException {
086: return new DatabaseMetaDataImpl(url, this , transport);
087: }
088:
089: /**
090: * Set the id.
091: * @param id an id
092: */
093: public void setId(String id) {
094: this .id = id;
095: }
096:
097: /**
098: * Get the id.
099: * @return an id
100: */
101: public String getId() {
102: return id;
103: }
104:
105: /**
106: * Close the connection.
107: * @throws java.sql.SQLException
108: */
109: public void close() throws SQLException {
110: transport.perform(new Call(id, "Close"));
111: }
112:
113: // Java 1.5
114: public void setTypeMap(Map/*<String,Class<?>>*/map) {
115:
116: }
117: }
|