Beispiel #1
0
  @Override
  public ISchematicCursor getCursor(
      ExecutionContext executionContext, IndexMeta indexMeta, String actualTableName)
      throws TddlException {
    Database db = getDatabase(actualTableName);
    if (db == null) {
      throw new TddlException("table don't contains indexName:" + actualTableName);
    }
    ITransaction txn = executionContext.getTransaction();
    CursorConfig cc = CursorConfig.DEFAULT;
    LockMode lm = LockMode.DEFAULT;
    if (txn != null) {
      com.sleepycat.je.TransactionConfig _config = ((JE_Transaction) txn).config;
      if (_config.getReadUncommitted()) {
        cc = CursorConfig.READ_UNCOMMITTED;
        lm = LockMode.READ_UNCOMMITTED;
      } else if (_config.getReadCommitted()) {
        cc = CursorConfig.READ_COMMITTED;
        // lm = LockMode.READ_COMMITTED;
      }
    } else {

      cc = CursorConfig.READ_COMMITTED;
    }
    JE_Cursor je_cursor =
        new JE_Cursor(
            indexMeta, db.openCursor(txn == null ? null : ((JE_Transaction) txn).txn, cc), lm);
    if (txn != null) {
      ((JE_Transaction) txn).addCursor(je_cursor);
    }
    return new SchematicCursor(
        je_cursor, je_cursor.getiCursorMeta(), ExecUtils.getOrderBy(indexMeta));
  }
Beispiel #2
0
  @Override
  public Object compute(Object[] args, ExecutionContext ec) {
    if (ExecUtils.isNull(args[0])) {
      return null;
    }

    Integer index = DataType.IntegerType.convertFrom(args[0]);

    if (index < 1 || index > args.length - 1) {
      return null;
    }

    Object resEle = args[index];

    if (ExecUtils.isNull(resEle)) {
      return null;
    }

    return DataType.StringType.convertFrom(resEle);
  }
Beispiel #3
0
  @Override
  public Object compute(Object[] args, ExecutionContext ec) {
    for (Object arg : args) {
      if (ExecUtils.isNull(arg)) {
        return null;
      }
    }
    String str = DataType.StringType.convertFrom(args[0]);
    Integer len = DataType.IntegerType.convertFrom(args[1]);
    if (len < 0) {
      return "";
    }

    return str.substring(0, len);
  }
Beispiel #4
0
  @Override
  public Object compute(Object[] args, ExecutionContext ec) {
    for (Object arg : args) {
      if (ExecUtils.isNull(arg)) {
        return null;
      }
    }
    BigInteger bitsValue = DataType.BigIntegerType.convertFrom(args[0]);
    String bitsStringReverse = TStringUtil.reverse(bitsValue.toString(2));

    String on = DataType.StringType.convertFrom(args[1]);
    String off = DataType.StringType.convertFrom(args[2]);
    String sep = ",";
    if (args.length >= 4) {
      sep = DataType.StringType.convertFrom(args[3]);
    }

    Integer number_of_bits = 64;

    if (args.length >= 5) {
      number_of_bits = DataType.IntegerType.convertFrom(args[4]);
    }

    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < number_of_bits; i++) {
      if (i != 0) {
        sb.append(sep);
      }

      if (i < bitsStringReverse.length()) {
        if (bitsStringReverse.charAt(i) == '0') {
          sb.append(off);
        } else {
          sb.append(on);
        }
      } else {
        sb.append(off);
      }
    }

    return sb.toString();
  }
Beispiel #5
0
 public ISchematicCursor getCursor(
     ITransaction txn, IndexMeta indexMeta, String isolation, String actualTableName)
     throws TddlException {
   Database db = getDatabase(actualTableName);
   if (db == null) {
     throw new TddlException("table don't contains indexName:" + actualTableName);
   }
   CursorConfig cc = CursorConfig.DEFAULT;
   LockMode lm = LockMode.DEFAULT;
   if (txn != null) {
     com.sleepycat.je.TransactionConfig _config = ((JE_Transaction) txn).config;
     if (_config.getReadUncommitted()) {
       cc = CursorConfig.READ_UNCOMMITTED;
       lm = LockMode.READ_UNCOMMITTED;
     } else if (_config.getReadCommitted()) {
       cc = CursorConfig.READ_COMMITTED;
       // lm = LockMode.READ_COMMITTED;
     }
   } else {
     if (Isolation.READ_COMMITTED.equals(isolation)) {
       cc = CursorConfig.READ_COMMITTED;
       // lm = LockMode.READ_COMMITTED;//not support
     } else if (Isolation.READ_UNCOMMITTED.equals(isolation)) {
       cc = CursorConfig.READ_UNCOMMITTED;
       lm = LockMode.READ_UNCOMMITTED;
     } else if (Isolation.REPEATABLE_READ.equals(isolation)) {
       // default
     } else if (Isolation.SERIALIZABLE.equals(isolation)) {
       // txn_config
     }
   }
   JE_Cursor je_cursor =
       new JE_Cursor(
           indexMeta, db.openCursor(txn == null ? null : ((JE_Transaction) txn).txn, cc), lm);
   if (txn != null) {
     ((JE_Transaction) txn).addCursor(je_cursor);
   }
   return new SchematicCursor(
       je_cursor, je_cursor.getiCursorMeta(), ExecUtils.getOrderBy(indexMeta));
 }
Beispiel #6
0
  @Override
  public Object compute(Object[] args, ExecutionContext ec) {
    for (Object arg : args) {
      if (ExecUtils.isNull(arg)) {
        return null;
      }
    }
    String str = DataType.StringType.convertFrom(args[0]);
    Integer len = DataType.IntegerType.convertFrom(args[1]);
    String padStr = DataType.StringType.convertFrom(args[2]);

    if (len == str.length()) {
      return str;
    }

    if (len < 0) {
      return null;
    }
    if (len < str.length()) {
      return str.substring(0, len);
    }

    return TStringUtil.rightPad(str, len, padStr);
  }