[#2829] Integrated Johanes Bühler's pull request, fixing formatting, license headers, etc.

[#2853] Add DSLContext.fetchFromJSON()
This commit is contained in:
Lukas Eder 2013-11-18 12:27:40 +01:00
parent 03d7d976bb
commit 423d9ceefb
12 changed files with 789 additions and 772 deletions

View File

@ -1,5 +1,50 @@
/**
* Copyright (c) 2009-2013, 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.test._.testcases;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.jooq.impl.DSL.count;
import java.sql.Date;
import java.sql.SQLException;
import java.util.Arrays;
@ -18,34 +63,32 @@ import org.jooq.test.jOOQAbstractTest;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.jooq.impl.DSL.count;
/**
*
* @author Johannes Buehler
* @author Lukas Eder
*/
public abstract class AbstractLoaderTests<
A extends UpdatableRecord<A> & Record6<Integer, String, String, Date, Integer, ?>,
AP,
B extends UpdatableRecord<B>,
S extends UpdatableRecord<S> & Record1<String>,
B2S extends UpdatableRecord<B2S> & Record3<String, Integer, Integer>,
BS extends UpdatableRecord<BS>,
L extends TableRecord<L> & Record2<String, String>,
X extends TableRecord<X>,
DATE extends UpdatableRecord<DATE>,
BOOL extends UpdatableRecord<BOOL>,
D extends UpdatableRecord<D>,
T extends UpdatableRecord<T>,
U extends TableRecord<U>,
UU extends UpdatableRecord<UU>,
I extends TableRecord<I>,
IPK extends UpdatableRecord<IPK>,
T725 extends UpdatableRecord<T725>,
T639 extends UpdatableRecord<T639>,
T785 extends TableRecord<T785>> extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T725, T639, T785> {
A extends UpdatableRecord<A> & Record6<Integer, String, String, Date, Integer, ?>,
AP,
B extends UpdatableRecord<B>,
S extends UpdatableRecord<S> & Record1<String>,
B2S extends UpdatableRecord<B2S> & Record3<String, Integer, Integer>,
BS extends UpdatableRecord<BS>,
L extends TableRecord<L> & Record2<String, String>,
X extends TableRecord<X>,
DATE extends UpdatableRecord<DATE>,
BOOL extends UpdatableRecord<BOOL>,
D extends UpdatableRecord<D>,
T extends UpdatableRecord<T>,
U extends TableRecord<U>,
UU extends UpdatableRecord<UU>,
I extends TableRecord<I>,
IPK extends UpdatableRecord<IPK>,
T725 extends UpdatableRecord<T725>,
T639 extends UpdatableRecord<T639>,
T785 extends TableRecord<T785>>
extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T725, T639, T785> {
public AbstractLoaderTests(jOOQAbstractTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T725, T639, T785> delegate) {
super(delegate);
}

View File

@ -40,34 +40,42 @@
*/
package org.jooq.test._.testcases;
import org.jooq.*;
import org.jooq.test.jOOQAbstractTest;
import java.sql.Date;
// ...
import org.jooq.Loader;
import org.jooq.Record1;
import org.jooq.Record2;
import org.jooq.Record3;
import org.jooq.Record6;
import org.jooq.TableRecord;
import org.jooq.UpdatableRecord;
import org.jooq.test.jOOQAbstractTest;
/**
* @author Johannes Buehler
* @author Lukas Eder
*/
public class CsvLoaderTests<
A extends UpdatableRecord<A> & Record6<Integer, String, String, Date, Integer, ?>,
AP,
B extends UpdatableRecord<B>,
S extends UpdatableRecord<S> & Record1<String>,
B2S extends UpdatableRecord<B2S> & Record3<String, Integer, Integer>,
BS extends UpdatableRecord<BS>,
L extends TableRecord<L> & Record2<String, String>,
X extends TableRecord<X>,
DATE extends UpdatableRecord<DATE>,
BOOL extends UpdatableRecord<BOOL>,
D extends UpdatableRecord<D>,
T extends UpdatableRecord<T>,
U extends TableRecord<U>,
UU extends UpdatableRecord<UU>,
I extends TableRecord<I>,
IPK extends UpdatableRecord<IPK>,
T725 extends UpdatableRecord<T725>,
T639 extends UpdatableRecord<T639>,
T785 extends TableRecord<T785>>
extends AbstractLoaderTests {
A extends UpdatableRecord<A> & Record6<Integer, String, String, Date, Integer, ?>,
AP,
B extends UpdatableRecord<B>,
S extends UpdatableRecord<S> & Record1<String>,
B2S extends UpdatableRecord<B2S> & Record3<String, Integer, Integer>,
BS extends UpdatableRecord<BS>,
L extends TableRecord<L> & Record2<String, String>,
X extends TableRecord<X>,
DATE extends UpdatableRecord<DATE>,
BOOL extends UpdatableRecord<BOOL>,
D extends UpdatableRecord<D>,
T extends UpdatableRecord<T>,
U extends TableRecord<U>,
UU extends UpdatableRecord<UU>,
I extends TableRecord<I>,
IPK extends UpdatableRecord<IPK>,
T725 extends UpdatableRecord<T725>,
T639 extends UpdatableRecord<T639>,
T785 extends TableRecord<T785>>
extends AbstractLoaderTests<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T725, T639, T785> {
public CsvLoaderTests(jOOQAbstractTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T725, T639, T785> delegate) {
super(delegate);
@ -237,5 +245,4 @@ public class CsvLoaderTests<
.fields(TAuthor_ID())
.execute();
}
}

View File

@ -40,18 +40,10 @@
*/
package org.jooq.test._.testcases;
import org.jooq.*;
import org.jooq.test.BaseTest;
import org.jooq.test._.tools.DOMBuilder;
import org.jooq.test.jOOQAbstractTest;
import org.junit.Test;
import org.w3c.dom.Document;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.math.BigDecimal;
@ -61,13 +53,33 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.jooq.Field;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Record2;
import org.jooq.Record3;
import org.jooq.Record6;
import org.jooq.Result;
import org.jooq.Row;
import org.jooq.TableRecord;
import org.jooq.UpdatableRecord;
import org.jooq.test.BaseTest;
import org.jooq.test.jOOQAbstractTest;
import org.jooq.test._.tools.DOMBuilder;
import org.junit.Test;
import org.w3c.dom.Document;
/**
* @author Lukas Eder
* @author Ivan Dugic
* @author Johannes Buehler
*/
public class FormatTests<
A extends UpdatableRecord<A> & Record6<Integer, String, String, Date, Integer, ?>,

View File

@ -40,26 +40,62 @@
*/
package org.jooq.test._.testcases;
import org.jooq.*;
import org.jooq.test.BaseTest;
import org.jooq.test.jOOQAbstractTest;
import org.junit.Test;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
// ...
import static org.jooq.SQLDialect.CUBRID;
// ...
import static org.jooq.SQLDialect.DERBY;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.SQLDialect.H2;
// ...
import static org.jooq.SQLDialect.MARIADB;
import static org.jooq.SQLDialect.MYSQL;
import static org.jooq.SQLDialect.POSTGRES;
import static org.jooq.SQLDialect.SQLITE;
// ...
// ...
import static org.jooq.impl.DSL.cast;
import static org.jooq.impl.DSL.castNull;
import static org.jooq.impl.DSL.count;
import static org.jooq.impl.DSL.decode;
import static org.jooq.impl.DSL.falseCondition;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.max;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.selectOne;
import static org.jooq.impl.DSL.tableByName;
import static org.jooq.impl.DSL.trueCondition;
import static org.jooq.impl.DSL.val;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.util.Arrays;
import static java.util.Arrays.asList;
import static junit.framework.Assert.*;
import static org.jooq.SQLDialect.*;
import static org.jooq.impl.DSL.*;
import org.jooq.Field;
import org.jooq.Insert;
import org.jooq.InsertQuery;
import org.jooq.MergeFinalStep;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Record2;
import org.jooq.Record3;
import org.jooq.Record6;
import org.jooq.Result;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableRecord;
import org.jooq.UpdatableRecord;
import org.jooq.UpdateQuery;
import org.jooq.test.BaseTest;
import org.jooq.test.jOOQAbstractTest;
// ...
// ...
// ...
// ...
// ...
import org.junit.Test;
public class InsertUpdateTests<
A extends UpdatableRecord<A> & Record6<Integer, String, String, Date, Integer, ?>,
@ -556,7 +592,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
// Returning all fields
InsertQuery<T> query;
query = create().insertQuery(TTriggers());
query.addValue(TTriggers_COUNTER(), (Field)null);
query.addValue(TTriggers_COUNTER(), null);
query.addValue(TTriggers_COUNTER(), 0);
query.setReturning();
assertEquals(1, query.execute());
@ -674,7 +710,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
// Without RETURNING clause
query = create().insertQuery(TTriggers());
query.addValue(TTriggers_ID(), (Field)null);
query.addValue(TTriggers_ID(), null);
query.addValue(TTriggers_COUNTER(), 0);
assertEquals(1, query.execute());
assertNull(query.getReturnedRecord());

View File

@ -54,26 +54,26 @@ import org.jooq.test.jOOQAbstractTest;
// ...
public class JsonLoaderTests<
A extends UpdatableRecord<A> & Record6<Integer, String, String, Date, Integer, ?>,
AP,
B extends UpdatableRecord<B>,
S extends UpdatableRecord<S> & Record1<String>,
B2S extends UpdatableRecord<B2S> & Record3<String, Integer, Integer>,
BS extends UpdatableRecord<BS>,
L extends TableRecord<L> & Record2<String, String>,
X extends TableRecord<X>,
DATE extends UpdatableRecord<DATE>,
BOOL extends UpdatableRecord<BOOL>,
D extends UpdatableRecord<D>,
T extends UpdatableRecord<T>,
U extends TableRecord<U>,
UU extends UpdatableRecord<UU>,
I extends TableRecord<I>,
IPK extends UpdatableRecord<IPK>,
T725 extends UpdatableRecord<T725>,
T639 extends UpdatableRecord<T639>,
T785 extends TableRecord<T785>>
extends AbstractLoaderTests {
A extends UpdatableRecord<A> & Record6<Integer, String, String, Date, Integer, ?>,
AP,
B extends UpdatableRecord<B>,
S extends UpdatableRecord<S> & Record1<String>,
B2S extends UpdatableRecord<B2S> & Record3<String, Integer, Integer>,
BS extends UpdatableRecord<BS>,
L extends TableRecord<L> & Record2<String, String>,
X extends TableRecord<X>,
DATE extends UpdatableRecord<DATE>,
BOOL extends UpdatableRecord<BOOL>,
D extends UpdatableRecord<D>,
T extends UpdatableRecord<T>,
U extends TableRecord<U>,
UU extends UpdatableRecord<UU>,
I extends TableRecord<I>,
IPK extends UpdatableRecord<IPK>,
T725 extends UpdatableRecord<T725>,
T639 extends UpdatableRecord<T639>,
T785 extends TableRecord<T785>>
extends AbstractLoaderTests<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T725, T639, T785> {
public JsonLoaderTests(jOOQAbstractTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T725, T639, T785> delegate) {
super(delegate);

View File

@ -40,6 +40,17 @@
*/
package org.jooq.test;
import static java.util.Arrays.asList;
import static org.jooq.SQLDialect.CUBRID;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.test._.listeners.JDBCLifecycleListener.RS_CLOSE_COUNT;
import static org.jooq.test._.listeners.JDBCLifecycleListener.RS_START_COUNT;
import static org.jooq.test._.listeners.JDBCLifecycleListener.STMT_CLOSE_COUNT;
import static org.jooq.test._.listeners.JDBCLifecycleListener.STMT_START_COUNT;
import static org.jooq.test._.listeners.LifecycleWatcherListener.LISTENER_END_COUNT;
import static org.jooq.test._.listeners.LifecycleWatcherListener.LISTENER_START_COUNT;
import static org.jooq.tools.reflect.Reflect.on;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Method;
@ -61,6 +72,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.UUID;
// ...
import org.jooq.DAO;
import org.jooq.DSLContext;
import org.jooq.DataType;
@ -160,23 +172,9 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.postgresql.util.PSQLException;
import static java.util.Arrays.asList;
import static org.jooq.SQLDialect.CUBRID;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.test._.listeners.JDBCLifecycleListener.RS_CLOSE_COUNT;
import static org.jooq.test._.listeners.JDBCLifecycleListener.RS_START_COUNT;
import static org.jooq.test._.listeners.JDBCLifecycleListener.STMT_CLOSE_COUNT;
import static org.jooq.test._.listeners.JDBCLifecycleListener.STMT_START_COUNT;
import static org.jooq.test._.listeners.LifecycleWatcherListener.LISTENER_END_COUNT;
import static org.jooq.test._.listeners.LifecycleWatcherListener.LISTENER_START_COUNT;
import static org.jooq.tools.reflect.Reflect.on;
// ...
// ...
/**
@ -1550,7 +1548,6 @@ public abstract class jOOQAbstractTest<
}
@Test
@Ignore // ist currently failing for other reasons than any change from my side
public void testRecordListenerBatchStore() throws Exception {
new RecordListenerTests(this).testRecordListenerBatchStore();
}
@ -1871,7 +1868,6 @@ public abstract class jOOQAbstractTest<
}
@Test
@Ignore
public void testLimitDistinct() throws Exception {
new OrderByTests(this).testLimitDistinct();
}
@ -2400,6 +2396,7 @@ public abstract class jOOQAbstractTest<
public void testCsvLoader() throws Exception {
new CsvLoaderTests(this).testLoader();
}
@Test
public void testJsonLoader() throws Exception {
new JsonLoaderTests(this).testLoader();

File diff suppressed because it is too large Load Diff

View File

@ -38,11 +38,17 @@
* 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.impl;
import javax.annotation.Generated;
import javax.sql.DataSource;
import static org.jooq.conf.ParamType.INLINED;
import static org.jooq.conf.ParamType.NAMED;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.queryPart;
import static org.jooq.impl.DSL.template;
import static org.jooq.impl.DSL.trueCondition;
import static org.jooq.impl.Utils.list;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringReader;
@ -60,6 +66,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;
import javax.sql.DataSource;
import org.jooq.Attachable;
import org.jooq.Batch;
import org.jooq.BatchBindStep;
@ -177,16 +186,6 @@ import org.jooq.exception.InvalidResultException;
import org.jooq.exception.SQLDialectNotSupportedException;
import org.jooq.impl.BatchCRUD.Action;
import org.jooq.tools.csv.CSVReader;
import org.jooq.tools.json.JSONReader;
import static org.jooq.conf.ParamType.INLINED;
import static org.jooq.conf.ParamType.NAMED;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.queryPart;
import static org.jooq.impl.DSL.template;
import static org.jooq.impl.DSL.trueCondition;
import static org.jooq.impl.Utils.list;
/**
* A default implementation for {@link DSLContext}.
@ -675,22 +674,22 @@ public class DefaultDSLContext implements DSLContext, Serializable {
String[] fields = reader.getFields();
data.add(fields);
data.addAll(records);
} catch (IOException e) {
}
catch (IOException e) {
throw new DataAccessException("Could not read the JSON string", e);
} finally {
try {
}
finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException ignore) {
}
catch (IOException ignore) {}
}
return fetchFromStringData(data);
}
@Override
public Result<Record> fetchFromStringData(String[]... data) {
return fetchFromStringData(list(data));
@ -751,7 +750,7 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return result;
}
// [jooq-tools] START [select]
// [jooq-tools] START [select]
@Generated("This method was generated using jOOQ-tools")
@Override
@ -885,7 +884,7 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return (SelectSelectStep) select(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20, field21, field22 });
}
// [jooq-tools] END [select]
// [jooq-tools] END [select]
@Override
public SelectSelectStep<Record> selectDistinct(Collection<? extends Field<?>> fields) {
@ -901,7 +900,7 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return result;
}
// [jooq-tools] START [selectDistinct]
// [jooq-tools] START [selectDistinct]
@Generated("This method was generated using jOOQ-tools")
@Override
@ -1035,7 +1034,7 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return (SelectSelectStep) selectDistinct(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20, field21, field22 });
}
// [jooq-tools] END [selectDistinct]
// [jooq-tools] END [selectDistinct]
@Override
public SelectSelectStep<Record1<Integer>> selectZero() {
@ -1078,7 +1077,7 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return new InsertImpl(configuration, into, Collections.<Field<?>>emptyList());
}
// [jooq-tools] START [insert]
// [jooq-tools] START [insert]
@Generated("This method was generated using jOOQ-tools")
@Override
@ -1212,7 +1211,7 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return new InsertImpl(configuration, into, Arrays.asList(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20, field21, field22 }));
}
// [jooq-tools] END [insert]
// [jooq-tools] END [insert]
@Override
public <R extends Record> InsertValuesStepN<R> insertInto(Table<R> into, Field<?>... fields) {
@ -1239,7 +1238,7 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return new MergeImpl(configuration, table);
}
// [jooq-tools] START [merge]
// [jooq-tools] START [merge]
@Generated("This method was generated using jOOQ-tools")
@Override
@ -1373,7 +1372,7 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return new MergeImpl(configuration, table, Arrays.asList(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20, field21, field22));
}
// [jooq-tools] END [merge]
// [jooq-tools] END [merge]
@Override
public <R extends Record> MergeKeyStepN<R> mergeInto(Table<R> table, Field<?>... fields) {
@ -1694,7 +1693,7 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return (Record22) newRecord(new Field[] { field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20, field21, field22 });
}
// [jooq-tools] END [newRecord]
// [jooq-tools] END [newRecord]
@Override
public <R extends UDTRecord<R>> R newRecord(UDT<R> type) {
@ -1709,14 +1708,14 @@ public class DefaultDSLContext implements DSLContext, Serializable {
@Override
public <R extends Record> R newRecord(Table<R> table, final Object source) {
return Utils.newRecord(table, configuration)
.operate(new RecordOperation<R, RuntimeException>() {
.operate(new RecordOperation<R, RuntimeException>() {
@Override
public R operate(R record) {
record.from(source);
return record;
}
});
@Override
public R operate(R record) {
record.from(source);
return record;
}
});
}
@Override
@ -1794,13 +1793,11 @@ public class DefaultDSLContext implements DSLContext, Serializable {
}
private final <T, R extends Record1<T>> T value1(R record) {
if (record == null) {
if (record == null)
return null;
}
if (record.size() != 1) {
if (record.size() != 1)
throw new InvalidResultException("Record contains more than one value : " + record);
}
return record.value1();
}

View File

@ -1,29 +1,72 @@
package org.jooq.tools.json;
/**
* Copyright (c) 2009-2013, 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.impl;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.Reader;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import org.jooq.tools.json.ContainerFactory;
import org.jooq.tools.json.JSONParser;
import org.jooq.tools.json.ParseException;
/**
* A very simple JSON reader based on Simple JSON.
*
* @author Johannes Bühler
*
* @since 3.3.0
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class JSONReader implements Closeable {
@SuppressWarnings({ "rawtypes", "unchecked" })
class JSONReader implements Closeable {
private final BufferedReader br;
private final JSONParser parser;
private String[] fieldMetaData;
private List<String[]> records;
private final JSONParser parser;
private String[] fieldMetaData;
private List<String[]> records;
public JSONReader(Reader reader) throws IOException {
public JSONReader(Reader reader) {
this.br = new BufferedReader(reader);
this.parser = new JSONParser();
}
@ -36,7 +79,8 @@ public class JSONReader implements Closeable {
LinkedHashMap jsonRoot = getJsonRoot();
readFields(jsonRoot);
records = readRecords(jsonRoot);
} catch (ParseException ex) {
}
catch (ParseException ex) {
throw new RuntimeException(ex);
}
return records;
@ -52,7 +96,6 @@ public class JSONReader implements Closeable {
@Override
public void close() throws IOException {
br.close();
}
private List<String[]> readRecords(LinkedHashMap jsonRoot) {
@ -98,7 +141,5 @@ public class JSONReader implements Closeable {
i++;
}
}
}

View File

@ -1,37 +1,42 @@
/**
* Copyright (c) 2009-2013, Lukas Eder, lukas.eder@gmail.com
* Copyright (c) 2009-2013, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* This software is licensed to you under the Apache License, Version 2.0
* (the "License"); You may obtain a copy of the License at
* 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:
*
* http://www.apache.org/licenses/LICENSE-2.0
* - 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
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* For more information, please visit http://www.jooq.org/licenses
*
* . Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 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
*
* . Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* http://www.apache.org/licenses/LICENSE-2.0
*
* . Neither the name "jOOQ" nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* 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.impl;
@ -70,7 +75,6 @@ import org.jooq.exception.DataAccessException;
import org.jooq.tools.StringUtils;
import org.jooq.tools.csv.CSVParser;
import org.jooq.tools.csv.CSVReader;
import org.jooq.tools.json.JSONReader;
import org.xml.sax.InputSource;
@ -81,8 +85,13 @@ import org.xml.sax.InputSource;
class LoaderImpl<R extends TableRecord<R>> implements
// Cascading interface implementations for Loader behaviour
LoaderOptionsStep<R>, LoaderXMLStep<R>, LoaderCSVStep<R>, LoaderCSVOptionsStep<R>, LoaderJSONStep<R>,
LoaderJSONOptionsStep<R>, Loader<R> {
LoaderOptionsStep<R>,
LoaderXMLStep<R>,
LoaderCSVStep<R>,
LoaderCSVOptionsStep<R>,
LoaderJSONStep<R>,
LoaderJSONOptionsStep<R>,
Loader<R> {
// Configuration constants
// -----------------------
@ -149,9 +158,7 @@ class LoaderImpl<R extends TableRecord<R>> implements
@Override
public final LoaderImpl<R> onDuplicateKeyIgnore() {
if (table.getPrimaryKey() == null) {
throw new IllegalStateException(
"ON DUPLICATE KEY IGNORE only works on tables with explicit primary keys. Table is not updatable : "
+ table);
throw new IllegalStateException("ON DUPLICATE KEY IGNORE only works on tables with explicit primary keys. Table is not updatable : " + table);
}
onDuplicate = ON_DUPLICATE_KEY_IGNORE;
@ -161,9 +168,7 @@ class LoaderImpl<R extends TableRecord<R>> implements
@Override
public final LoaderImpl<R> onDuplicateKeyUpdate() {
if (table.getPrimaryKey() == null) {
throw new IllegalStateException(
"ON DUPLICATE KEY UPDATE only works on tables with explicit primary keys. Table is not updatable : "
+ table);
throw new IllegalStateException("ON DUPLICATE KEY UPDATE only works on tables with explicit primary keys. Table is not updatable : " + table);
}
onDuplicate = ON_DUPLICATE_KEY_UPDATE;
@ -377,6 +382,7 @@ class LoaderImpl<R extends TableRecord<R>> implements
JSONReader reader = new JSONReader(data);
try {
// The current json format is not designed for streaming. Thats why
// all records are loaded at once.
List<String[]> allRecords = reader.readAll();

View File

@ -237,6 +237,10 @@ public class CSVReader implements Closeable, Iterator<String[]> {
br.close();
}
// ------------------------------------------------------------------------
// XXX: Iterator implementation added by Johannes Buehler
// ------------------------------------------------------------------------
@Override
public boolean hasNext() {
return hasNext;
@ -246,7 +250,8 @@ public class CSVReader implements Closeable, Iterator<String[]> {
public String[] next() {
try {
return readNext();
} catch (IOException e) {
}
catch (IOException e) {
throw new RuntimeException(e);
}
}

View File

@ -524,4 +524,4 @@ public class JSONParser {
status = S_IN_ERROR;
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
}
}
}