Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

JDBC Exception during update. #23

Open
gonsan opened this issue Nov 19, 2014 · 4 comments
Open

JDBC Exception during update. #23

gonsan opened this issue Nov 19, 2014 · 4 comments

Comments

@gonsan
Copy link

gonsan commented Nov 19, 2014

Hello, I'm facing MySQL exception problem.

The exception is related with MySQL update query.
And this exception is occured at below line.
at com.bloidonia.vertx.mods.JdbcProcessor$5.process(JdbcProcessor.java:379)

The exception is this,
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'A' for key 'name'

JDBC will send exception when the query has some problem or we have some problem. but this module do not send error reply directly.
So I have to wait until timeout.

@timyates
Copy link
Owner

Do you have an example that reproduces this?

@gonsan
Copy link
Author

gonsan commented Nov 20, 2014

First, I made some field that use 'unique' keyword in my table.
So, It's not possible to make same value with different row.

here is simple example.

JsonObject request = new JsonObject();
final JsonArray statementArray = new JsonArray();
request.putString("action", "transaction");

eb.sendWithTimeout(JDBC_PERSISTER_ADDR, request, TIMEOUT, new Handler<AsyncResult<Message<JsonObject>>>() {
  @Override
  public void handle(AsyncResult<Message<JsonObject>> event) {
      if(event.result().body() == null) {
          handler.handle(TIMEOUT_JSON_OBJECT);
          return;
      }
      if(event.failed() || !"ok".equals(event.result().body().getString("status"))) {
          handler.handle(TIMEOUT_JSON_OBJECT);
          return;
      }
      sendTransaction(statementArray, 0, event, handler);
  }
});


private void sendTransaction(final JsonArray queryArray, final int count, AsyncResult<Message<JsonObject>> event, final Handler<JsonObject> originHandler) {
    event.result().replyWithTimeout(queryArray.get(count), TIMEOUT, new Handler<AsyncResult<Message<JsonObject>>>() {
        @Override
        public void handle(final AsyncResult<Message<JsonObject>> evnt) {            
            //rollback
            if(evnt.failed() || !"ok".equals(evnt.result().body().getString("status"))) {
                JsonObject request = new JsonObject();
                request.putString("action", "rollback");
                evnt.result().replyWithTimeout(request, TIMEOUT, new Handler<AsyncResult<Message<JsonObject>>>() {
                    @Override
                    public void handle(AsyncResult<Message<JsonObject>> event) {
                        if(event.failed() || !"ok".equals(event.result().body().getString("status"))) {
                            originHandler.handle(TIMEOUT_JSON_OBJECT);
                            return;
                        }
                        JsonObject dbJson = FAIL_JSON_OBJECT;
                        originHandler.handle(dbJson);
                    }
                });
                return;
            }
            if(queryArray.size() > count+1) {
                sendTransaction(queryArray, count+1, evnt, originHandler);
            } else {
                // commit
                JsonObject request = new JsonObject();
                request.putString("action", "commit");
                evnt.result().replyWithTimeout(request, TIMEOUT, new Handler<AsyncResult<Message<JsonObject>>>() {
                    @Override
                    public void handle(AsyncResult<Message<JsonObject>> event) {
                        if(event.failed() || !"ok".equals(event.result().body().getString("status"))) {
                            originHandler.handle(TIMEOUT_JSON_OBJECT);
                            return;
                        }
                        JsonObject dbJson = event.result().body();
                        originHandler.handle(dbJson);
                    }
                });
                return;
            }
        }
    });
}

@timyates
Copy link
Owner

I'll have a go at coming up with a simple failing example that I can run locally over the next few days.

So what happens with that code? You see an exception but it isn't returned from the module?

@gonsan
Copy link
Author

gonsan commented Nov 20, 2014

The exception is below,

First, the exception is occured and I didn't get any response before timeout.
So I have to wait until get timeout.
sequence is below,

  1. send query
  2. Exception is occured.
  3. transaction time is occured.
  4. this time I can get transaction timeout response from JDBC module.
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'ABCD' for key 'name'
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
        at com.mysql.jdbc.Util.getInstance(Util.java:360)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:971)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2141)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2077)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2062)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:1423)
        at com.bloidonia.vertx.mods.JdbcProcessor$5.process(JdbcProcessor.java:379)
        at com.bloidonia.vertx.mods.JdbcProcessor$BatchHandler.handle(JdbcProcessor.java:595)
        at com.bloidonia.vertx.mods.JdbcProcessor.doUpdate(JdbcProcessor.java:347)
        at com.bloidonia.vertx.mods.JdbcProcessor.access$1300(JdbcProcessor.java:47)
        at com.bloidonia.vertx.mods.JdbcProcessor$TransactionalHandler.handle(JdbcProcessor.java:468)
        at com.bloidonia.vertx.mods.JdbcProcessor$TransactionalHandler.handle(JdbcProcessor.java:439)
        at org.vertx.java.core.eventbus.impl.DefaultEventBus$11.run(DefaultEventBus.java:943)
        at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:175)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:744)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants