コード例 #1
0
ファイル: H2Connection.java プロジェクト: taojiaenx/tjeadbc
 public void forceQueRequest(Request request) {
   synchronized (lock) {
     if (blockingRequest == null) {
       requestQueue.add(request);
       channel.writeAndFlush(request.getRequest());
       if (request.isBlocking()) {
         blockingRequest = new BlockingRequestInProgress(request);
         request
             .getToComplete()
             .addListener(
                 new DbListener<Object>() {
                   @Override
                   public void onCompletion(DbFuture<Object> future) {
                     blockingRequest.continueWithRequests();
                   }
                 });
       }
     } else {
       if (blockingRequest.unblockBy(request)) {
         requestQueue.add(request);
         channel.writeAndFlush(request.getRequest());
       } else {
         blockingRequest.add(request);
       }
     }
   }
 }
コード例 #2
0
ファイル: H2Connection.java プロジェクト: taojiaenx/tjeadbc
 @Override
 public DbFuture<PreparedUpdate> prepareUpdate(String sql) {
   checkClosed();
   final Request request = requestCreator.executePrepareUpdate(sql);
   queRequest(request);
   return (DbFuture<PreparedUpdate>) request.getToComplete();
 }
コード例 #3
0
ファイル: H2Connection.java プロジェクト: taojiaenx/tjeadbc
 @Override
 public DbFuture<Result> executeUpdate(String sql) {
   checkClosed();
   final Request request = requestCreator.executeUpdate(sql);
   queRequest(request);
   return (DbFuture) request.getToComplete();
 }
コード例 #4
0
ファイル: H2Connection.java プロジェクト: taojiaenx/tjeadbc
 private void forceCloseOnPendingRequests() {
   for (Request request : requestQueue) {
     if (request.getRequest().tryCancel()) {
       request
           .getToComplete()
           .trySetException(new DbSessionClosedException("Connection is closed"));
     }
   }
   if (null != blockingRequest) {
     for (Request waitingRequest : blockingRequest.waitingRequests) {
       if (waitingRequest.getRequest().tryCancel()) {
         waitingRequest
             .getToComplete()
             .trySetException(new DbSessionClosedException("Connection is closed"));
       }
     }
   }
 }
コード例 #5
0
ファイル: H2Connection.java プロジェクト: taojiaenx/tjeadbc
 @Override
 public <T> DbFuture<T> executeQuery(String sql, ResultHandler<T> eventHandler, T accumulator) {
   checkClosed();
   synchronized (lock) {
     final Request request = requestCreator.createQuery(sql, eventHandler, accumulator);
     queRequest(request);
     return (DbFuture<T>) request.getToComplete();
   }
 }
コード例 #6
0
ファイル: H2Connection.java プロジェクト: taojiaenx/tjeadbc
 @Override
 public DbFuture<Void> rollback() {
   checkClosed();
   synchronized (lock) {
     if (!isInTransaction()) {
       throw new DbException("Not currently in a transaction, cannot rollback");
     }
     final Request request = requestCreator.rollbackTransaction();
     queRequest(request);
     isInTransaction = false;
     return (DbFuture<Void>) request.getToComplete();
   }
 }
コード例 #7
0
ファイル: H2Connection.java プロジェクト: taojiaenx/tjeadbc
 @Override
 public DbFuture<Void> close(CloseMode closeMode) throws DbException {
   synchronized (lock) {
     if (this.closeFuture != null) {
       return closeFuture;
     }
     if (closeMode == CloseMode.CANCEL_PENDING_OPERATIONS) {
       forceCloseOnPendingRequests();
     }
     Request request = requestCreator.createCloseRequest();
     forceQueRequest(request);
     closeFuture = (DefaultDbFuture<Void>) request.getToComplete();
     closeFuture.addListener(
         new DbListener<Void>() {
           @Override
           public void onCompletion(DbFuture<Void> future) {
             H2Connection.this.manager.removeConnection(H2Connection.this);
           }
         });
     return closeFuture;
   }
 }