@Override public void putMetadataForTables(final Map<TableReference, byte[]> tableRefToMetadata) { if (tableRefToMetadata.isEmpty()) { return; } run((Function<DSLContext, Void>) ctx -> { Query query = ctx .update(METADATA_TABLE) .set(METADATA, (byte[]) null) .where(TABLE_NAME.eq((String) null)); BatchBindStep batch = ctx.batch(query); for (Entry<TableReference, byte[]> entry : tableRefToMetadata.entrySet()) { batch = batch.bind(entry.getValue(), entry.getKey().getQualifiedName()); } batch.execute(); return null; }); }
@Override public Batch batch( Collection<? extends Query> queries) { return delegate.batch(queries); }
@Override public Batch batch(Query query, Object[]... bindings) { return delegate.batch(query, bindings); }
@Override public Batch batch(Queries queries) { return delegate.batch(queries); }
@Override public Batch batch(String... queries) { return delegate.batch(queries); }
@Override public BatchBindStep batch(Query query) { return delegate.batch(query); }
@Override public BatchBindStep batch(String sql) { return delegate.batch(sql); }
@Override public Batch batch(Query... queries) { return delegate.batch(queries); }
@Override public Batch batch(String sql, Object[]... bindings) { return delegate.batch(sql, bindings); }
public boolean executeQuery(final DSLContext dslContext, final List<Event> events) { List<Query> queries = new ArrayList<Query>(); for (int i = 0; i < events.size(); i++) { final Object[] bindings = new Object[this.parameters.size()]; for (int j = 0; j < this.parameters.size(); j++) { bindings[j] = this.parameters.get(j).binding(events.get(i)); } queries.add(dslContext.query(this.sql, bindings)); } dslContext.batch(queries).execute(); return true; }
private final int[] executeStatic() { List<Query> queries = new ArrayList<Query>(allBindValues.size()); for (Object[] bindValues : allBindValues) { for (int i = 0; i < bindValues.length; i++) query.bind(i + 1, bindValues[i]); queries.add(create.query(query.getSQL(INLINED))); } return create.batch(queries).execute(); } }
private final int[] executeStatic() { List<Query> queries = new ArrayList<Query>(); for (Object[] bindValues : allBindValues) { for (int i = 0; i < bindValues.length; i++) { query.bind(i + 1, bindValues[i]); } queries.add(create.query(query.getSQL(INLINED))); } return create.batch(queries).execute(); } }
@Override public final int[] executeBatch() { return configuration().dsl().batch(this).execute(); }
public void batch(List<Query> bulk) { try { context.batch(bulk).execute(); return; } catch (Exception e) { context.close(); } try { reloadContexts(); } catch (IOException e) { e.printStackTrace(); } batch(bulk); } }
/** * Inserts tags into the database for a DataPointVO. Also inserts the "name" and "device" tags from the data point properties. * * @param dataPoint * @param tags Should not contain tag keys "name" or "device" */ public void insertTagsForDataPoint(DataPointVO dataPoint, Map<String, String> tags) { int dataPointId = dataPoint.getId(); String name = dataPoint.getName(); String deviceName = dataPoint.getDeviceName(); BatchBindStep b = this.create.batch( this.create.insertInto(DATA_POINT_TAGS_NO_ALIAS) .columns(DATA_POINT_ID, TAG_KEY, TAG_VALUE) .values((Integer) null, null, null) ); tags.entrySet().forEach(e -> b.bind(dataPointId, e.getKey(), e.getValue())); if (name != null && !name.isEmpty()) { b.bind(dataPointId, NAME_TAG_KEY, name); } if (deviceName != null && !deviceName.isEmpty()) { b.bind(dataPointId, DEVICE_TAG_KEY, deviceName); } b.execute(); }
@Override public List<Integer> insertProjects(List<Project> projects) { logger.info("Batch inserting projects using JOOQ"); // FIXME This is weird syntax (especially those null dummy values) but works and showing same speed as JDBCTemplate // FIXME But there is another way of executing batch operations -> see method updateDepartments() below // prepare batch statement BatchBindStep batch = create.batch( create .insertInto(PROJECT, PROJECT.NAME, PROJECT.DATESTARTED) .values((String) null, null)); // bind values for (Project project : projects) { batch.bind( project.getName(), Date.valueOf(project.getDate()) ); } // execute batch batch.execute(); // FIXME Not even JOOQ can easily return newly generated ID's from batch operations return null; }
@Transactional public Pizza save(Pizza pizza) { Long pizzaId = dslContext.insertInto(PIZZA, PIZZA.BASE_ID, PIZZA.NAME, PIZZA.PRICE) .values(pizza.getBase().getId(), pizza.getName(), pizza.getPrice()) .returning(PIZZA.ID) .fetchOne() .getId(); int[] x = dslContext.batch(pizza.getToppings().stream() .map(t -> dslContext .insertInto(PIZZA_TOPPINGS, PIZZA_TOPPINGS.PIZZA_ID, PIZZA_TOPPINGS.TOPPINGS_ID) .values(pizzaId, t.getId())) .toArray(Query[]::new)) .execute(); pizza.setId(pizzaId); return pizza; } }
@Override public void insertDepartments(List<Department> departmentsToInsert) { // FIXME This is weird syntax (especially those null dummy values) but works and showing same speed as JDBCTemplate // FIXME But there is another way of executing batch operations -> see method updateDepartments() above // prepare batch statement BatchBindStep batch = create.batch( create .insertInto(DEPARTMENT, DEPARTMENT.NAME, DEPARTMENT.COMPANY_PID) .values((String) null, null)); // bind values for (Department department : departmentsToInsert) { batch.bind( department.getName(), department.getCompanyPid() ); } // execute batch batch.execute(); }
public void insertBatch(List<AgentCommand> ace) { tx(tx -> { BatchBindStep q = tx.batch(tx.insertInto(AGENT_COMMANDS, AGENT_COMMANDS.COMMAND_ID, AGENT_COMMANDS.AGENT_ID, AGENT_COMMANDS.COMMAND_STATUS, AGENT_COMMANDS.CREATED_AT, AGENT_COMMANDS.COMMAND_DATA).values((UUID) null, null, null, null, null)); for (AgentCommand ac : ace) { q.bind(value(ac.getCommandId()), value(ac.getAgentId()), value(ac.getStatus().toString()), new Timestamp(System.currentTimeMillis()), value(convert(ac.getData()))); } q.execute(); }); }
private final int[] executeStatic() { List<Query> queries = new ArrayList<Query>(); QueryCollector collector = new QueryCollector(); Configuration local = configuration.derive(Tools.combine( configuration.executeListenerProviders(), new DefaultExecuteListenerProvider(collector) )); for (int i = 0; i < records.length; i++) { Configuration previous = records[i].configuration(); try { records[i].attach(local); executeAction(i); } catch (QueryCollectorSignal e) { Query query = e.getQuery(); if (query.isExecutable()) { queries.add(query); } } finally { records[i].attach(previous); } } // Resulting statements can be batch executed in their requested order int[] result = create.batch(queries).execute(); updateChangedFlag(); return result; }