Exemple #1
0
  @Override
  public CloneableRecord get(
      ExecutionContext context, CloneableRecord key, IndexMeta indexMeta, String dbName) {

    DatabaseEntry keyEntry = new DatabaseEntry();
    DatabaseEntry valueEntry = new DatabaseEntry();
    keyEntry.setData(indexCodecMap.get(indexMeta.getName()).getKey_codec().encode(key));
    OperationStatus status =
        getDatabase(dbName)
            .get(
                context.getTransaction() == null
                    ? null
                    : ((JE_Transaction) context.getTransaction()).txn,
                keyEntry,
                valueEntry,
                LockMode.DEFAULT);
    if (OperationStatus.SUCCESS != status) {
      return null;
    }
    if (valueEntry.getSize() != 0) {
      return indexCodecMap.get(indexMeta.getName()).getValue_codec().decode(valueEntry.getData());
    } else {
      return null;
    }
  }
Exemple #2
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));
  }
Exemple #3
0
 @Override
 public ISchematicCursor getCursor(
     ExecutionContext executionContext, IndexMeta meta, IQuery iQuery) throws TddlException {
   String actualTable = iQuery.getTableName();
   return getCursor(
       executionContext.getTransaction(), meta, executionContext.getIsolation(), actualTable);
 }
Exemple #4
0
  @Override
  public void delete(
      ExecutionContext context, CloneableRecord key, IndexMeta indexMeta, String dbName)
      throws TddlException {

    DatabaseEntry keyEntry = new DatabaseEntry();
    keyEntry.setData(indexCodecMap.get(indexMeta.getName()).getKey_codec().encode(key));
    try {
      getDatabase(dbName)
          .delete(
              context.getTransaction() == null
                  ? null
                  : ((JE_Transaction) context.getTransaction()).txn,
              keyEntry);
    } catch (LockTimeoutException ex) {

      throw ex;
    } catch (ReplicaWriteException ex) {
      throw new TddlException(ExceptionErrorCodeUtils.Read_only, ex);
    }
  }
Exemple #5
0
  /**
   * todo:触发更新二级索引
   *
   * @param key
   * @param value
   * @throws TddlException
   */
  @Override
  public void put(
      ExecutionContext context,
      CloneableRecord key,
      CloneableRecord value,
      IndexMeta indexMeta,
      String dbName)
      throws TddlException {
    DatabaseEntry keyEntry = new DatabaseEntry();
    DatabaseEntry valueEntry = new DatabaseEntry();
    keyEntry.setData(indexCodecMap.get(indexMeta.getName()).getKey_codec().encode(key));

    // 当临时表排序时候可能会用到临时表join,主键插入值为null
    // if (keyEntry.getData().length == 1 && !isTempTable) {
    // throw new RuntimeException("pk must not null.");
    // }

    if (value != null) {
      valueEntry.setData(indexCodecMap.get(indexMeta.getName()).getValue_codec().encode(value));
    } else {
      valueEntry = emptyValueEntry;
    }
    try {
      ITransaction transaction = context.getTransaction();
      com.sleepycat.je.Transaction txn = null;
      if (transaction != null && transaction instanceof JE_Transaction) {
        txn = ((JE_Transaction) transaction).txn;
      }
      OperationStatus operationStatus = getDatabase(dbName).put(txn, keyEntry, valueEntry);
      if (operationStatus.equals(OperationStatus.SUCCESS)) {
        return;
      }
    } catch (LockTimeoutException ex) {

      throw ex;
    } catch (ReplicaWriteException ex) {
      throw new TddlException(ExceptionErrorCodeUtils.Read_only, ex);
    }
  }