1 2 24 25 package com.lutris.appserver.server.sessionEnhydra.persistent; 26 27 import java.sql.SQLException ; 28 29 import com.lutris.appserver.server.Enhydra; 30 import com.lutris.appserver.server.session.SessionException; 31 import com.lutris.appserver.server.sessionEnhydra.StandardSession; 32 import com.lutris.appserver.server.sessionEnhydra.StandardSessionManager; 33 import com.lutris.appserver.server.sql.DBQuery; 34 import com.lutris.appserver.server.sql.DBTransaction; 35 import com.lutris.appserver.server.sql.DatabaseManagerException; 36 import com.lutris.appserver.server.sql.Query; 37 38 46 class DBUtil { 47 48 60 static int dbUpdate(PersistentSession session, String dbName) 61 throws SessionException { 62 PersistentSessionDO sessionDO = new PersistentSessionDO(session); 63 try { 64 DBTransaction t = createTransaction(dbName); 65 try { 66 t.update(sessionDO); 67 t.commit(); 68 } catch (Exception e) { 69 t.rollback(); 70 throw e; 71 } finally { 72 t.release(); 73 } 74 } catch (Exception e) { 75 throw new SessionException(e); 76 } 77 return sessionDO.getTransactionRowCount(); 78 } 79 80 90 static void dbDelete(String sessionKey, String dbName) 91 throws SessionException { 92 try { 93 DBTransaction t = createTransaction(dbName); 94 SessionDeleteDO s = new SessionDeleteDO(sessionKey); 95 try { 96 t.delete(s); 97 t.commit(); 98 } catch (Exception e) { 99 t.rollback(); 100 throw e; 101 } finally { 102 t.release(); 103 } 104 } catch (Exception e) { 105 throw new SessionException(e); 106 } 107 } 108 109 119 static void dbInsert(PersistentSession session, String dbName) 120 throws SessionException { 121 try { 122 PersistentSessionDO sessionDO = new PersistentSessionDO(session); 123 DBTransaction t = createTransaction(dbName); 124 try { 125 t.insert(sessionDO); 126 t.commit(); 127 } catch (Exception e) { 128 t.rollback(); 129 throw e; 130 } finally { 131 t.release(); 132 } 133 } catch (Exception e) { 134 throw new SessionException(e); 135 } 136 } 137 138 148 static Object dbQuery(Query query, String dbName) throws SessionException { 149 try { 150 DBQuery q = createQuery(dbName); 151 try { 152 q.query(query); 153 return q.next(); 154 } catch (Exception e) { 155 throw e; 156 } finally { 157 q.release(); 158 } 159 } catch (Exception e) { 160 throw new SessionException(e); 161 } 162 } 163 164 172 static DBTransaction createTransaction(String dbName) 173 throws DatabaseManagerException, SQLException { 174 DBTransaction t; 175 if (dbName != null) { 176 t = Enhydra.getDatabaseManager().createTransaction(dbName); 177 } else { 178 t = Enhydra.getDatabaseManager().createTransaction(); 179 } 180 return t; 181 } 182 183 191 static DBQuery createQuery(String dbName) 192 throws DatabaseManagerException, SQLException { 193 DBQuery q; 194 if (dbName != null) { 195 q = Enhydra.getDatabaseManager().createQuery(dbName); 196 } else { 197 q = Enhydra.getDatabaseManager().createQuery(); 198 } 199 return q; 200 } 201 202 } 203 204 205 206 207 | Popular Tags |