From dca8c44162a79d27b7ba5cd3d9314ef2505944e5 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sun, 20 May 2012 23:19:59 +0200 Subject: [PATCH] [#1432] Removed redundant SQLClause, merged functionality into SQLField --- jOOQ/src/main/java/org/jooq/impl/Factory.java | 6 +- .../src/main/java/org/jooq/impl/Position.java | 3 +- .../main/java/org/jooq/impl/SQLClause.java | 114 ------------------ 3 files changed, 5 insertions(+), 118 deletions(-) delete mode 100644 jOOQ/src/main/java/org/jooq/impl/SQLClause.java diff --git a/jOOQ/src/main/java/org/jooq/impl/Factory.java b/jOOQ/src/main/java/org/jooq/impl/Factory.java index ea41c8709e..aae28c5120 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Factory.java +++ b/jOOQ/src/main/java/org/jooq/impl/Factory.java @@ -813,7 +813,7 @@ public class Factory implements FactoryOperations { * @return A field wrapping the plain SQL */ public static Field field(String sql, QueryPart... parts) { - return new SQLClause(sql, SQLDataType.OTHER, parts); + return new SQLField(sql, SQLDataType.OTHER, parts); } /** @@ -847,7 +847,7 @@ public class Factory implements FactoryOperations { * @return A field wrapping the plain SQL */ public static Field field(String sql, Class type, QueryPart... parts) { - return new SQLClause(sql, getDataType(type), parts); + return new SQLField(sql, getDataType(type), parts); } /** @@ -881,7 +881,7 @@ public class Factory implements FactoryOperations { * @return A field wrapping the plain SQL */ public static Field field(String sql, DataType type, QueryPart... parts) { - return new SQLClause(sql, type, parts); + return new SQLField(sql, type, parts); } /** diff --git a/jOOQ/src/main/java/org/jooq/impl/Position.java b/jOOQ/src/main/java/org/jooq/impl/Position.java index becb48b97a..201ed2c736 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Position.java +++ b/jOOQ/src/main/java/org/jooq/impl/Position.java @@ -36,6 +36,7 @@ package org.jooq.impl; +import static org.jooq.impl.Factory.field; import static org.jooq.impl.Factory.function; import org.jooq.Configuration; @@ -77,7 +78,7 @@ class Position extends AbstractFunction { return function("charindex", SQLDataType.INTEGER, search, in); default: - return new SQLClause("{position}({0} {in} {1})", SQLDataType.INTEGER, search, in); + return field("{position}({0} {in} {1})", SQLDataType.INTEGER, search, in); } } } diff --git a/jOOQ/src/main/java/org/jooq/impl/SQLClause.java b/jOOQ/src/main/java/org/jooq/impl/SQLClause.java deleted file mode 100644 index ead788058f..0000000000 --- a/jOOQ/src/main/java/org/jooq/impl/SQLClause.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * 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 java.util.List; - -import org.jooq.Attachable; -import org.jooq.BindContext; -import org.jooq.DataType; -import org.jooq.QueryPart; -import org.jooq.RenderContext; -import org.jooq.exception.DataAccessException; -import org.jooq.tools.StringUtils; - -/** - * @author Lukas Eder - */ -class SQLClause extends AbstractField { - - /** - * Generated UID - */ - private static final long serialVersionUID = 3132876322089761785L; - - private final String sql; - private final QueryPart[] parts; - - SQLClause(String sql, DataType type, QueryPart... parts) { - super(sql, type); - - this.sql = sql; - this.parts = parts; - } - - // ------------------------------------------------------------------------ - // Field API - // ------------------------------------------------------------------------ - - @Override - public final List getAttachables() { - return getAttachables(parts); - } - - @Override - public final void toSQL(RenderContext context) { - // Tokenise {keywords} and placeholders {1} {2}. - // Avoid tokenising JDBC escape syntax, e.g. {fn xx()} - String[] sqlParts = StringUtils.split("\\{(?!(fn|d|t|ts)\\b)[\\w\\s]+\\}", sql); - - int i = 0; - for (String sqlPart : sqlParts) { - if (sqlPart.matches("\\{\\d+\\}")) { - if (i == parts.length) { - throw new DataAccessException("The number of placeholders must match the number of query parts : " + sql); - } - - context.sql(parts[i++]); - } - else if (sqlPart.matches("\\{[\\w\\s]+\\}")) { - context.keyword(sqlPart.substring(1, sqlPart.length() - 1)); - } - else { - context.sql(sqlPart); - } - } - - if (i != parts.length) { - throw new DataAccessException("The number of placeholders must match the number of query parts : " + sql); - } - } - - @Override - public final void bind(BindContext context) { - context.bind(parts); - } - - @Override - public final boolean isNullLiteral() { - return "null".equalsIgnoreCase(sql); - } -}