[#561] More fixes

This commit is contained in:
Lukas Eder 2014-08-06 14:15:05 +02:00
parent 30a859b550
commit 1210ee4362
13 changed files with 484 additions and 5 deletions

View File

@ -75,6 +75,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -396,6 +397,13 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
assertTrue(array3 instanceof Integer[]);
}
public void testFetchSet() throws Exception {
assertEquals(
new LinkedHashSet<>(AUTHOR_IDS),
create().select(TBook_AUTHOR_ID()).from(TBook()).fetchSet(TBook_AUTHOR_ID())
);
}
public void testFetch() throws Exception {
SelectQuery<?> q = create().selectQuery();
q.addFrom(TAuthor());

View File

@ -1001,7 +1001,8 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
// --------------------------------
create().mergeInto(TAuthor())
.using(selectOne())
.on(TAuthor_ID().equal(1))
// Inline this bind value. In this particular case, INFORMIX doesn't like bind values...
.on(TAuthor_ID().equal(inline(1)))
.whenMatchedThenUpdate()
.set(TAuthor_FIRST_NAME(), "John")
.whenNotMatchedThenInsert(TAuthor_ID(), TAuthor_LAST_NAME())

View File

@ -1261,6 +1261,11 @@ public abstract class jOOQAbstractTest<
new FetchTests(this).testFetchArray();
}
@Test
public void testFetchSet() throws Exception {
new FetchTests(this).testFetchSet();
}
@Test
public void testFetchGroupsPOJO() throws Exception {
new FetchTests(this).testFetchGroupsPOJO();

View File

@ -45,6 +45,7 @@ import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Generated;
@ -896,6 +897,113 @@ public interface Result<R extends Record> extends List<R>, Attachable {
<T, U> U[] intoArray(Field<T> field, Converter<? super T, U> converter) throws IllegalArgumentException,
DataTypeException;
/**
* Return all values for a field index from the result.
*
* @return The resulting values. This may be an array type more concrete
* than <code>Object[]</code>, depending on whether jOOQ has any
* knowledge about <code>fieldIndex</code>'s actual type.
* @see #getValues(int)
* @throws IllegalArgumentException If the argument fieldIndex is not
* contained in {@link #fieldsRow()}
*/
Set<?> intoSet(int fieldIndex) throws IllegalArgumentException;
/**
* Return all values for a field index from the result.
*
* @return The resulting values.
* @see #getValues(int, Class)
* @throws IllegalArgumentException If the argument fieldIndex is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> Set<T> intoSet(int fieldIndex, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field index from the result.
*
* @return The resulting values.
* @see #getValues(int, Converter)
* @throws IllegalArgumentException If the argument fieldIndex is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<U> Set<U> intoSet(int fieldIndex, Converter<?, U> converter) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field name from the result.
*
* @return The resulting values. This may be an array type more concrete
* than <code>Object[]</code>, depending on whether jOOQ has any
* knowledge about <code>fieldName</code>'s actual type.
* @see #getValues(String)
* @throws IllegalArgumentException If the argument fieldName is not
* contained in {@link #fieldsRow()}
*/
Set<?> intoSet(String fieldName) throws IllegalArgumentException;
/**
* Return all values for a field name from the result.
*
* @return The resulting values.
* @see #getValues(String, Class)
* @throws IllegalArgumentException If the argument fieldName is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> Set<T> intoSet(String fieldName, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field name from the result.
*
* @return The resulting values.
* @see #getValues(String, Converter)
* @throws IllegalArgumentException If the argument fieldName is not
* contained in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<U> Set<U> intoSet(String fieldName, Converter<?, U> converter) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field from the result.
*
* @return The resulting values.
* @see #getValues(Field)
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
*/
<T> Set<T> intoSet(Field<T> field) throws IllegalArgumentException;
/**
* Return all values for a field from the result.
*
* @return The resulting values.
* @see #getValues(Field, Class)
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T> Set<T> intoSet(Field<?> field, Class<? extends T> type) throws IllegalArgumentException, DataTypeException;
/**
* Return all values for a field from the result.
*
* @return The resulting values.
* @see #getValues(Field, Converter)
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
*/
<T, U> Set<U> intoSet(Field<T> field, Converter<? super T, U> converter) throws IllegalArgumentException,
DataTypeException;
/**
* Copy all records from this result into a new result with new records
* holding only a subset of the previous fields.

View File

@ -46,6 +46,7 @@ import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import org.jooq.conf.Settings;
@ -1141,6 +1142,96 @@ public interface ResultQuery<R extends Record> extends Query {
*/
<T, U> U[] fetchArray(Field<T> field, Converter<? super T, U> converter) throws DataAccessException;
/**
* Execute the query and return all values for a field index from the
* generated result.
*
* @return The resulting values.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(int)
*/
Set<?> fetchSet(int fieldIndex) throws DataAccessException;
/**
* Execute the query and return all values for a field index from the
* generated result.
*
* @return The resulting values.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(int, Class)
*/
<T> Set<T> fetchSet(int fieldIndex, Class<? extends T> type) throws DataAccessException;
/**
* Execute the query and return all values for a field index from the
* generated result.
*
* @return The resulting values.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(int, Converter)
*/
<U> Set<U> fetchSet(int fieldIndex, Converter<?, U> converter) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
* generated result.
*
* @return The resulting values.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(String)
*/
Set<?> fetchSet(String fieldName) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
* generated result.
*
* @return The resulting values.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(String, Converter)
*/
<T> Set<T> fetchSet(String fieldName, Class<? extends T> type) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
* generated result.
*
* @return The resulting values.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(String, Class)
*/
<U> Set<U> fetchSet(String fieldName, Converter<?, U> converter) throws DataAccessException;
/**
* Execute the query and return all values for a field from the generated
* result.
*
* @return The resulting values.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Field)
*/
<T> Set<T> fetchSet(Field<T> field) throws DataAccessException;
/**
* Execute the query and return all values for a field from the generated
* result.
*
* @return The resulting values.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Field, Class)
*/
<T> Set<T> fetchSet(Field<?> field, Class<? extends T> type) throws DataAccessException;
/**
* Execute the query and return all values for a field from the generated
* result.
*
* @return The resulting values.
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Field, Converter)
*/
<T, U> Set<U> fetchSet(Field<T> field, Converter<? super T, U> converter) throws DataAccessException;
/**
* Map resulting records onto a custom type.
* <p>

View File

@ -57,6 +57,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@ -704,6 +705,51 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
return fetch().intoArray(field, converter);
}
@Override
public final Set<?> fetchSet(int fieldIndex) {
return fetch().intoSet(fieldIndex);
}
@Override
public final <T> Set<T> fetchSet(int fieldIndex, Class<? extends T> type) {
return fetch().intoSet(fieldIndex, type);
}
@Override
public final <U> Set<U> fetchSet(int fieldIndex, Converter<?, U> converter) {
return fetch().intoSet(fieldIndex, converter);
}
@Override
public final Set<?> fetchSet(String fieldName) {
return fetch().intoSet(fieldName);
}
@Override
public final <T> Set<T> fetchSet(String fieldName, Class<? extends T> type) {
return fetch().intoSet(fieldName, type);
}
@Override
public final <U> Set<U> fetchSet(String fieldName, Converter<?, U> converter) {
return fetch().intoSet(fieldName, converter);
}
@Override
public final <T> Set<T> fetchSet(Field<T> field) {
return fetch().intoSet(field);
}
@Override
public final <T> Set<T> fetchSet(Field<?> field, Class<? extends T> type) {
return fetch().intoSet(field, type);
}
@Override
public final <T, U> Set<U> fetchSet(Field<T> field, Converter<? super T, U> converter) {
return fetch().intoSet(field, converter);
}
/**
* Subclasses may override this method
* <p>

View File

@ -0,0 +1,87 @@
/**
* Copyright (c) 2009-2014, 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 org.jooq.Context;
import org.jooq.DataType;
import org.jooq.Field;
/**
* @author Lukas Eder
*/
class Coalesce<T> extends AbstractField<T> {
/**
* Generated UID
*/
private static final long serialVersionUID = -4546488210418866103L;
private final Field<T>[] fields;
@SuppressWarnings("unchecked")
Coalesce(DataType<T> dataType, Field<?>[] fields) {
super("coalesce", dataType);
this.fields = (Field[]) fields;
}
@Override
public final void accept(Context<?> ctx) {
switch (ctx.family()) {
/* [pro] xx
xxxx xxxxxxxxx x
xxxxxxxx xxxxxxxx x xxxxxxxxxx
xxx xxxx x x xx x x xxxxxxxxxxxxxx xxxx
xxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx
xxxxxx
x
xx [/pro] */
default: {
ctx.visit(DSL.function("coalesce", getDataType(), fields));
break;
}
}
}
}

View File

@ -6384,7 +6384,7 @@ public class DSL {
*/
@Support
public static <T> Field<T> coalesce(Field<T> field, Field<?>... fields) {
return function("coalesce", nullSafeDataType(field), nullSafe(combine(field, fields)));
return new Coalesce<T>(nullSafeDataType(field), nullSafe(combine(field, fields)));
}
/**

View File

@ -196,6 +196,20 @@ class DateAdd<T extends java.util.Date> extends AbstractFunction<T> {
xxxxxx xxxxxxxxxxxxxxxxxxxxx xxxx xxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxx xxxxxx
x
xxxx xxxxxxxxx x
xxxxxx xxxxxxxxxx x
xxxx xxxxx xxxxxxx x xxxxxxx xxxxxx
xxxx xxxxxx xxxxxxx x xxxxxxxx xxxxxx
xxxx xxxx xxxxxxx x xxxxxx xxxxxx
xxxx xxxxx xxxxxxx x xxxxxxx xxxxxx
xxxx xxxxxxx xxxxxxx x xxxxxxxxx xxxxxx
xxxx xxxxxxx xxxxxxx x xxxxxxxxx xxxxxx
xxxxxxxx xxxxxxxxxxxxxxxxxxx
x
xxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxx xxxxx xxxxxxxxx xxxxxxxxxxxxxxxxxxx
x
xxxx xxxx x
xxxxxx xxxxxxxxxx x
xxxx xxxxx xxxxxxx x xxxxxxx xxxxxx

View File

@ -400,6 +400,32 @@ class Expression<T> extends AbstractFunction<T> {
x
x
xxxx xxxxxxxxx x
xx xxxxxxxxxxxxxxxxxxxxx xx xxxxxxxxxxxxxxxxxx x
xx xxxxxxxxx xx xxxx x
xxxxxx xxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
xxxx x
xxxxxx xxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
x
xxxx x
xx xxxxxxxx xxxxx xxxx xxxx xx xxx xx xx xxxx xxxxx
xxxxxxxxxxx xxxx x xxxxxxxxxxxxxxxxxx
xx xxxxxxxxx xx xxxx x
xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x xxxxxxxxx
xxxxxxxxxxxx
x
xxxx x
xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x xxxxxxxxx
xxxxxxxxxxxx
x
x
x
xxxx xxxx x
xx xxxxxxxxxxxxxxxxxxxxx xx xxxxxxxxxxxxxxxxxx x
xx xxxxxxxxx xx xxxx x
@ -520,10 +546,10 @@ class Expression<T> extends AbstractFunction<T> {
/* [pro] xx
xxxx xxxxxxxxx x
xx xxxxxxxxx xx xxxx x
xxxxxx xxxxxxxxxx x xxxxxxxxxx xxxxx xxxx xx xxxxxx xxxxxxxxxxxxxx xxxx xxxxxxxxxxxxxxx
xxxxxx xxxxxxxxxx x xxx xxxxxx xxxxxx xxxxxxxxxxxxxx xxxx xxxxxxxxxxxxxxx
x
xxxx x
xxxxxx xxxxxxxxxx x xxxxxxxxxx xxxxx xxxx xx xxxxxx xxxxxxxxxxxxxx xxxx xxxxxxxxxxxxxxx
xxxxxx xxxxxxxxxx x xxx xxxxxx xxxxxx xxxxxxxxxxxxxx xxxx xxxxxxxxxxxxxxx
x
x

View File

@ -57,9 +57,11 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -1077,6 +1079,51 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
return Convert.convertArray(intoArray(field), converter);
}
@Override
public final Set<?> intoSet(int fieldIndex) {
return new LinkedHashSet<Object>(getValues(fieldIndex));
}
@Override
public final <T> Set<T> intoSet(int fieldIndex, Class<? extends T> type) {
return new LinkedHashSet<T>(getValues(fieldIndex, type));
}
@Override
public final <U> Set<U> intoSet(int fieldIndex, Converter<?, U> converter) {
return new LinkedHashSet<U>(getValues(fieldIndex, converter));
}
@Override
public final Set<?> intoSet(String fieldName) {
return new LinkedHashSet<Object>(getValues(fieldName));
}
@Override
public final <T> Set<T> intoSet(String fieldName, Class<? extends T> type) {
return new LinkedHashSet<T>(getValues(fieldName, type));
}
@Override
public final <U> Set<U> intoSet(String fieldName, Converter<?, U> converter) {
return new LinkedHashSet<U>(getValues(fieldName, converter));
}
@Override
public final <T> Set<T> intoSet(Field<T> field) {
return new LinkedHashSet<T>(getValues(field));
}
@Override
public final <T> Set<T> intoSet(Field<?> field, Class<? extends T> type) {
return new LinkedHashSet<T>(getValues(field, type));
}
@Override
public final <T, U> Set<U> intoSet(Field<T> field, Converter<? super T, U> converter) {
return new LinkedHashSet<U>(getValues(field, converter));
}
@Override
public final Result<Record> into(Field<?>... f) {
Result<Record> result = new ResultImpl<Record>(Utils.configuration(this), f);

View File

@ -50,6 +50,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.annotation.Generated;
@ -2594,6 +2595,51 @@ class SelectImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
return getDelegate().fetchArray(field, converter);
}
@Override
public final Set<?> fetchSet(int fieldIndex) {
return getDelegate().fetchSet(fieldIndex);
}
@Override
public final <T> Set<T> fetchSet(int fieldIndex, Class<? extends T> type) {
return getDelegate().fetchSet(fieldIndex, type);
}
@Override
public final <U> Set<U> fetchSet(int fieldIndex, Converter<?, U> converter) {
return getDelegate().fetchSet(fieldIndex, converter);
}
@Override
public final Set<?> fetchSet(String fieldName) {
return getDelegate().fetchSet(fieldName);
}
@Override
public final <T> Set<T> fetchSet(String fieldName, Class<? extends T> type) {
return getDelegate().fetchSet(fieldName, type);
}
@Override
public final <U> Set<U> fetchSet(String fieldName, Converter<?, U> converter) {
return getDelegate().fetchSet(fieldName, converter);
}
@Override
public final <T> Set<T> fetchSet(Field<T> field) {
return getDelegate().fetchSet(field);
}
@Override
public final <T> Set<T> fetchSet(Field<?> field, Class<? extends T> type) {
return getDelegate().fetchSet(field, type);
}
@Override
public final <T, U> Set<U> fetchSet(Field<T> field, Converter<? super T, U> converter) {
return getDelegate().fetchSet(field, converter);
}
@Override
public final <T> List<T> fetchInto(Class<? extends T> type) {
return getDelegate().fetchInto(type);

View File

@ -733,7 +733,7 @@ class SelectQueryImpl<R extends Record> extends AbstractSelect<R> implements Sel
// The simplest way to see if no FROM clause needs to be rendered is to
// render it. But use a new RenderContext (without any VisitListeners)
// for that purpose!
boolean hasFrom = true
boolean hasFrom = false
/* [pro] xx
xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xx xxxxx
xx [/pro] */