0
이렇게 처리 할 수있는 기능이 있습니까? Java vertx java
기존 이메일이있는 경우 사용자 을 추가하지 마십시오. 기존 이메일이없는 경우 사용자를 추가하십시오.
하나의 API가 모든 것을 처리하므로 두 API, User API 및 Database API로 API를 분리하려고합니다.
내가
"쿼리"와 같은 JSON을 사용하여 쿼리를 보낼 경우
["SELECT * FROM USER WHERE email='" + email + "'",
"INSERT INTO USER VALUES('" + email + "', '" + name + "', '" + password + "')"]
및 데이터베이스 API가 동시에 그 쿼리를 처리해야합니다. SELECT
에서 결과가 있다면
는 INSERT
vertx에서 어떤 해결책이 있나요, INSERT
그렇지 않은 경우에는하지 않는합니까?
미리 감사드립니다.
connection.query("SELECT * FROM USER WHERE email='" + email + "'", rs -> {
if(!rs.result().getResults().isEmpty()) {
handler.handle(Future.failedFuture("email already exists"));
} else {
connection.execute("INSERT INTO USER VALUES('" + email + "', '" + name + "', '" + password + "')", ins -> {
if (ins.failed()) {
throw new RuntimeException(ins.cause());
}
// and close the connection
connection.close(done -> {
if (done.failed()) {
throw new RuntimeException(done.cause());
}
});
});
handler.handle(Future.succeededFuture(new JsonObject().put("result", "succeed")));
}
});