From 1fff3741bd5293cfa0ae2226e8569296bc4b9fb4 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Thu, 29 Jan 2015 15:20:17 +0100 Subject: [PATCH] [#4012] Add new LoaderConfigurationException to indicate bad configurations in Loader API --- .../LoaderConfigurationException.java | 66 +++++++++++++++++++ .../main/java/org/jooq/impl/LoaderImpl.java | 8 +++ 2 files changed, 74 insertions(+) create mode 100644 jOOQ/src/main/java/org/jooq/exception/LoaderConfigurationException.java diff --git a/jOOQ/src/main/java/org/jooq/exception/LoaderConfigurationException.java b/jOOQ/src/main/java/org/jooq/exception/LoaderConfigurationException.java new file mode 100644 index 0000000000..de6192538c --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/exception/LoaderConfigurationException.java @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2009-2015, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * This work is dual-licensed + * - under the Apache Software License 2.0 (the "ASL") + * - under the jOOQ License and Maintenance Agreement (the "jOOQ License") + * ============================================================================= + * You may choose which license applies to you: + * + * - If you're using this work with Open Source databases, you may choose + * either ASL or jOOQ License. + * - If you're using this work with at least one commercial database, you must + * choose jOOQ License + * + * For more information, please visit http://www.jooq.org/licenses + * + * Apache Software License 2.0: + * ----------------------------------------------------------------------------- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * jOOQ License and Maintenance Agreement: + * ----------------------------------------------------------------------------- + * Data Geekery grants the Customer the non-exclusive, timely limited and + * non-transferable license to install and use the Software under the terms of + * the jOOQ License and Maintenance Agreement. + * + * This library is distributed with a LIMITED WARRANTY. See the jOOQ License + * and Maintenance Agreement for more details: http://www.jooq.org/licensing + */ +package org.jooq.exception; + +import org.jooq.Loader; + +/** + * The LoaderConfigurationException indicates that a {@link Loader} + * was executed with an illegal execution configuration. + * + * @author Lukas Eder + */ +public class LoaderConfigurationException extends DataAccessException { + + /** + * Generated UID + */ + private static final long serialVersionUID = 1070990582126075536L; + + /** + * Constructor for LoaderConfigurationException. + * + * @param message the detail message + */ + public LoaderConfigurationException(String message) { + super(message); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java b/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java index 51a598c92d..d7486c54d1 100644 --- a/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java @@ -73,6 +73,7 @@ import org.jooq.SelectQuery; import org.jooq.Table; import org.jooq.TableRecord; import org.jooq.exception.DataAccessException; +import org.jooq.exception.LoaderConfigurationException; import org.jooq.tools.StringUtils; import org.jooq.tools.csv.CSVParser; import org.jooq.tools.csv.CSVReader; @@ -390,6 +391,8 @@ class LoaderImpl> implements @Override public final LoaderImpl execute() throws IOException { + checkFlags(); + if (content == CONTENT_CSV) { executeCSV(); } @@ -406,6 +409,11 @@ class LoaderImpl> implements return this; } + private void checkFlags() { + if (batch != BATCH_NONE && onDuplicate == ON_DUPLICATE_KEY_IGNORE) + throw new LoaderConfigurationException("Cannot apply batch loading with onDuplicateKeyIgnore flag. Turn off either flag."); + } + private void executeJSON() throws IOException { JSONReader reader = new JSONReader(data);