@@ -96,7 +96,13 @@ protected Object clone() throws CloneNotSupportedException {
96
96
@ Override
97
97
@ SuppressWarnings ("rawtypes" )
98
98
public void createTable (Class <?> cls ) {
99
- mainConnLock .acquireUninterruptibly ();
99
+ try {
100
+ if (!mainConnLock .tryAcquire (10 , TimeUnit .SECONDS )) {
101
+ throw new IllegalStateException ();
102
+ }
103
+ } catch (InterruptedException e ) {
104
+ throw new RuntimeException (e );
105
+ }
100
106
try {
101
107
Validate .notNull (cls );
102
108
if (createdTableClasses .contains (cls )) return ;
@@ -150,27 +156,27 @@ public void rollbackTransaction() {
150
156
@ Override
151
157
public <T > SynchronizedQuery .TransactionalQuery <T > queryTransactional (Class <T > tableClass ) {
152
158
Connection conn ;
153
- try {
154
- createTable (tableClass );
155
- conn = getConnection ();
156
- conn .setAutoCommit (false );
157
- } catch (Throwable ex ) {
158
- mainConnLock .release ();
159
- throw new RuntimeException (ex );
160
- }
159
+ createTable (tableClass );
161
160
try {
162
161
if (!mainConnLock .tryAcquire (10 , TimeUnit .SECONDS )) {
163
162
throw new IllegalStateException ();
164
163
}
165
164
} catch (InterruptedException e ) {
166
165
throw new RuntimeException (e );
167
166
}
167
+ try {
168
+ conn = getConnection ();
169
+ conn .setAutoCommit (false );
170
+ } catch (Throwable ex ) {
171
+ mainConnLock .release ();
172
+ throw new RuntimeException (ex );
173
+ }
168
174
SQLiteQuery <T > sqliteQuery = new SQLiteQuery <>(tableClass , conn , logger );
169
175
FinalizablePhantomReference <SynchronizedQuery .TransactionalQuery <T >> reference = new FinalizablePhantomReference <SynchronizedQuery .TransactionalQuery <T >>(sqliteQuery , frq ) {
170
176
public void finalizeReferent () {
171
177
Semaphore lock = references .remove (this );
172
178
if (lock != null ) {
173
- logger .severe ("Unhandled TransactionalQuery found" );
179
+ logger .severe ("Unhandled TransactionalQuery found: " + this );
174
180
try {
175
181
if (conn .isValid (1 ) && !conn .getAutoCommit ()) {
176
182
conn .rollback ();
@@ -180,7 +186,7 @@ public void finalizeReferent() {
180
186
logger .log (Level .SEVERE , "Bad connection!" , e );
181
187
}
182
188
dbConn = null ;
183
- dbConn = newConnection ();
189
+ dbConn = createConnection ();
184
190
lock .release ();
185
191
}
186
192
}
0 commit comments