use of io.mycat.newquery.SqlResult in project Mycat2 by MyCATApache.
the class XaTestSuite method beginDoubleTargetInsertCommit.
@Test
public void beginDoubleTargetInsertCommit(VertxTestContext testContext) throws Exception {
clearData();
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
baseXaSqlConnection.begin().onComplete(event -> {
Assertions.assertTrue(event.succeeded());
Future<NewMycatConnection> ds1 = baseXaSqlConnection.getConnection("ds1");
Future<NewMycatConnection> ds2 = baseXaSqlConnection.getConnection("ds2");
CompositeFuture all = CompositeFuture.join(ds1.compose(connection -> {
Future<SqlResult> future = connection.insert("INSERT INTO db1.travelrecord (id)\n" + " VALUES\n" + " (1);");
return future.compose(rowSet -> {
Assertions.assertEquals(1, rowSet.getAffectRows());
return Future.succeededFuture(connection);
});
}), ds2.compose(connection -> {
Future<SqlResult> future = connection.insert("INSERT INTO db1.travelrecord (id)\n" + " VALUES\n" + " (2);");
return future.compose(rowSet -> {
Assertions.assertEquals(1, rowSet.getAffectRows());
return Future.succeededFuture(connection);
});
}));
all.onComplete(event13 -> {
Assertions.assertTrue(event13.succeeded());
baseXaSqlConnection.commit().onComplete(event12 -> {
Assertions.assertTrue(event12.succeeded());
Assertions.assertFalse(baseXaSqlConnection.isInTransaction());
Future<NewMycatConnection> connectionFuture = baseXaSqlConnection.getConnection("ds2");
connectionFuture.compose(sqlConnection -> sqlConnection.query("select id from db1.travelrecord")).onComplete(event1 -> {
Assertions.assertTrue(event1.succeeded());
Assertions.assertEquals(1, event1.result().size());
testContext.completeNow();
});
});
});
});
}
use of io.mycat.newquery.SqlResult in project Mycat2 by MyCATApache.
the class ReceiverImpl method proxyProcedure.
@Override
public Future<Void> proxyProcedure(String sql, String targetName) {
targetName = dataContext.resolveDatasourceTargetName(targetName, true);
XaSqlConnection transactionSession = (XaSqlConnection) dataContext.getTransactionSession();
Future<NewMycatConnection> mySQLManagerConnection = transactionSession.getConnection(targetName);
Future<List<Object>> objectFuture = mySQLManagerConnection.flatMap(newMycatConnection -> {
Future<List<Object>> call = newMycatConnection.call(sql);
return (Future) call;
});
Future<List<Object>> rowBaseIteratorFuture = objectFuture.map(objects -> objects.stream().map(o -> {
if (o instanceof long[])
return o;
if (o instanceof SqlResult)
return ((SqlResult) o).toLongs();
if (o instanceof RowSet)
return ((RowSet) o).toRowBaseIterator();
throw new UnsupportedOperationException();
}).collect(Collectors.toList()));
return rowBaseIteratorFuture.flatMap(objectList -> {
if (objectList instanceof List) {
List list = (List) objectList;
int thisStmtResultSetSize = list.size();
int resultSetCounter = getResultSetCounter();
resetResultSetCounter(resultSetCounter + thisStmtResultSetSize - 1);
Future<Void> future = Future.succeededFuture();
for (Object o : list) {
if (o instanceof long[]) {
long[] r = (long[]) o;
future = future.flatMap(unused -> sendOk(r[0], r[1]));
} else if (o instanceof RowBaseIterator) {
RowBaseIterator rs = (RowBaseIterator) o;
future = future.flatMap(unused -> sendResultSet(rs));
}
return future;
}
}
throw new UnsupportedOperationException();
});
}
Aggregations