KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > client > ClientUserSession


1 package com.daffodilwoods.daffodildb.client;
2
3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.information.*;
4 import com.daffodilwoods.daffodildb.server.serversystem.*;
5 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*;
6 import com.daffodilwoods.database.general.*;
7 import com.daffodilwoods.database.resource.*;
8
9 public class ClientUserSession implements _ClientUserSession {
10
11    private _Connection connection;
12    _ClientUser clientUser;
13    _Client client;
14    private String JavaDoc databaseName;
15    private boolean browserType;
16    private String JavaDoc savePoinString;
17
18    public ClientUserSession(String JavaDoc databaseName, _Connection connection, _ClientUser user, _Client client0) {
19       this.connection = connection;
20       this.clientUser = user;
21       this.databaseName = databaseName;
22       client = client0;
23    }
24
25    public String JavaDoc toString() {
26       try {
27          return connection.getSessionConstant().toString();
28       } catch (DException ex) {
29          throw new RuntimeException JavaDoc(ex.getMessage());
30       }
31    }
32
33    public void commit() throws DException {
34       if (connection == null)
35          throw new DException("DSE279", null);
36       connection.commit();
37    }
38
39    public void rollBack() throws DException {
40       if (connection == null)
41          throw new DException("DSE279", null);
42       connection.rollback();
43    }
44
45    public Object JavaDoc execute(String JavaDoc string, Object JavaDoc[] objectArray) throws DException, java.sql.SQLException JavaDoc {
46       if (connection == null)
47          throw new DException("DSE279", null);
48       Object JavaDoc returnObject = null;
49       if (objectArray == null || objectArray.length == 0) {
50          returnObject = connection.execute(string, 0, IteratorConstants.UPDATABLE);
51       } else {
52          _PreparedStatement temp = connection.getPreparedStatement(string, IteratorConstants.UPDATABLE);
53          returnObject = temp.execute(objectArray);
54       }
55       if (returnObject instanceof _SelectIterator) {
56          _SelectIterator iterator = (_SelectIterator) returnObject;
57          boolean type = iterator.isUpdatable();
58          if (type) {
59             RecordSetBuffer rsb = new RecordSetBuffer();
60             rsb.setClientUserSession(this);
61             rsb.setSelectIterator(iterator);
62             rsb.setQuery(string);
63             rsb.setParameters(objectArray);
64             rsb.setListenerMode(browserType);
65             return rsb;
66          }
67          RecordSet rsb = new RecordSet();
68          rsb.setQuery(string);
69          rsb.setSelectIterator(iterator);
70          return rsb;
71       }
72       return returnObject;
73    }
74
75    public _DatabaseInformation getDatabaseInformation() throws DException {
76       return clientUser.getDatabaseInformation(databaseName);
77    }
78
79    public Object JavaDoc[] executeBatch(String JavaDoc string) throws DException, java.sql.SQLException JavaDoc {
80       if (connection == null)
81          throw new DException("DSE279", null);
82       return connection.executeBatch(string);
83    }
84
85    public void close() throws DException {
86       if (connection == null)
87          throw new DException("DSE279", null);
88       connection.close();
89       connection = null;
90    }
91
92    public Object JavaDoc executeQuery(String JavaDoc string, String JavaDoc string1, String JavaDoc string2, Object JavaDoc[] objectArray) throws java.sql.SQLException JavaDoc {
93       throw new UnsupportedOperationException JavaDoc("Method not supported");
94    }
95
96    public _ClientStatement getStatement(String JavaDoc query) throws java.sql.SQLException JavaDoc {
97       try {
98          if (connection == null)
99             throw new DException("DSE279", null);
100          _PreparedStatement preparedStatement = connection.getPreparedStatement(query, IteratorConstants.UPDATABLE);
101          ClientStatement clientStatement = new ClientStatement(query, preparedStatement, this);
102          clientStatement.connection = connection;
103          clientStatement.setClient(client);
104          clientStatement.setListenerMode(browserType);
105          return clientStatement;
106       } catch (DException ex) {
107          throw ex.getSqlException(null);
108       }
109    }
110
111    public boolean isDataModified() throws DException {
112       if (connection == null)
113          throw new DException("DSE279", null);
114       return connection.isDataModified();
115    }
116
117    public _ClientUserSession getChildSession() throws DException {
118
119       throw new UnsupportedOperationException JavaDoc(" getChildSession() method not supported ");
120    }
121
122    public void setAutoCommit(boolean autoCommit) throws DException {
123       if (connection == null)
124          throw new DException("DSE279", null);
125       connection.setAutoCommit(autoCommit);
126    }
127
128    /*public int getType() {
129      if(connection == null)
130        throw new DRuntimeException("DSE279",null);
131      return connection.getType();
132       }
133       public void setType(int type){
134      if(connection == null)
135        throw new DRuntimeException("DSE279",null);
136      connection.setType(type);
137       }*/

138
139    public void setIsolationLevel(int level) throws DException {
140       connection.setTransactionIsolation(level);
141    }
142
143    public _ClientStatement getStatement(String JavaDoc query, String JavaDoc parm2, String JavaDoc parm3) throws java.sql.SQLException JavaDoc {
144       throw new UnsupportedOperationException JavaDoc(" this method will be removed ");
145    }
146
147    public Object JavaDoc[] createDeepRecordCopy(QualifiedIdentifier tableName, Object JavaDoc[] keys) throws DException {
148       if (connection == null)
149          throw new DException("DSE279", null);
150       return connection.createDeepRecordCopy(tableName, keys);
151    }
152
153    public void startSavePoint() throws DException {
154       if (connection == null)
155          throw new DException("DSE279", null);
156       savePoinString = connection.setSavePoint();
157    }
158
159    public void commitSavePoint() throws DException {
160       if (connection == null)
161          throw new DException("DSE279", null);
162       connection.commitSavePoint();
163    }
164
165    public void rollbackSavePoint() throws DException {
166       if (connection == null)
167          throw new DException("DSE279", null);
168       if (savePoinString == null)
169          throw new DException("DSE0", new Object JavaDoc[] {"First start a savepoint."});
170       connection.rollbackSavePoint(savePoinString);
171    }
172
173    public void releaseSavePoint() throws DException {
174       if (connection == null)
175          throw new DException("DSE279", null);
176       if (savePoinString == null)
177          throw new DException("DSE0", new Object JavaDoc[] {"First start a savepoint."});
178       connection.releaseSavePoint(savePoinString);
179    }
180
181    public void setListenerMode(boolean browserType1) throws DException {
182       browserType = browserType1;
183    }
184
185    public _Connection getConnection() {
186       return connection;
187    }
188
189    public boolean isClosed() throws DException {
190       return connection.isClosed();
191    }
192 }
193
Popular Tags