diff --git a/jOOQ-test/src/org/jooq/test/_/testcases/TemplateTests.java b/jOOQ-test/src/org/jooq/test/_/testcases/TemplateTests.java deleted file mode 100644 index 5c3ca39d0a..0000000000 --- a/jOOQ-test/src/org/jooq/test/_/testcases/TemplateTests.java +++ /dev/null @@ -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 & Record6, - AP, - B extends UpdatableRecord, - S extends UpdatableRecord & Record1, - B2S extends UpdatableRecord & Record3, - BS extends UpdatableRecord, - L extends TableRecord & Record2, - X extends TableRecord, - DATE extends UpdatableRecord, - BOOL extends UpdatableRecord, - D extends UpdatableRecord, - T extends UpdatableRecord, - U extends TableRecord, - UU extends UpdatableRecord, - I extends TableRecord, - IPK extends UpdatableRecord, - T725 extends UpdatableRecord, - T639 extends UpdatableRecord, - T785 extends TableRecord> -extends BaseTest { - - public TemplateTests(jOOQAbstractTest 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(); - } -} diff --git a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java index 86899bd9db..a67bf9aa6a 100644 --- a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java +++ b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java @@ -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(); diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 25c89fd087..53998b541f 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -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. *

@@ -470,17 +460,6 @@ public interface DSLContext { @Support Result 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 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 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 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> 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> fetchMany(Template template, Object... parameters) throws DataAccessException; - /** * Execute a new query holding plain SQL. *

@@ -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 - * null 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. *

@@ -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. *

@@ -986,16 +917,6 @@ public interface DSLContext { @Support ResultQuery 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 resultQuery(Template template, Object... parameters); - // ------------------------------------------------------------------------- // XXX JDBC convenience methods // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/Template.java b/jOOQ/src/main/java/org/jooq/Template.java index 398bbddd85..3c72102b9a 100644 --- a/jOOQ/src/main/java/org/jooq/Template.java +++ b/jOOQ/src/main/java/org/jooq/Template.java @@ -105,9 +105,13 @@ package org.jooq; * ORDER BY * a.id ASC * + *

* + * @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 { /** diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 3dab2f600b..eb55965e89 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -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 table(Template template, Object... parameters) { + static Table 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 field(Template template, Object... parameters) { + static Field 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 Field field(Template template, Class type, Object... parameters) { + static Field field(org.jooq.Template template, Class 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 Field field(Template template, DataType type, Object... parameters) { + static Field field(org.jooq.Template template, DataType type, Object... parameters) { return new SQLField(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)); } diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index 1816706f4a..b449a4d363 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -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 fetch(Template template, Object... parameters) { + @SuppressWarnings("deprecation") + Result 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 fetchLazy(Template template, Object... parameters) { + @SuppressWarnings("deprecation") + Cursor 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> fetchMany(Template template, Object... parameters) { + @SuppressWarnings("deprecation") + List> 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 resultQuery(Template template, Object... parameters) { + @SuppressWarnings("deprecation") + ResultQuery resultQuery(org.jooq.Template template, Object... parameters) { return new SQLResultQuery(configuration, queryPart(template, parameters)); } diff --git a/jOOQ/src/main/java/org/jooq/impl/SQLTemplate.java b/jOOQ/src/main/java/org/jooq/impl/SQLTemplate.java index 71c9e4cf48..a24616c2f2 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SQLTemplate.java +++ b/jOOQ/src/main/java/org/jooq/impl/SQLTemplate.java @@ -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;