Beispiel #1
0
 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);
       }
     }
   }
 }
Beispiel #2
0
 @Override
 public DbFuture<PreparedUpdate> prepareUpdate(String sql) {
   checkClosed();
   final Request request = requestCreator.executePrepareUpdate(sql);
   queRequest(request);
   return (DbFuture<PreparedUpdate>) request.getToComplete();
 }
Beispiel #3
0
 @Override
 public DbFuture<Result> executeUpdate(String sql) {
   checkClosed();
   final Request request = requestCreator.executeUpdate(sql);
   queRequest(request);
   return (DbFuture) request.getToComplete();
 }
Beispiel #4
0
 @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();
   }
 }
Beispiel #5
0
 @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();
   }
 }
Beispiel #6
0
 public Request dequeRequest() {
   synchronized (lock) {
     final Request request = requestQueue.poll();
     if (logger.isDebugEnabled()) {
       logger.debug("Dequeued request: {}", request);
     }
     if (request.getRequest().wasCancelled()) {
       if (logger.isDebugEnabled()) {
         logger.debug("Request has been cancelled: {}", request);
       }
       return dequeRequest();
     }
     return request;
   }
 }
Beispiel #7
0
 @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;
   }
 }
Beispiel #8
0
 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"));
       }
     }
   }
 }
Beispiel #9
0
 public boolean unblockBy(Request nextRequest) {
   return blockingRequest.unblockBy(nextRequest);
 }