From 7b7ebb7af71839d3e38baf87c81075f61863bcbe Mon Sep 17 00:00:00 2001 From: Rob Rudin Date: Fri, 31 Mar 2023 14:00:55 -0400 Subject: [PATCH] Cleaned up validation of rowsHandle in RowBatcherImpl Removed `rowsClass` as a class field, only needs to be a local variable. Extracted `validateRowsHandle` so the constructor is easier to understand. --- .../datamovement/impl/RowBatcherImpl.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/RowBatcherImpl.java b/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/RowBatcherImpl.java index 46bc88739..503d9738d 100644 --- a/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/RowBatcherImpl.java +++ b/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/RowBatcherImpl.java @@ -67,34 +67,42 @@ class RowBatcherImpl extends BatcherImpl implements RowBatcher { private final AtomicLong serverTimestamp = new AtomicLong(-1); private final ContentHandle rowsHandle; - private final Class rowsClass; private final RowManager defaultRowManager; RowBatcherImpl(DataMovementManagerImpl moveMgr, ContentHandle rowsHandle) { super(moveMgr); - if (rowsHandle == null) - throw new IllegalArgumentException("Cannot create RowBatcher with null rows manager"); - if (!(rowsHandle instanceof StructureReadHandle)) - throw new IllegalArgumentException("Rows handle must also be StructureReadHandle"); - if (!(rowsHandle instanceof BaseHandle)) - throw new IllegalArgumentException("Rows handle must also be BaseHandle"); - if (((BaseHandle) rowsHandle).getFormat() == Format.UNKNOWN) - throw new IllegalArgumentException("Rows handle must specify a format"); + validateRowsHandle(rowsHandle); this.rowsHandle = rowsHandle; - this.rowsClass = rowsHandle.getContentClass(); - if (this.rowsClass == null) - throw new IllegalArgumentException("Rows handle cannot have a null content class"); - if (!DatabaseClientFactory.getHandleRegistry().isRegistered(this.rowsClass)) - throw new IllegalArgumentException( - "Rows handle must be registered with DatabaseClientFactory.HandleFactoryRegistry" - ); - defaultRowManager = getPrimaryClient().newRowManager(); + + defaultRowManager = getPrimaryClient().newRowManager(); super.withBatchSize(DEFAULT_BATCH_SIZE); if (moveMgr.getConnectionType() == DatabaseClient.ConnectionType.DIRECT) { withForestConfig(moveMgr.getForestConfig()); } } + private void validateRowsHandle(ContentHandle rowsHandle) { + if (rowsHandle == null) { + throw new IllegalArgumentException("Cannot create RowBatcher with null rows manager"); + } + if (!(rowsHandle instanceof StructureReadHandle)) { + throw new IllegalArgumentException("Rows handle must also be StructureReadHandle"); + } + if (!(rowsHandle instanceof BaseHandle)) { + throw new IllegalArgumentException("Rows handle must also be BaseHandle"); + } + if (((BaseHandle) rowsHandle).getFormat() == Format.UNKNOWN) { + throw new IllegalArgumentException("Rows handle must specify a format"); + } + + Class rowsClass = rowsHandle.getContentClass(); + if (rowsClass == null) { + throw new IllegalArgumentException("Rows handle cannot have a null content class"); + } else if (!DatabaseClientFactory.getHandleRegistry().isRegistered(rowsClass)) { + throw new IllegalArgumentException("Rows handle must be registered with DatabaseClientFactory.HandleFactoryRegistry"); + } + } + @Override public RowManager getRowManager() { return defaultRowManager;