如果我只获取值,是否需要使用 commit

Do I need to use commit if I am only getting values

我想检查数据库中是否存在用户。我需要使用 commit 吗?这段代码是获取值的正确方法吗?

val transaction: DistributedTransaction = transactionService.start
    logger.trace("transaction started: " + transaction);
    //Perform the operations you want to group in the transaction

    val pUserKey = new Key(new IntValue("bucket", utilities.bucketIDFromEmail(userKeys.bucket)),
      new TextValue("email", userKeys.email)
    )
    val cUserKey = new Key(
      new TextValue("authprovider", "credentials"),
      new TextValue("firstname", userKeys.firstName),
      new TextValue("lastname", userKeys.lastName)
    )
    logger.trace("created keys. ")
    logger.trace("getting user")
    val get:Get = new Get(pUserKey,cUserKey);

    val result:Optional[Result] = transaction.get(get);
    if(result.isPresent){
      logger.trace(s"found user ${result}")
    } else {
      logger.trace(s"user doesn't exist")
    }

    try {
      logger.trace(s"committing")
      transaction.commit()
    } catch {
      case e1:UnknownTransactionStatusException =>{
        logger.error("error in commiting. Unknowns status")
        throw e1;

      }
      case e2:CommitException =>{
        logger.error("error in commiting. Rolling back")
        transaction.abort();
        throw e2;
      }
    }

什么时候实际获取值?当我打电话给 transaction.get 或当我打电话给 transaction.commit?

是的,请始终在标量数据库中调用 commit

默认 SNAPSHOT 实际上不需要它,但 SERIALIZABLE 需要它,因此最好始终调用它。