src/main/java/org/embulk/output/kintone/KintonePageOutput.java in embulk-output-kintone-0.3.0 vs src/main/java/org/embulk/output/kintone/KintonePageOutput.java in embulk-output-kintone-0.3.1
- old
+ new
@@ -14,21 +14,21 @@
import org.embulk.spi.PageReader;
import org.embulk.spi.Schema;
import org.embulk.spi.TransactionalPageOutput;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class KintonePageOutput
implements TransactionalPageOutput
{
public static final int UPSERT_BATCH_SIZE = 10000;
public static final int CHUNK_SIZE = 100;
- private PageReader pageReader;
- private PluginTask task;
+ private final PageReader pageReader;
+ private final PluginTask task;
private KintoneClient client;
public KintonePageOutput(PluginTask task, Schema schema)
{
this.pageReader = new PageReader(schema);
@@ -88,18 +88,18 @@
return Exec.newTaskReport();
}
public interface Consumer<T>
{
- public void accept(T t);
+ void accept(T t);
}
public void connect(final PluginTask task)
{
KintoneClientBuilder builder = KintoneClientBuilder.create("https://" + task.getDomain());
if (task.getGuestSpaceId().isPresent()) {
- builder.setGuestSpaceId(task.getGuestSpaceId().or(-1));
+ builder.setGuestSpaceId(task.getGuestSpaceId().orElse(-1));
}
if (task.getBasicAuthUsername().isPresent() && task.getBasicAuthPassword().isPresent()) {
builder.withBasicAuth(task.getBasicAuthUsername().get(),
task.getBasicAuthPassword().get());
}
@@ -155,20 +155,16 @@
private void updatePage(final Page page)
{
execute(client -> {
try {
- if (!task.getUpdateKeyName().isPresent()) {
- // already validated in KintoneOutputPlugin.open()
- throw new RuntimeException("unreachable error");
- }
ArrayList<RecordForUpdate> updateRecords = new ArrayList<>();
pageReader.setPage(page);
KintoneColumnVisitor visitor = new KintoneColumnVisitor(pageReader,
task.getColumnOptions(),
- task.getUpdateKeyName().get());
+ task.getUpdateKeyName().orElseThrow(() -> new RuntimeException("unreachable"))); // Already validated
while (pageReader.nextRecord()) {
Record record = new Record();
UpdateKey updateKey = new UpdateKey();
visitor.setRecord(record);
visitor.setUpdateKey(updateKey);
@@ -199,21 +195,17 @@
private void upsertPage(final Page page)
{
execute(client -> {
try {
- if (!task.getUpdateKeyName().isPresent()) {
- // already validated in KintoneOutputPlugin.open()
- throw new RuntimeException("unreachable error");
- }
ArrayList<Record> records = new ArrayList<>();
ArrayList<UpdateKey> updateKeys = new ArrayList<>();
pageReader.setPage(page);
KintoneColumnVisitor visitor = new KintoneColumnVisitor(pageReader,
task.getColumnOptions(),
- task.getUpdateKeyName().get());
+ task.getUpdateKeyName().orElseThrow(() -> new RuntimeException("unreachable"))); // Already validated
while (pageReader.nextRecord()) {
Record record = new Record();
UpdateKey updateKey = new UpdateKey();
visitor.setRecord(record);
visitor.setUpdateKey(updateKey);
@@ -292,10 +284,10 @@
if (queryValues.isEmpty()) {
return allRecords;
}
String cursorId = client.record().createCursor(
task.getAppId(),
- Arrays.asList(fieldCode),
+ Collections.singletonList(fieldCode),
fieldCode + " in (" + String.join(",", queryValues) + ")"
);
while (true) {
GetRecordsByCursorResponseBody resp = client.record().getRecordsByCursor(cursorId);
List<Record> records = resp.getRecords();