Example #1
0
 private CommonTree parse(String preparedSql) {
   CommonTree result = null;
   ANTLRNoCaseStringStream inputStream = new ANTLRNoCaseStringStream(preparedSql);
   MySQL51Lexer lexer = new MySQL51Lexer(inputStream);
   CommonTokenStream tokens = new CommonTokenStream(lexer);
   lexer.setErrorListener(new QueuingErrorListener(lexer));
   tokens.getTokens();
   if (lexer.getErrorListener().hasErrors()) {
     logger.warn(local.message("ERR_Lexing_SQL", preparedSql));
     return result;
   }
   PlaceholderNode.resetId();
   MySQL51Parser parser = new MySQL51Parser(tokens);
   parser.setTreeAdaptor(mySQLTreeAdaptor);
   parser.setErrorListener(new QueuingErrorListener(parser));
   try {
     CommonTree stmtTree = (CommonTree) parser.statement().getTree();
     result = stmtTree;
   } catch (RecognitionException e) {
     logger.warn(local.message("ERR_Parsing_SQL", preparedSql));
   }
   if (parser.getErrorListener().hasErrors()) {
     logger.warn(local.message("ERR_Parsing_SQL", preparedSql));
   }
   return result;
 }
Example #2
0
 private void assertReady() {
   if (!ready) {
     if (statementInterceptor == null) {
       throw new ClusterJUserException(local.message("ERR_No_Statement_Interceptor"));
     }
     if (connectionLifecycleInterceptor == null) {
       throw new ClusterJUserException(local.message("ERR_No_Connection_Lifecycle_Interceptor"));
     }
   } else {
     if (sessionFactory == null) {
       sessionFactory = ClusterJHelper.getSessionFactory(properties);
     }
   }
 }
 public void equalLong(Column storeColumn, long value) {
   try {
     ndbOperation.equalLong(storeColumn.getName(), value);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public void setNull(Column storeColumn) {
   try {
     ndbOperation.setNull(storeColumn.getName());
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public void setDatetime(Column storeColumn, Timestamp value) {
   try {
     ndbOperation.setDatetime(storeColumn.getName(), value);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public Blob getBlobHandle(Column storeColumn) {
   try {
     return new BlobImpl(ndbOperation.getBlobHandle(storeColumn.getName()));
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public void setByte(Column storeColumn, byte value) {
   try {
     ndbOperation.setInt(storeColumn.getName(), (int) value);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
Example #8
0
 public byte[] getBytes(Column storeColumn) {
   int index = storeColumn.getColumnId();
   NdbRecAttr ndbRecAttr = ndbRecAttrs[index];
   if (ndbRecAttr.isNULL() == 1) return null;
   int prefixLength = storeColumn.getPrefixLength();
   int actualLength = lengths[index];
   int offset = offsets[index];
   switch (prefixLength) {
     case 0:
       break;
     case 1:
       actualLength = (byteBuffer.get(offset) + 256) % 256;
       offset += 1;
       break;
     case 2:
       actualLength = (byteBuffer.get(offset) + 256) % 256;
       int length2 = (byteBuffer.get(offset + 1) + 256) % 256;
       actualLength += 256 * length2;
       offset += 2;
       break;
     default:
       throw new ClusterJFatalInternalException(
           local.message("ERR_Invalid_Prefix_Length", prefixLength));
   }
   byteBuffer.position(offset);
   byte[] result = new byte[actualLength];
   byteBuffer.get(result);
   return result;
 }
Example #9
0
  public String getString(Column storeColumn) {
    int index = storeColumn.getColumnId();
    NdbRecAttr ndbRecAttr = ndbRecAttrs[index];
    if (ndbRecAttr.isNULL() == 1) return null;
    int prefixLength = storeColumn.getPrefixLength();
    int actualLength;
    int offset = offsets[index];
    byteBuffer.limit(byteBuffer.capacity());
    switch (prefixLength) {
      case 0:
        actualLength = lengths[index];
        break;
      case 1:
        actualLength = (byteBuffer.get(offset) + 256) % 256;
        offset += 1;
        break;
      case 2:
        actualLength = (byteBuffer.get(offset) + 256) % 256;
        int length2 = (byteBuffer.get(offset + 1) + 256) % 256;
        actualLength += 256 * length2;
        offset += 2;
        break;
      default:
        throw new ClusterJFatalInternalException(
            local.message("ERR_Invalid_Prefix_Length", prefixLength));
    }

    byteBuffer.position(offset);
    byteBuffer.limit(offset + actualLength);

    String result = Utility.decode(byteBuffer, storeColumn.getCharsetNumber(), bufferManager);
    byteBuffer.clear();
    return result;
  }
 public void equalByte(Column storeColumn, byte b) {
   try {
     ndbOperation.equalInt(storeColumn.getName(), (int) b);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public void equalTime(Column storeColumn, Time value) {
   try {
     Timestamp timestamp = new Timestamp(((Time) value).getTime());
     ndbOperation.equalDatetime(storeColumn.getName(), timestamp);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 /** Return a buffer to the pool. */
 public void returnBuffer(ByteBuffer buffer) {
   //        checkGuard(buffer, "returnBuffer"); // uncomment this to enable checking
   if (buffer.capacity() != bufferSize + guard.length) {
     String message =
         local.message(
             "ERR_Wrong_Buffer_Size_Returned_To_Pool", name, bufferSize, buffer.capacity());
     throw new ClusterJFatalInternalException(message);
   }
   pool.add(buffer);
 }
 public void setString(Column storeColumn, String value) {
   ByteBuffer stringStorageBuffer = Utility.encode(value, storeColumn, bufferManager);
   int length = stringStorageBuffer.remaining() - storeColumn.getPrefixLength();
   if (length > storeColumn.getLength()) {
     throw new ClusterJUserException(
         local.message(
             "ERR_Data_Too_Long", storeColumn.getName(), storeColumn.getLength(), length));
   }
   int returnCode = ndbOperation.setValue(storeColumn.getColumnId(), stringStorageBuffer);
   bufferManager.clearStringStorageBuffer();
   handleError(returnCode, ndbOperation);
 }
 public void setBytes(Column storeColumn, byte[] value) {
   // TODO use the string storage buffer instead of allocating a new buffer for each value
   int length = value.length;
   if (length > storeColumn.getLength()) {
     throw new ClusterJUserException(
         local.message(
             "ERR_Data_Too_Long", storeColumn.getName(), storeColumn.getLength(), length));
   }
   ByteBuffer buffer = Utility.convertValue(storeColumn, value);
   int returnCode = ndbOperation.setValue(storeColumn.getColumnId(), buffer);
   handleError(returnCode, ndbOperation);
 }
Example #15
0
 public void setProperty(PropertyImpl property) {
   if (this.property != null && this.property.fmd.getType() != property.fmd.getType()) {
     throw new ClusterJUserException(
         local.message(
             "ERR_Multiple_Parameter_Usage",
             parameterName,
             this.property.fmd.getType().getName(),
             property.fmd.getType().getName()));
   } else {
     this.property = property;
   }
 }
Example #16
0
 /**
  * Return the interceptor for the statement interceptor callbacks.
  *
  * @param statementInterceptor the statement interceptor
  * @param connection the connection
  * @param properties the connection properties
  * @return the interceptor delegate
  */
 public static InterceptorImpl getInterceptorImpl(
     StatementInterceptor statementInterceptor, Connection connection, Properties properties) {
   InterceptorImpl result = getInterceptorImpl(connection, properties);
   if (result.statementInterceptor != null) {
     throw new ClusterJUserException(local.message("ERR_Duplicate_Statement_Interceptor"));
   }
   result.statementInterceptor = statementInterceptor;
   if (result.connectionLifecycleInterceptor != null) {
     result.ready = true;
   }
   return result;
 }
 private int convertBoundType(BoundType type) {
   switch (type) {
     case BoundEQ:
       return NdbIndexScanOperation.BoundType.BoundEQ;
     case BoundGE:
       return NdbIndexScanOperation.BoundType.BoundGE;
     case BoundGT:
       return NdbIndexScanOperation.BoundType.BoundGT;
     case BoundLE:
       return NdbIndexScanOperation.BoundType.BoundLE;
     case BoundLT:
       return NdbIndexScanOperation.BoundType.BoundLT;
     default:
       throw new ClusterJFatalInternalException(
           local.message("ERR_Implementation_Should_Not_Occur"));
   }
 }
 /** Check the guard */
 void checkGuard(ByteBuffer buffer, String where) {
   buffer.clear();
   boolean fail = false;
   // the buffer has guard.length extra bytes in it, initialized with the guard bytes
   buffer.position(buffer.capacity() - guard.length);
   for (int i = 0; i < guard.length; ++i) {
     byte actual = buffer.get();
     byte expected = guard[i];
     if (expected != actual) {
       fail = true;
       logger.warn(
           local.message(
               "WARN_Buffer_Pool_Guard_Check_Failed",
               where,
               (buffer.capacity() - guard.length),
               expected,
               actual,
               buffer.toString()));
     }
   }
   // reset it for next time
   initializeGuard(buffer);
 }
Example #19
0
 public Predicate lessEqual(PredicateOperand other) {
   throw new UnsupportedOperationException(local.message("ERR_NotImplemented"));
 }
Example #20
0
 public Predicate between(PredicateOperand lower, PredicateOperand upper) {
   throw new UnsupportedOperationException(local.message("ERR_NotImplemented"));
 }
Example #21
0
 public Object getObject(Column storeColumn) {
   throw new ClusterJFatalInternalException(local.message("ERR_Implementation_Should_Not_Occur"));
 }
Example #22
0
 public Predicate isNotNull() {
   throw new UnsupportedOperationException(local.message("ERR_NotImplemented"));
 }
Example #23
0
 public boolean wasNull(Column storeColumn) {
   throw new ClusterJFatalInternalException(local.message("ERR_Implementation_Should_Not_Occur"));
 }
 public void equalBoolean(Column storeColumn, boolean booleanValue) {
   throw new UnsupportedOperationException(local.message("ERR_NotImplemented"));
 }
Example #25
0
 public boolean[] getBooleans(Column storeColumn) {
   throw new ClusterJFatalInternalException(local.message("ERR_Not_Implemented"));
 }