[#1107] Let Field.contains() support the Postgres ARRAY @> ARRAY operator

This commit is contained in:
Lukas Eder 2012-02-26 12:36:04 +00:00
parent 5951e92b69
commit 5709eb5add
34 changed files with 342 additions and 140 deletions

View File

@ -709,4 +709,41 @@ public class jOOQPostgresTest extends jOOQAbstractTest<
assertEquals(U_959.class_, result.get(1));
assertEquals(U_959.public_, result.get(2));
}
@Test
public void testPostgresArrayOperations() throws Exception {
// [#1107] The contains operator @> is implemented in Field.contains()
// -------------------------------------------------------------------
assertEquals(0,
create().selectCount()
.from(T_ARRAYS)
.where(T_ARRAYS.NUMBER_ARRAY.contains((Integer[])null))
.fetchOne(0));
assertEquals(3,
create().selectCount()
.from(T_ARRAYS)
.where(T_ARRAYS.NUMBER_ARRAY.contains(new Integer[0]))
.fetchOne(0));
assertEquals(2,
create().selectCount()
.from(T_ARRAYS)
.where(T_ARRAYS.NUMBER_ARRAY.contains(new Integer[] { 1 }))
.fetchOne(0));
assertEquals(1,
create().selectCount()
.from(T_ARRAYS)
.where(T_ARRAYS.NUMBER_ARRAY.contains(new Integer[] { 1, 2 }))
.fetchOne(0));
assertEquals(0,
create().selectCount()
.from(T_ARRAYS)
.where(T_ARRAYS.NUMBER_ARRAY.contains(new Integer[] { 1, 2, 3 }))
.fetchOne(0));
}
}

View File

@ -11,7 +11,7 @@ package org.jooq.test.postgres.generatedclasses;
public final class Routines {
/**
* Invoke F_ARRAYS
* Call public.f_arrays
*
* @param inArray
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
@ -25,7 +25,7 @@ public final class Routines {
}
/**
* Get F_ARRAYS as a field
* Get public.f_arrays as a field
*
* @param inArray
*/
@ -37,7 +37,7 @@ public final class Routines {
}
/**
* Get F_ARRAYS as a field
* Get public.f_arrays as a field
*
* @param inArray
*/
@ -49,7 +49,7 @@ public final class Routines {
}
/**
* Invoke F_ARRAYS
* Call public.f_arrays
*
* @param inArray
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
@ -63,7 +63,7 @@ public final class Routines {
}
/**
* Get F_ARRAYS as a field
* Get public.f_arrays as a field
*
* @param inArray
*/
@ -75,7 +75,7 @@ public final class Routines {
}
/**
* Get F_ARRAYS as a field
* Get public.f_arrays as a field
*
* @param inArray
*/
@ -87,7 +87,7 @@ public final class Routines {
}
/**
* Invoke F_ARRAYS
* Call public.f_arrays
*
* @param inArray
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
@ -101,7 +101,7 @@ public final class Routines {
}
/**
* Get F_ARRAYS as a field
* Get public.f_arrays as a field
*
* @param inArray
*/
@ -113,7 +113,7 @@ public final class Routines {
}
/**
* Get F_ARRAYS as a field
* Get public.f_arrays as a field
*
* @param inArray
*/
@ -125,7 +125,7 @@ public final class Routines {
}
/**
* Invoke F_AUTHOR_EXISTS
* Call public.f_author_exists
*
* @param authorName
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
@ -139,7 +139,7 @@ public final class Routines {
}
/**
* Get F_AUTHOR_EXISTS as a field
* Get public.f_author_exists as a field
*
* @param authorName
*/
@ -151,7 +151,7 @@ public final class Routines {
}
/**
* Get F_AUTHOR_EXISTS as a field
* Get public.f_author_exists as a field
*
* @param authorName
*/
@ -163,7 +163,7 @@ public final class Routines {
}
/**
* Invoke F_GET_ONE_CURSOR
* Call public.f_get_one_cursor
*
* @param bookIds
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
@ -177,7 +177,7 @@ public final class Routines {
}
/**
* Get F_GET_ONE_CURSOR as a field
* Get public.f_get_one_cursor as a field
*
* @param bookIds
*/
@ -189,7 +189,7 @@ public final class Routines {
}
/**
* Get F_GET_ONE_CURSOR as a field
* Get public.f_get_one_cursor as a field
*
* @param bookIds
*/
@ -201,7 +201,7 @@ public final class Routines {
}
/**
* Invoke F_NUMBER
* Call public.f_number
*
* @param n
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
@ -215,7 +215,7 @@ public final class Routines {
}
/**
* Get F_NUMBER as a field
* Get public.f_number as a field
*
* @param n
*/
@ -227,7 +227,7 @@ public final class Routines {
}
/**
* Get F_NUMBER as a field
* Get public.f_number as a field
*
* @param n
*/
@ -239,7 +239,7 @@ public final class Routines {
}
/**
* Invoke F_ONE
* Call public.f_one
*
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
*/
@ -251,7 +251,7 @@ public final class Routines {
}
/**
* Get F_ONE as a field
* Get public.f_one as a field
*
*/
public static org.jooq.Field<java.lang.Integer> fOne() {
@ -261,7 +261,7 @@ public final class Routines {
}
/**
* Invoke F317
* Call public.f317
*
* @param p1
* @param p2
@ -281,7 +281,7 @@ public final class Routines {
}
/**
* Get F317 as a field
* Get public.f317 as a field
*
* @param p1
* @param p2
@ -299,7 +299,7 @@ public final class Routines {
}
/**
* Get F317 as a field
* Get public.f317 as a field
*
* @param p1
* @param p2
@ -317,7 +317,7 @@ public final class Routines {
}
/**
* Invoke P_ARRAYS
* Call public.p_arrays
*
* @param inArray IN parameter
* @param outArray OUT parameter
@ -332,7 +332,7 @@ public final class Routines {
}
/**
* Invoke P_ARRAYS
* Call public.p_arrays
*
* @param inArray IN parameter
* @param outArray OUT parameter
@ -347,7 +347,7 @@ public final class Routines {
}
/**
* Invoke P_ARRAYS
* Call public.p_arrays
*
* @param inArray IN parameter
* @param outArray OUT parameter
@ -362,7 +362,7 @@ public final class Routines {
}
/**
* Invoke P_AUTHOR_EXISTS
* Call public.p_author_exists
*
* @param authorName IN parameter
* @param result OUT parameter
@ -377,7 +377,7 @@ public final class Routines {
}
/**
* Invoke P_CREATE_AUTHOR
* Call public.p_create_author
*
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
*/
@ -388,7 +388,7 @@ public final class Routines {
}
/**
* Invoke P_CREATE_AUTHOR_BY_NAME
* Call public.p_create_author_by_name
*
* @param firstName IN parameter
* @param lastName IN parameter
@ -403,7 +403,7 @@ public final class Routines {
}
/**
* Invoke P_ENHANCE_ADDRESS1
* Call public.p_enhance_address1
*
* @param address IN parameter
* @param no OUT parameter
@ -418,7 +418,7 @@ public final class Routines {
}
/**
* Invoke P_ENHANCE_ADDRESS2
* Call public.p_enhance_address2
*
* @param address OUT parameter
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
@ -431,7 +431,7 @@ public final class Routines {
}
/**
* Invoke P_ENHANCE_ADDRESS3
* Call public.p_enhance_address3
*
* @param address IN OUT parameter
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
@ -445,7 +445,7 @@ public final class Routines {
}
/**
* Invoke P_GET_ONE_CURSOR
* Call public.p_get_one_cursor
*
* @param total OUT parameter
* @param books OUT parameter
@ -461,7 +461,7 @@ public final class Routines {
}
/**
* Invoke P_GET_TWO_CURSORS
* Call public.p_get_two_cursors
*
* @param books OUT parameter
* @param authors OUT parameter
@ -475,7 +475,7 @@ public final class Routines {
}
/**
* Invoke P_TRIGGERS
* Call public.p_triggers
*
* @throws org.jooq.exception.DataAccessException if something went wrong executing the query
*/
@ -487,7 +487,7 @@ public final class Routines {
}
/**
* Get P_TRIGGERS as a field
* Get public.p_triggers as a field
*
*/
public static org.jooq.Field<java.lang.Object> pTriggers() {
@ -497,7 +497,7 @@ public final class Routines {
}
/**
* Invoke P_UNUSED
* Call public.p_unused
*
* @param in1 IN parameter
* @param out1 OUT parameter
@ -514,7 +514,7 @@ public final class Routines {
}
/**
* Invoke P391
* Call public.p391
*
* @param i1 IN parameter
* @param io1 IN OUT parameter

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TArrays extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TArraysRecord> {
private static final long serialVersionUID = 1751903858;
private static final long serialVersionUID = -669017663;
/**
* The singleton instance of t_arrays
* The singleton instance of public.t_arrays
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TArrays T_ARRAYS = new org.jooq.test.postgres.generatedclasses.tables.TArrays();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TAuthor extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TAuthorRecord> {
private static final long serialVersionUID = 860783999;
private static final long serialVersionUID = -7636340;
/**
* The singleton instance of t_author
* The singleton instance of public.t_author
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TAuthor T_AUTHOR = new org.jooq.test.postgres.generatedclasses.tables.TAuthor();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TBook extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TBookRecord> {
private static final long serialVersionUID = 884711017;
private static final long serialVersionUID = -1441052876;
/**
* The singleton instance of t_book
* The singleton instance of public.t_book
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TBook T_BOOK = new org.jooq.test.postgres.generatedclasses.tables.TBook();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TBookStore extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TBookStoreRecord> {
private static final long serialVersionUID = 1823166931;
private static final long serialVersionUID = 882832138;
/**
* The singleton instance of t_book_store
* The singleton instance of public.t_book_store
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TBookStore T_BOOK_STORE = new org.jooq.test.postgres.generatedclasses.tables.TBookStore();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TBookToBookStore extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TBookToBookStoreRecord> {
private static final long serialVersionUID = -647448628;
private static final long serialVersionUID = 974465859;
/**
* The singleton instance of t_book_to_book_store
* The singleton instance of public.t_book_to_book_store
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TBookToBookStore T_BOOK_TO_BOOK_STORE = new org.jooq.test.postgres.generatedclasses.tables.TBookToBookStore();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TBooleans extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TBooleansRecord> {
private static final long serialVersionUID = 1774781543;
private static final long serialVersionUID = 1994252730;
/**
* The singleton instance of t_booleans
* The singleton instance of public.t_booleans
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TBooleans T_BOOLEANS = new org.jooq.test.postgres.generatedclasses.tables.TBooleans();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TDates extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TDatesRecord> {
private static final long serialVersionUID = -1409756932;
private static final long serialVersionUID = 335309541;
/**
* The singleton instance of t_dates
* The singleton instance of public.t_dates
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TDates T_DATES = new org.jooq.test.postgres.generatedclasses.tables.TDates();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TIdentity extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TIdentityRecord> {
private static final long serialVersionUID = -1727765735;
private static final long serialVersionUID = -471519130;
/**
* The singleton instance of t_identity
* The singleton instance of public.t_identity
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TIdentity T_IDENTITY = new org.jooq.test.postgres.generatedclasses.tables.TIdentity();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TIdentityPk extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TIdentityPkRecord> {
private static final long serialVersionUID = 217982289;
private static final long serialVersionUID = 642491046;
/**
* The singleton instance of t_identity_pk
* The singleton instance of public.t_identity_pk
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TIdentityPk T_IDENTITY_PK = new org.jooq.test.postgres.generatedclasses.tables.TIdentityPk();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class TTriggers extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.TTriggersRecord> {
private static final long serialVersionUID = 1722759821;
private static final long serialVersionUID = -1990301350;
/**
* The singleton instance of t_triggers
* The singleton instance of public.t_triggers
*/
public static final org.jooq.test.postgres.generatedclasses.tables.TTriggers T_TRIGGERS = new org.jooq.test.postgres.generatedclasses.tables.TTriggers();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class T_639NumbersTable extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.T_639NumbersTableRecord> {
private static final long serialVersionUID = -395812328;
private static final long serialVersionUID = 1784568845;
/**
* The singleton instance of t_639_numbers_table
* The singleton instance of public.t_639_numbers_table
*/
public static final org.jooq.test.postgres.generatedclasses.tables.T_639NumbersTable T_639_NUMBERS_TABLE = new org.jooq.test.postgres.generatedclasses.tables.T_639NumbersTable();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class T_658Ref extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.T_658RefRecord> {
private static final long serialVersionUID = -900598214;
private static final long serialVersionUID = 1661790169;
/**
* The singleton instance of t_658_ref
* The singleton instance of public.t_658_ref
*/
public static final org.jooq.test.postgres.generatedclasses.tables.T_658Ref T_658_REF = new org.jooq.test.postgres.generatedclasses.tables.T_658Ref();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class T_725LobTest extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.T_725LobTestRecord> {
private static final long serialVersionUID = -1348018481;
private static final long serialVersionUID = 1840202374;
/**
* The singleton instance of t_725_lob_test
* The singleton instance of public.t_725_lob_test
*/
public static final org.jooq.test.postgres.generatedclasses.tables.T_725LobTest T_725_LOB_TEST = new org.jooq.test.postgres.generatedclasses.tables.T_725LobTest();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class T_785 extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.T_785Record> {
private static final long serialVersionUID = 49630399;
private static final long serialVersionUID = 421993292;
/**
* The singleton instance of t_785
* The singleton instance of public.t_785
*/
public static final org.jooq.test.postgres.generatedclasses.tables.T_785 T_785 = new org.jooq.test.postgres.generatedclasses.tables.T_785();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class T_959 extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.T_959Record> {
private static final long serialVersionUID = -1003664711;
private static final long serialVersionUID = -744425146;
/**
* The singleton instance of t_959
* The singleton instance of public.t_959
*/
public static final org.jooq.test.postgres.generatedclasses.tables.T_959 T_959 = new org.jooq.test.postgres.generatedclasses.tables.T_959();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class T_986_1 extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.T_986_1Record> {
private static final long serialVersionUID = -469380001;
private static final long serialVersionUID = 1559256172;
/**
* The singleton instance of t_986_1
* The singleton instance of public.t_986_1
*/
public static final org.jooq.test.postgres.generatedclasses.tables.T_986_1 T_986_1 = new org.jooq.test.postgres.generatedclasses.tables.T_986_1();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class T_986_2 extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.T_986_2Record> {
private static final long serialVersionUID = -1770651142;
private static final long serialVersionUID = -630772153;
/**
* The singleton instance of t_986_2
* The singleton instance of public.t_986_2
*/
public static final org.jooq.test.postgres.generatedclasses.tables.T_986_2 T_986_2 = new org.jooq.test.postgres.generatedclasses.tables.T_986_2();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class VAuthor extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.VAuthorRecord> {
private static final long serialVersionUID = 307768556;
private static final long serialVersionUID = 2083650111;
/**
* The singleton instance of v_author
* The singleton instance of public.v_author
*/
public static final org.jooq.test.postgres.generatedclasses.tables.VAuthor V_AUTHOR = new org.jooq.test.postgres.generatedclasses.tables.VAuthor();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class VBook extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.VBookRecord> {
private static final long serialVersionUID = -1755327145;
private static final long serialVersionUID = -53666140;
/**
* The singleton instance of v_book
* The singleton instance of public.v_book
*/
public static final org.jooq.test.postgres.generatedclasses.tables.VBook V_BOOK = new org.jooq.test.postgres.generatedclasses.tables.VBook();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class VLibrary extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.VLibraryRecord> {
private static final long serialVersionUID = 285477391;
private static final long serialVersionUID = 1225516368;
/**
* The singleton instance of v_library
* The singleton instance of public.v_library
*/
public static final org.jooq.test.postgres.generatedclasses.tables.VLibrary V_LIBRARY = new org.jooq.test.postgres.generatedclasses.tables.VLibrary();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class XTestCase_64_69 extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.XTestCase_64_69Record> {
private static final long serialVersionUID = -331440754;
private static final long serialVersionUID = 325449761;
/**
* The singleton instance of x_test_case_64_69
* The singleton instance of public.x_test_case_64_69
*/
public static final org.jooq.test.postgres.generatedclasses.tables.XTestCase_64_69 X_TEST_CASE_64_69 = new org.jooq.test.postgres.generatedclasses.tables.XTestCase_64_69();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class XTestCase_71 extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.XTestCase_71Record> {
private static final long serialVersionUID = 8582864;
private static final long serialVersionUID = -962881081;
/**
* The singleton instance of x_test_case_71
* The singleton instance of public.x_test_case_71
*/
public static final org.jooq.test.postgres.generatedclasses.tables.XTestCase_71 X_TEST_CASE_71 = new org.jooq.test.postgres.generatedclasses.tables.XTestCase_71();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class XTestCase_85 extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.XTestCase_85Record> {
private static final long serialVersionUID = 1044283848;
private static final long serialVersionUID = -1878057551;
/**
* The singleton instance of x_test_case_85
* The singleton instance of public.x_test_case_85
*/
public static final org.jooq.test.postgres.generatedclasses.tables.XTestCase_85 X_TEST_CASE_85 = new org.jooq.test.postgres.generatedclasses.tables.XTestCase_85();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.tables;
*/
public class XUnused extends org.jooq.impl.UpdatableTableImpl<org.jooq.test.postgres.generatedclasses.tables.records.XUnusedRecord> {
private static final long serialVersionUID = 1418269432;
private static final long serialVersionUID = 1016898761;
/**
* The singleton instance of x_unused
* The singleton instance of public.x_unused
*/
public static final org.jooq.test.postgres.generatedclasses.tables.XUnused X_UNUSED = new org.jooq.test.postgres.generatedclasses.tables.XUnused();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.udt;
*/
public class UAddressType extends org.jooq.impl.UDTImpl<org.jooq.test.postgres.generatedclasses.udt.records.UAddressTypeRecord> {
private static final long serialVersionUID = 1787194541;
private static final long serialVersionUID = -15622476;
/**
* The singleton instance of u_address_type
* The singleton instance of public.u_address_type
*/
public static final org.jooq.test.postgres.generatedclasses.udt.UAddressType U_ADDRESS_TYPE = new org.jooq.test.postgres.generatedclasses.udt.UAddressType();

View File

@ -8,10 +8,10 @@ package org.jooq.test.postgres.generatedclasses.udt;
*/
public class UStreetType extends org.jooq.impl.UDTImpl<org.jooq.test.postgres.generatedclasses.udt.records.UStreetTypeRecord> {
private static final long serialVersionUID = -318438597;
private static final long serialVersionUID = -578196600;
/**
* The singleton instance of u_street_type
* The singleton instance of public.u_street_type
*/
public static final org.jooq.test.postgres.generatedclasses.udt.UStreetType U_STREET_TYPE = new org.jooq.test.postgres.generatedclasses.udt.UStreetType();

View File

@ -60,11 +60,7 @@ INSERT INTO t_book_to_book_store VALUES ('Ex Libris', 1, 1)/
INSERT INTO t_book_to_book_store VALUES ('Ex Libris', 3, 2)/
INSERT INTO t_book_to_book_store VALUES ('Buchhandlung im Volkshaus', 3, 1)/
INSERT INTO t_arrays VALUES (1, null, null, null, null, null, null)
/
INSERT INTO t_arrays VALUES (2, '{}', '{}', '{}', '{}', '{}', '{}')
/
INSERT INTO t_arrays VALUES (3, '{"a"}', '{1}', ARRAY[TO_DATE('1981-07-10', 'YYYY-MM-DD')], ARRAY[ROW('Downing Street', '10', null)]::u_street_type[], '{"England"}', ARRAY[ARRAY[1]])
/
INSERT INTO t_arrays VALUES (4, '{"a", "b"}', '{1, 2}', ARRAY[TO_DATE('1981-07-10', 'YYYY-MM-DD'), TO_DATE('2000-01-01', 'YYYY-MM-DD')], ARRAY[ROW('Downing Street', '10', '{}'), ROW('Bahnhofstrasse', '12', '{1, 2}')]::u_street_type[], '{"England", "Germany"}', ARRAY[ARRAY[1], ARRAY[2]])
/
INSERT INTO t_arrays VALUES (1, null, null, null, null, null, null)/
INSERT INTO t_arrays VALUES (2, '{}', '{}', '{}', '{}', '{}', '{}')/
INSERT INTO t_arrays VALUES (3, '{"a"}', '{1}', ARRAY[TO_DATE('1981-07-10', 'YYYY-MM-DD')], ARRAY[ROW('Downing Street', '10', null)]::u_street_type[], '{"England"}', ARRAY[ARRAY[1]])/
INSERT INTO t_arrays VALUES (4, '{"a", "b"}', '{1, 2}', ARRAY[TO_DATE('1981-07-10', 'YYYY-MM-DD'), TO_DATE('2000-01-01', 'YYYY-MM-DD')], ARRAY[ROW('Downing Street', '10', '{}'), ROW('Bahnhofstrasse', '12', '{1, 2}')]::u_street_type[], '{"England", "Germany"}', ARRAY[ARRAY[1], ARRAY[2]])/

View File

@ -483,6 +483,15 @@ public interface Field<T> extends NamedTypeProviderQueryPart<T>, AliasProvider<F
* <p>
* Note: This also works with numbers, for instance
* <code>val(1133).contains(13)</code>
* <p>
* If you're using {@link SQLDialect#POSTGRES}, then you can use this method also to express the "ARRAY contains" operator. For example:
* <code><pre>
* // Use this expression
* val(new Integer[] { 1, 2, 3 }).contains(new Integer[] { 1, 2 })
*
* // ... to render this SQL
* ARRAY[1, 2, 3] @> ARRAY[1, 2]
* </pre></code>
*
* @see Factory#escape(String, char)
* @see #like(Object, char)
@ -498,6 +507,15 @@ public interface Field<T> extends NamedTypeProviderQueryPart<T>, AliasProvider<F
* <p>
* Note: This also works with numbers, for instance
* <code>val(1133).contains(13)</code>
* <p>
* If you're using {@link SQLDialect#POSTGRES}, then you can use this method also to express the "ARRAY contains" operator. For example:
* <code><pre>
* // Use this expression
* val(new Integer[] { 1, 2, 3 }).contains(new Integer[] { 1, 2 })
*
* // ... to render this SQL
* ARRAY[1, 2, 3] @> ARRAY[1, 2]
* </pre></code>
*
* @see Factory#escape(Field, char)
* @see #like(Field, char)

View File

@ -39,7 +39,6 @@ import static org.jooq.impl.ExpressionOperator.ADD;
import static org.jooq.impl.ExpressionOperator.DIVIDE;
import static org.jooq.impl.ExpressionOperator.MULTIPLY;
import static org.jooq.impl.ExpressionOperator.SUBTRACT;
import static org.jooq.impl.Factory.escape;
import static org.jooq.impl.Factory.falseCondition;
import static org.jooq.impl.Factory.literal;
import static org.jooq.impl.Factory.nullSafe;
@ -79,7 +78,6 @@ abstract class AbstractField<T> extends AbstractNamedTypeProviderQueryPart<T> im
* Generated UID
*/
private static final long serialVersionUID = 2884811923648354905L;
private static final char ESCAPE = '!';
AbstractField(String name, DataType<T> type) {
super(name, type);
@ -383,63 +381,36 @@ abstract class AbstractField<T> extends AbstractNamedTypeProviderQueryPart<T> im
@Override
public final Condition contains(T value) {
Field<String> concat = Factory.concat(literal("'%'"), escapeForLike(value), literal("'%'"));
return like(concat, ESCAPE);
return new Contains<T>(this, value);
}
@Override
public final Condition contains(Field<T> value) {
Field<String> concat = Factory.concat(literal("'%'"), escapeForLike(value), literal("'%'"));
return like(concat, ESCAPE);
return new Contains<T>(this, value);
}
@Override
public final Condition startsWith(T value) {
Field<String> concat = Factory.concat(escapeForLike(value), literal("'%'"));
return like(concat, ESCAPE);
Field<String> concat = Factory.concat(Util.escapeForLike(value), literal("'%'"));
return like(concat, Util.ESCAPE);
}
@Override
public final Condition startsWith(Field<T> value) {
Field<String> concat = Factory.concat(escapeForLike(value), literal("'%'"));
return like(concat, ESCAPE);
Field<String> concat = Factory.concat(Util.escapeForLike(value), literal("'%'"));
return like(concat, Util.ESCAPE);
}
@Override
public final Condition endsWith(T value) {
Field<String> concat = Factory.concat(literal("'%'"), escapeForLike(value));
return like(concat, ESCAPE);
Field<String> concat = Factory.concat(literal("'%'"), Util.escapeForLike(value));
return like(concat, Util.ESCAPE);
}
@Override
public final Condition endsWith(Field<T> value) {
Field<String> concat = Factory.concat(literal("'%'"), escapeForLike(value));
return like(concat, ESCAPE);
}
/**
* Utility method to escape strings or "toString" other objects
*/
private final Field<String> escapeForLike(Object value) {
if (value != null && value.getClass() == String.class) {
return val(escape("" + value, ESCAPE));
}
else {
return val("" + value);
}
}
/**
* Utility method to escape string fields, or cast other fields
*/
@SuppressWarnings("unchecked")
private final Field<String> escapeForLike(Field<?> field) {
if (nullSafe(field).getDataType().isString()) {
return escape((Field<String>) field, ESCAPE);
}
else {
return field.cast(String.class);
}
Field<String> concat = Factory.concat(literal("'%'"), Util.escapeForLike(value));
return like(concat, Util.ESCAPE);
}
@Override

View File

@ -96,7 +96,9 @@ class AttachableImpl implements AttachableInternal {
}
for (Attachable attachable : getAttachables()) {
attachable.attach(c);
if (attachable != null) {
attachable.attach(c);
}
}
}

View File

@ -0,0 +1,144 @@
/**
* Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* . Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* . 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.
*
* . 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.
*
* 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.
*/
package org.jooq.impl;
import static org.jooq.impl.Factory.literal;
import static org.jooq.impl.Factory.val;
import java.util.List;
import org.jooq.Attachable;
import org.jooq.BindContext;
import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.RenderContext;
import org.jooq.exception.DataAccessException;
/**
* Abstraction for various "contains" operations
*
* @author Lukas Eder
*/
class Contains<T> extends AbstractCondition {
/**
* Generated UID
*/
private static final long serialVersionUID = 6146303086487338550L;
private final Field<T> lhs;
private final Field<T> rhs;
private final T value;
Contains(Field<T> field, T value) {
this.lhs = field;
this.rhs = null;
this.value = value;
}
Contains(Field<T> field, Field<T> rhs) {
this.lhs = field;
this.rhs = rhs;
this.value = null;
}
@Override
public final void toSQL(RenderContext context) {
context.sql(condition());
}
@Override
public final void bind(BindContext context) throws DataAccessException {
context.bind(condition());
}
@Override
public final List<Attachable> getAttachables() {
return getAttachables(lhs, rhs);
}
private final Condition condition() {
// [#1107] Some dialects support "contains" operations for ARRAYs
if (lhs.getDataType().isArray()) {
return new PostgresArrayContains();
}
// "contains" operations on Strings
else {
Field<String> concat;
if (rhs == null) {
concat = Factory.concat(literal("'%'"), Util.escapeForLike(value), literal("'%'"));
}
else {
concat = Factory.concat(literal("'%'"), Util.escapeForLike(rhs), literal("'%'"));
}
return lhs.like(concat, Util.ESCAPE);
}
}
/**
* The Postgres array contains operator
*/
private class PostgresArrayContains extends AbstractCondition {
/**
* Generated UID
*/
private static final long serialVersionUID = 8083622843635168388L;
@Override
public final void toSQL(RenderContext context) {
context.sql(lhs).sql(" @> ").sql(rhs());
}
@Override
public final void bind(BindContext context) throws DataAccessException {
context.bind(lhs).bind(rhs());
}
private final Field<T> rhs() {
return (rhs == null) ? val(value) : rhs;
}
@Override
public List<Attachable> getAttachables() {
return getAttachables(lhs, rhs);
}
}
}

View File

@ -37,7 +37,10 @@ package org.jooq.impl;
import static java.lang.Boolean.FALSE;
import static java.lang.Integer.toOctalString;
import static org.jooq.impl.Factory.escape;
import static org.jooq.impl.Factory.getDataType;
import static org.jooq.impl.Factory.nullSafe;
import static org.jooq.impl.Factory.val;
import static org.jooq.tools.StringUtils.leftPad;
import java.lang.reflect.Constructor;
@ -81,17 +84,23 @@ import org.jooq.tools.StopWatchListener;
import org.jooq.tools.StringUtils;
/**
* General jooq utilities
* General jOOQ utilities
*
* @author Lukas Eder
*/
final class Util {
/**
* The default escape character for <code>[a] LIKE [b] ESCAPE [...]</code>
* clauses.
*/
static final char ESCAPE = '!';
/**
* Indicating whether JPA (<code>javax.persistence</code>) is on the
* classpath.
*/
private static Boolean isJPAAvailable;
private static Boolean isJPAAvailable;
/**
* Create a new Oracle-style VARRAY {@link ArrayRecord}
@ -926,4 +935,29 @@ final class Util {
return sb.toString();
}
/**
* Utility method to escape strings or "toString" other objects
*/
static final Field<String> escapeForLike(Object value) {
if (value != null && value.getClass() == String.class) {
return val(escape("" + value, ESCAPE));
}
else {
return val("" + value);
}
}
/**
* Utility method to escape string fields, or cast other fields
*/
@SuppressWarnings("unchecked")
static final Field<String> escapeForLike(Field<?> field) {
if (nullSafe(field).getDataType().isString()) {
return escape((Field<String>) field, ESCAPE);
}
else {
return field.cast(String.class);
}
}
}