@Overridepublic void insertStart(RecordContext ctx) {DSL.using(ctx.configuration()).execute("...");}
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
public void executeStart(ExecuteContext ctx) {
if(ctx.query() instanceof Insert){
Connection connection = ctx.connection();
//TODO: figure out how to get the table name
String tableName="domain";
int batchSize = (ctx.batchQueries().length > 1) ? ctx.batchQueries().length : 1;
try {
connection.createStatement().execute("LOCK TABLE sequence WRITE");
ResultSet resultSet = connection.createStatement().executeQuery("SELECT value FROM sequence WHERE name='" + tableName + "'");
connection.createStatement().execute("INSERT INTO sequence (name, value) VALUES ("+ tableName +","+ batchSize +") ON DUPLICATE KEY UPDATE value=value+"+batchSize);
connection.createStatement().execute("UNLOCK TABLES");
Long id = null;
if(resultSet.isBeforeFirst()){
id = resultSet.getLong(0);
}
else{
id = 1l;
}
//TODO: figure out how to set the id value of the queries being executed, as well as batched statments
} catch (SQLException e) {
log.error("Error while trying to update sequence table", e);
}
}
if(ctx.batchQueries().length > 0 && ctx.batchQueries()[0] instanceof Insert){
Connection connection = ctx.connection();
try {
InsertQuery<?> query= (InsertQuery<?>) ctx.batchQueries()[0];
Field f = query.getClass().getSuperclass().getSuperclass().getDeclaredField("table");
f.setAccessible(true);
Table table = (Table) f.get(query);
String tableName = table.getName();
int batchSize = (ctx.batchQueries().length > 1) ? ctx.batchQueries().length : 1;
connection.createStatement().execute("LOCK TABLE sequence WRITE");
ResultSet resultSet = connection.createStatement().executeQuery("SELECT value FROM sequence WHERE name='" + tableName + "'");
connection.createStatement().execute("INSERT INTO sequence (name, value) VALUES ('"+ tableName +"',"+ batchSize +") ON DUPLICATE KEY UPDATE value=value+"+batchSize);
connection.createStatement().execute("UNLOCK TABLES");
Integer id = (resultSet.next()) ? resultSet.getInt(1) : 1;
for(Query batchedQuery: ctx.batchQueries()) {
Method method = batchedQuery.getClass().getDeclaredMethod("getValues");
method.setAccessible(true);
Map insertFields = (Map) method.invoke(query);
TableField primaryKey = (TableField) table.getPrimaryKey().getFields().get(0);
//create value
Class<?> cl = Class.forName("org.jooq.impl.Val");
//TODO: figure out how to get this to work
Object val = cl.getConstructor(Integer.class, DataType.class).newInstance(id, primaryKey.getDataType());
insertFields.putIfAbsent(primaryKey, val);
}
} catch (Exception e) {
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.