示例#1
0
 private TempTable getTempTable(
     String tempTableID,
     Command command,
     BufferManager buffer,
     boolean delegate,
     boolean forUpdate,
     CommandContext context)
     throws TeiidProcessingException {
   final TempTable tempTable = tempTables.get(tempTableID);
   if (tempTable != null) {
     // isolate if needed
     if (forUpdate) {
       if (transactionMode == TransactionMode.ISOLATE_WRITES) {
         TransactionContext tc = context.getTransactionContext();
         if (tc != null) {
           TempTableSynchronization synch = getSynchronization(context);
           if (synch != null && synch.existingTables.contains(tempTable.getId())) {
             TempTable result = synch.tables.get(tempTableID);
             if (result == null) {
               synchronized (synch) {
                 if (synch.isCompleted()) {
                   throw new AssertionError("Expected active transaction"); // $NON-NLS-1$
                 }
                 if (!tempTable.getActive().compareAndSet(0, 1)) {
                   throw new TeiidProcessingException(
                       QueryPlugin.Event.TEIID30227,
                       QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30227, tempTableID));
                 }
                 synch.tables.put(tempTableID, tempTable.clone());
               }
             }
             return tempTable;
           }
         } else if (tempTable.getActive().get() != 0) {
           throw new TeiidProcessingException(
               QueryPlugin.Event.TEIID30227,
               QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30227, tempTableID));
         }
       }
     } else if (transactionMode == TransactionMode.ISOLATE_READS) {
       TransactionContext tc = context.getTransactionContext();
       if (tc != null && tc.getIsolationLevel() > Connection.TRANSACTION_READ_COMMITTED) {
         TempTableSynchronization synch = getSynchronization(context);
         if (synch != null) {
           TempTable result = synch.tables.get(tempTableID);
           if (result == null) {
             result = tempTable;
             synchronized (synch) {
               if (!synch.isCompleted()) {
                 synch.tables.put(tempTableID, tempTable);
                 result.getActive().getAndIncrement();
               }
             }
           }
           return result;
         }
       }
     }
     return tempTable;
   }
   if (delegate && this.parentTempTableStore != null) {
     return this.parentTempTableStore.getTempTable(
         tempTableID, command, buffer, delegate, forUpdate, context);
   }
   return null;
 }