diff --git a/src/main/java/org/embulk/input/mongodb/MongodbInputPlugin.java b/src/main/java/org/embulk/input/mongodb/MongodbInputPlugin.java index e28ab69..1b351f6 100644 --- a/src/main/java/org/embulk/input/mongodb/MongodbInputPlugin.java +++ b/src/main/java/org/embulk/input/mongodb/MongodbInputPlugin.java @@ -163,7 +163,7 @@ public TaskReport run(TaskSource taskSource, final TaskMapper taskMapper = CONFIG_MAPPER_FACTORY.createTaskMapper(); final PluginTask task = taskMapper.map(taskSource, PluginTask.class); BufferAllocator allocator = Exec.getBufferAllocator(); - PageBuilder pageBuilder = Exec.getPageBuilder(allocator, schema, output); + PageBuilder pageBuilder = getPageBuilder(allocator, schema, output); final Column column = pageBuilder.getSchema().getColumns().get(0); ValueCodec valueCodec = new ValueCodec(task.getStopOnInvalidRecord(), task); @@ -480,4 +480,23 @@ private void validateJsonField(String name, String jsonString) throw new ConfigException(String.format("Invalid JSON string was given for '%s' parameter. [%s]", name, jsonString)); } } + + @SuppressWarnings("deprecation") + private static PageBuilder getPageBuilder(final BufferAllocator bufferAllocator, final Schema schema, final PageOutput output) + { + return HAS_EXEC_GET_PAGE_BUILDER ? Exec.getPageBuilder(bufferAllocator, schema, output) : new PageBuilder(bufferAllocator, schema, output); + } + + private static boolean hasExecGetPageBuilder() + { + try { + Exec.class.getMethod("getPageBuilder", BufferAllocator.class, Schema.class, PageOutput.class); + } + catch (final NoSuchMethodException ex) { + return false; + } + return true; + } + + private static final boolean HAS_EXEC_GET_PAGE_BUILDER = hasExecGetPageBuilder(); }