[#2626] Hide current Template implementation from public. This may not
make it into jOOQ 3.2
This commit is contained in:
parent
69573b1ea1
commit
83d9fe33a9
@ -1,158 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2009-2013, 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.test._.testcases;
|
||||
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
import static org.jooq.impl.DSL.queryPart;
|
||||
import static org.jooq.impl.DSL.val;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.sql.Date;
|
||||
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.Record2;
|
||||
import org.jooq.Record3;
|
||||
import org.jooq.Record6;
|
||||
import org.jooq.TableRecord;
|
||||
import org.jooq.Template;
|
||||
import org.jooq.UpdatableRecord;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.test.BaseTest;
|
||||
import org.jooq.test.jOOQAbstractTest;
|
||||
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.apache.velocity.runtime.RuntimeConstants;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TemplateTests<
|
||||
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 TemplateTests(jOOQAbstractTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T725, T639, T785> delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextTemplates() throws Exception {
|
||||
class TextTemplate implements Template {
|
||||
|
||||
private final String sql;
|
||||
|
||||
public TextTemplate(String sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryPart transform(Object... input) {
|
||||
return queryPart(sql, input);
|
||||
}
|
||||
}
|
||||
|
||||
Record r1 =
|
||||
create().resultQuery(new TextTemplate("SELECT ? as x FROM t_author a WHERE a.id IN (?, ?) ORDER BY a.id"), 1, 2, 3)
|
||||
.fetchOne();
|
||||
assertTextTemplateRecord(r1);
|
||||
|
||||
Record r2 =
|
||||
create().resultQuery(new TextTemplate("SELECT {0} as x FROM t_author a WHERE a.id IN ({1}, {2}) ORDER BY a.id"), val(1), inline(2), inline(3))
|
||||
.fetchOne();
|
||||
assertTextTemplateRecord(r2);
|
||||
}
|
||||
|
||||
private void assertTextTemplateRecord(Record record) {
|
||||
assertEquals(1, record.fields().length);
|
||||
assertEquals("x", record.field(0).getName().toLowerCase());
|
||||
assertEquals(1, (int) record.getValue(0, int.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVelocityTemplates() throws Exception {
|
||||
class VelocityTemplate implements Template {
|
||||
|
||||
private final String file;
|
||||
|
||||
public VelocityTemplate(String file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryPart transform(Object... input) {
|
||||
URL url = this.getClass().getResource("/org/jooq/test/_/templates/");
|
||||
|
||||
VelocityEngine ve = new VelocityEngine();
|
||||
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
|
||||
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, new File(url.getFile()).getAbsolutePath());
|
||||
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
|
||||
ve.init();
|
||||
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("p", input);
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
ve.getTemplate(file, "UTF-8").merge(context, writer);
|
||||
return DSL.queryPart(writer.toString(), input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
create().resultQuery(new VelocityTemplate("authors-and-books.vm"), 1, 2, 3)
|
||||
.fetch();
|
||||
}
|
||||
}
|
||||
@ -143,7 +143,6 @@ import org.jooq.test._.testcases.RowValueExpressionTests;
|
||||
import org.jooq.test._.testcases.SchemaAndMappingTests;
|
||||
import org.jooq.test._.testcases.SelectTests;
|
||||
import org.jooq.test._.testcases.StatementTests;
|
||||
import org.jooq.test._.testcases.TemplateTests;
|
||||
import org.jooq.test._.testcases.ThreadSafetyTests;
|
||||
import org.jooq.test._.testcases.TruncateTests;
|
||||
import org.jooq.test._.testcases.ValuesConstructorTests;
|
||||
@ -1150,16 +1149,6 @@ public abstract class jOOQAbstractTest<
|
||||
new PlainSQLTests(this).testCustomSQL();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextTemplates() throws Exception {
|
||||
new TemplateTests(this).testTextTemplates();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVelocityTemplates() throws Exception {
|
||||
new TemplateTests(this).testVelocityTemplates();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsignedDataTypes() throws Exception {
|
||||
new DataTypeTests(this).testUnsignedDataTypes();
|
||||
|
||||
@ -374,16 +374,6 @@ public interface DSLContext {
|
||||
@Support
|
||||
Query query(String sql, QueryPart... parts);
|
||||
|
||||
/**
|
||||
* Create a new query from a template.
|
||||
*
|
||||
* @param template The template generating a delegate query part
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return A query wrapping the template's output
|
||||
*/
|
||||
@Support
|
||||
Query query(Template template, Object... parameters);
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
@ -470,17 +460,6 @@ public interface DSLContext {
|
||||
@Support
|
||||
Result<Record> fetch(String sql, QueryPart... parts) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a new query from a template.
|
||||
*
|
||||
* @param template The template generating a delegate query part
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return The results from the executed query
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
@Support
|
||||
Result<Record> fetch(Template template, Object... parameters) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL and "lazily" return the generated
|
||||
* result.
|
||||
@ -585,18 +564,6 @@ public interface DSLContext {
|
||||
@Support
|
||||
Cursor<Record> fetchLazy(String sql, QueryPart... parts) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a new query from a template and "lazily" return the generated
|
||||
* result.
|
||||
*
|
||||
* @param template The template generating a delegate query part
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return The results from the executed query
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
@Support
|
||||
Cursor<Record> fetchLazy(Template template, Object... parameters) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL, possibly returning several result
|
||||
* sets.
|
||||
@ -678,18 +645,6 @@ public interface DSLContext {
|
||||
@Support
|
||||
List<Result<Record>> fetchMany(String sql, QueryPart... parts) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a new query from a template, possibly returning several result
|
||||
* sets.
|
||||
*
|
||||
* @param template The template generating a delegate query part
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return The results from the executed query
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
@Support
|
||||
List<Result<Record>> fetchMany(Template template, Object... parameters) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
@ -779,19 +734,6 @@ public interface DSLContext {
|
||||
@Support
|
||||
Record fetchOne(String sql, QueryPart... parts) throws DataAccessException, InvalidResultException;
|
||||
|
||||
/**
|
||||
* Execute a new query from a template.
|
||||
*
|
||||
* @param template The template generating a delegate query part
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return The results from the executed query. This may be
|
||||
* <code>null</code> if the database returned no records
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws InvalidResultException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
Record fetchOne(Template template, Object... parameters) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query holding plain SQL.
|
||||
* <p>
|
||||
@ -856,17 +798,6 @@ public interface DSLContext {
|
||||
@Support
|
||||
int execute(String sql, QueryPart... parts) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a new query from a template.
|
||||
*
|
||||
* @param template The template generating a delegate query part
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return The results from the executed query
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
@Support
|
||||
int execute(Template template, Object... parameters) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Create a new query holding plain SQL.
|
||||
* <p>
|
||||
@ -986,16 +917,6 @@ public interface DSLContext {
|
||||
@Support
|
||||
ResultQuery<Record> resultQuery(String sql, QueryPart... parts);
|
||||
|
||||
/**
|
||||
* Create a new query from a template.
|
||||
*
|
||||
* @param template The template generating a delegate query part
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return An executable query
|
||||
*/
|
||||
@Support
|
||||
ResultQuery<Record> resultQuery(Template template, Object... parameters);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX JDBC convenience methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -105,9 +105,13 @@ package org.jooq;
|
||||
* ORDER BY
|
||||
* a.id ASC
|
||||
* </pre></code>
|
||||
* <p>
|
||||
*
|
||||
* @deprecated - This type is still very experimental and not yet released to a
|
||||
* broad public. Do not use this type yet.
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
@Deprecated
|
||||
public interface Template {
|
||||
|
||||
/**
|
||||
|
||||
@ -194,7 +194,6 @@ import org.jooq.SelectSelectStep;
|
||||
import org.jooq.SelectWhereStep;
|
||||
import org.jooq.Support;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.Template;
|
||||
import org.jooq.TruncateIdentityStep;
|
||||
import org.jooq.UDTRecord;
|
||||
import org.jooq.Update;
|
||||
@ -4866,14 +4865,15 @@ public class DSL {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a new {@link Template} that can transform parameter objects into a
|
||||
* {@link QueryPart}.
|
||||
* Create a new {@link org.jooq.Template} that can transform parameter
|
||||
* objects into a {@link QueryPart}.
|
||||
*
|
||||
* @param sql The input SQL.
|
||||
* @return A template that can transform parameter objects into a
|
||||
* {@link QueryPart}.
|
||||
*/
|
||||
public static Template template(String sql) {
|
||||
@SuppressWarnings("deprecation")
|
||||
static org.jooq.Template template(String sql) {
|
||||
return new SQLTemplate(sql);
|
||||
}
|
||||
|
||||
@ -4949,8 +4949,9 @@ public class DSL {
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return A query part wrapping the plain SQL
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Support
|
||||
public static QueryPart queryPart(Template template, Object... parameters) {
|
||||
static QueryPart queryPart(org.jooq.Template template, Object... parameters) {
|
||||
return template.transform(parameters);
|
||||
}
|
||||
|
||||
@ -5062,8 +5063,9 @@ public class DSL {
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return A query part wrapping the plain SQL
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Support
|
||||
public static Table<Record> table(Template template, Object... parameters) {
|
||||
static Table<Record> table(org.jooq.Template template, Object... parameters) {
|
||||
return new SQLTable(queryPart(template, parameters));
|
||||
}
|
||||
|
||||
@ -5345,8 +5347,9 @@ public class DSL {
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return A query part wrapping the plain SQL
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Support
|
||||
public static Field<Object> field(Template template, Object... parameters) {
|
||||
static Field<Object> field(org.jooq.Template template, Object... parameters) {
|
||||
return field(template, Object.class, parameters);
|
||||
}
|
||||
|
||||
@ -5359,8 +5362,9 @@ public class DSL {
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return A query part wrapping the plain SQL
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Support
|
||||
public static <T> Field<T> field(Template template, Class<T> type, Object... parameters) {
|
||||
static <T> Field<T> field(org.jooq.Template template, Class<T> type, Object... parameters) {
|
||||
return field(template, getDataType(type), parameters);
|
||||
}
|
||||
|
||||
@ -5373,8 +5377,9 @@ public class DSL {
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return A query part wrapping the plain SQL
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Support
|
||||
public static <T> Field<T> field(Template template, DataType<T> type, Object... parameters) {
|
||||
static <T> Field<T> field(org.jooq.Template template, DataType<T> type, Object... parameters) {
|
||||
return new SQLField<T>(type, queryPart(template, parameters));
|
||||
}
|
||||
|
||||
@ -5526,8 +5531,9 @@ public class DSL {
|
||||
* @param parameters The parameters provided to the template
|
||||
* @return A query part wrapping the plain SQL
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Support
|
||||
public static Condition condition(Template template, Object... parameters) {
|
||||
static Condition condition(org.jooq.Template template, Object... parameters) {
|
||||
return new SQLCondition(queryPart(template, parameters));
|
||||
}
|
||||
|
||||
|
||||
@ -169,7 +169,6 @@ import org.jooq.Sequence;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableLike;
|
||||
import org.jooq.TableRecord;
|
||||
import org.jooq.Template;
|
||||
import org.jooq.TruncateIdentityStep;
|
||||
import org.jooq.UDT;
|
||||
import org.jooq.UDTRecord;
|
||||
@ -370,8 +369,8 @@ public class DefaultDSLContext implements DSLContext, Serializable {
|
||||
return query(template(sql), (Object[]) parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query query(Template template, Object... parameters) {
|
||||
@SuppressWarnings("deprecation")
|
||||
Query query(org.jooq.Template template, Object... parameters) {
|
||||
return new SQLQuery(configuration, queryPart(template, parameters));
|
||||
}
|
||||
|
||||
@ -390,8 +389,8 @@ public class DefaultDSLContext implements DSLContext, Serializable {
|
||||
return resultQuery(sql, parts).fetch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Record> fetch(Template template, Object... parameters) {
|
||||
@SuppressWarnings("deprecation")
|
||||
Result<Record> fetch(org.jooq.Template template, Object... parameters) {
|
||||
return resultQuery(template, parameters).fetch();
|
||||
}
|
||||
|
||||
@ -410,8 +409,8 @@ public class DefaultDSLContext implements DSLContext, Serializable {
|
||||
return resultQuery(sql, parts).fetchLazy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor<Record> fetchLazy(Template template, Object... parameters) {
|
||||
@SuppressWarnings("deprecation")
|
||||
Cursor<Record> fetchLazy(org.jooq.Template template, Object... parameters) {
|
||||
return resultQuery(template, parameters).fetchLazy();
|
||||
}
|
||||
|
||||
@ -430,8 +429,8 @@ public class DefaultDSLContext implements DSLContext, Serializable {
|
||||
return resultQuery(sql, parts).fetchMany();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Result<Record>> fetchMany(Template template, Object... parameters) {
|
||||
@SuppressWarnings("deprecation")
|
||||
List<Result<Record>> fetchMany(org.jooq.Template template, Object... parameters) {
|
||||
return resultQuery(template, parameters).fetchMany();
|
||||
}
|
||||
|
||||
@ -450,8 +449,8 @@ public class DefaultDSLContext implements DSLContext, Serializable {
|
||||
return resultQuery(sql, parts).fetchOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Record fetchOne(Template template, Object... parameters) {
|
||||
@SuppressWarnings("deprecation")
|
||||
Record fetchOne(org.jooq.Template template, Object... parameters) {
|
||||
return resultQuery(template, parameters).fetchOne();
|
||||
}
|
||||
|
||||
@ -470,8 +469,8 @@ public class DefaultDSLContext implements DSLContext, Serializable {
|
||||
return query(sql, parts).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int execute(Template template, Object... parameters) {
|
||||
@SuppressWarnings("deprecation")
|
||||
int execute(org.jooq.Template template, Object... parameters) {
|
||||
return query(template, parameters).execute();
|
||||
}
|
||||
|
||||
@ -490,8 +489,8 @@ public class DefaultDSLContext implements DSLContext, Serializable {
|
||||
return resultQuery(template(sql), (Object[]) parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultQuery<Record> resultQuery(Template template, Object... parameters) {
|
||||
@SuppressWarnings("deprecation")
|
||||
ResultQuery<Record> resultQuery(org.jooq.Template template, Object... parameters) {
|
||||
return new SQLResultQuery(configuration, queryPart(template, parameters));
|
||||
}
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ import org.jooq.QueryPart;
|
||||
import org.jooq.RenderContext;
|
||||
import org.jooq.Template;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class SQLTemplate implements Template {
|
||||
|
||||
private final String sql;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user