2828 * Helper class to work with DataBase access.
2929 */
3030public class DataAccess {
31- private WebDavEngine engine ;
31+ private final WebDavEngine engine ;
3232 private Connection currentConnection ;
3333 private String defaultTableSpace ;
34- private long totalBytes ;
3534
3635 /**
3736 * Initialize {@link DataAccess} with {@link WebDavEngine}
@@ -41,12 +40,7 @@ public class DataAccess {
4140 */
4241 DataAccess (WebDavEngine engine ) {
4342 this .engine = engine ;
44- try {
45- defaultTableSpace = executeScalar ("SELECT DEFAULT_TABLESPACE FROM DBA_USERS WHERE USERNAME = (SELECT USER FROM dual)" );
46- totalBytes = getTotalBytesDB ();
47- } catch (Exception e ) {
48- engine .getLogger ().logError (e .getMessage (), e );
49- }
43+ engine .setDataAccess (this );
5044 }
5145
5246 private long getTotalBytesDB () {
@@ -90,9 +84,16 @@ private Connection getConnection() throws ServerException {
9084 /**
9185 * Returns default table space in which DB is stored.
9286 *
93- * @return Returns default table space in which DB is stored.
87+ * @return Default table space in which DB is stored.
9488 */
9589 String getDefaultTableSpace () {
90+ if (defaultTableSpace == null ) {
91+ try {
92+ defaultTableSpace = executeScalar ("SELECT DEFAULT_TABLESPACE FROM DBA_USERS WHERE USERNAME = (SELECT USER FROM dual)" );
93+ } catch (Exception e ) {
94+ engine .getLogger ().logError ("Cannot acquire defaultTableSpace" , e );
95+ }
96+ }
9697 return defaultTableSpace ;
9798 }
9899
@@ -102,7 +103,12 @@ String getDefaultTableSpace() {
102103 * @return Returns total bytes used by DB.
103104 */
104105 long getTotalBytes () {
105- return totalBytes ;
106+ try {
107+ return getTotalBytesDB ();
108+ } catch (Exception e ) {
109+ engine .getLogger ().logError ("Cannot acquire totalBytes" , e );
110+ }
111+ return 0 ;
106112 }
107113
108114 /**
@@ -114,6 +120,19 @@ void closeConnection() {
114120 currentConnection .close ();
115121 currentConnection = null ;
116122 }
123+ } catch (SQLException e ) {
124+ engine .getLogger ().logError ("Failed to close connection" , e );
125+ }
126+ }
127+
128+ /**
129+ * Rollbacks transaction.
130+ */
131+ void rollback () {
132+ try {
133+ if (currentConnection != null ) {
134+ currentConnection .rollback ();
135+ }
117136 } catch (SQLException e ) {
118137 engine .getLogger ().logError ("Failed to rollback connection" , e );
119138 }
0 commit comments