jooq/jOOQ/src/main/java/org/jooq/impl/FunctionTable.java
Lukas Eder c2473cd0ec [#2665] Implement SPI for RenderContext and BindContext listening to
allow for custom SQL transformation

 * Added clauses for FIELD_REFERENCE, TABLE_REFERENCE, etc.
 * Implemented UPDATE clauses
 * Changed QueryPartInternal to allow for specifying a Clause[] array
per QueryPart
 * Added a mechanism to omit clause event emission
2013-08-08 16:36:53 +02:00

117 lines
3.9 KiB
Java

/**
* 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.impl;
import static org.jooq.Clause.DUMMY;
import org.jooq.BindContext;
import org.jooq.Clause;
import org.jooq.Field;
import org.jooq.Record;
import org.jooq.RenderContext;
import org.jooq.Table;
import org.jooq.exception.SQLDialectNotSupportedException;
/**
* @author Lukas Eder
*/
class FunctionTable<R extends Record> extends AbstractTable<R> {
/**
* Generated UID
*/
private static final long serialVersionUID = 2380426377794577041L;
private final Field<?> function;
FunctionTable(Field<?> function) {
super("function_table");
this.function = function;
}
@SuppressWarnings("unchecked")
@Override
public final Class<? extends R> getRecordType() {
return (Class<? extends R>) RecordImpl.class;
}
@Override
public final Table<R> as(String as) {
return new TableAlias<R>(new FunctionTable<R>(function), as);
}
@Override
public final Table<R> as(String as, String... fieldAliases) {
return new TableAlias<R>(new FunctionTable<R>(function), as, fieldAliases);
}
@Override
public final void toSQL(RenderContext context) {
switch (context.configuration().dialect()) {
case HSQLDB: {
context.keyword("table(").visit(function).sql(")");
break;
}
default:
throw new SQLDialectNotSupportedException("FUNCTION TABLE is not supported for " + context.configuration().dialect());
}
}
@Override
public final void bind(BindContext context) {
switch (context.configuration().dialect()) {
case HSQLDB:
context.visit(function);
break;
default:
throw new SQLDialectNotSupportedException("FUNCTION TABLE is not supported for " + context.configuration().dialect());
}
}
@Override
public final Clause[] clauses() {
return new Clause[] { DUMMY };
}
@Override
final Fields<R> fields0() {
return new Fields<R>();
}
}