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 databaseName; 15 private boolean browserType; 16 private String savePoinString; 17 18 public ClientUserSession(String 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 toString() { 26 try { 27 return connection.getSessionConstant().toString(); 28 } catch (DException ex) { 29 throw new RuntimeException (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 execute(String string, Object [] objectArray) throws DException, java.sql.SQLException { 46 if (connection == null) 47 throw new DException("DSE279", null); 48 Object 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 [] executeBatch(String string) throws DException, java.sql.SQLException { 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 executeQuery(String string, String string1, String string2, Object [] objectArray) throws java.sql.SQLException { 93 throw new UnsupportedOperationException ("Method not supported"); 94 } 95 96 public _ClientStatement getStatement(String query) throws java.sql.SQLException { 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 (" 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 138 139 public void setIsolationLevel(int level) throws DException { 140 connection.setTransactionIsolation(level); 141 } 142 143 public _ClientStatement getStatement(String query, String parm2, String parm3) throws java.sql.SQLException { 144 throw new UnsupportedOperationException (" this method will be removed "); 145 } 146 147 public Object [] createDeepRecordCopy(QualifiedIdentifier tableName, Object [] 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 [] {"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 [] {"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 |