diff --git a/jOOQ/src/main/java/org/jooq/SQLDialect.java b/jOOQ/src/main/java/org/jooq/SQLDialect.java
index 7c05b771f6..d99d8f443d 100644
--- a/jOOQ/src/main/java/org/jooq/SQLDialect.java
+++ b/jOOQ/src/main/java/org/jooq/SQLDialect.java
@@ -57,6 +57,7 @@ import org.jooq.util.sybase.SybaseFactory;
* @author Lukas Eder
*/
public enum SQLDialect {
+
/**
* The standard SQL dialect.
*
@@ -139,10 +140,31 @@ public enum SQLDialect {
this.factory = factory;
}
+ /**
+ * The name of this dialect as it appears in related class names.
+ */
public final String getName() {
return name;
}
+ /**
+ * The name of this dialect as it appears in related package names.
+ */
+ public final String getNameLC() {
+ return name.toLowerCase();
+ }
+
+ /**
+ * The name of this dialect as it appears in related enum values
+ */
+ public final String getNameUC() {
+ return name.toUpperCase();
+ }
+
+ /**
+ * A {@link Factory} class whose instances are pre-configured with this
+ * dialect.
+ */
public final Class extends Factory> getFactory() {
return factory;
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java b/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java
new file mode 100644
index 0000000000..1c4bbdec62
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java
@@ -0,0 +1,552 @@
+/**
+ * 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.lang.reflect.Constructor;
+import java.math.BigInteger;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.jooq.Attachable;
+import org.jooq.Batch;
+import org.jooq.BatchBindStep;
+import org.jooq.Condition;
+import org.jooq.Cursor;
+import org.jooq.DeleteQuery;
+import org.jooq.DeleteWhereStep;
+import org.jooq.FactoryOperations;
+import org.jooq.Field;
+import org.jooq.Insert;
+import org.jooq.InsertQuery;
+import org.jooq.InsertSetStep;
+import org.jooq.InsertValuesStep;
+import org.jooq.LoaderOptionsStep;
+import org.jooq.MergeUsingStep;
+import org.jooq.Query;
+import org.jooq.QueryPart;
+import org.jooq.Record;
+import org.jooq.Result;
+import org.jooq.ResultQuery;
+import org.jooq.SQLDialect;
+import org.jooq.Schema;
+import org.jooq.Select;
+import org.jooq.SelectQuery;
+import org.jooq.SelectSelectStep;
+import org.jooq.Sequence;
+import org.jooq.SimpleSelectQuery;
+import org.jooq.SimpleSelectWhereStep;
+import org.jooq.Table;
+import org.jooq.TableLike;
+import org.jooq.TableRecord;
+import org.jooq.Truncate;
+import org.jooq.UDT;
+import org.jooq.UDTRecord;
+import org.jooq.UpdateQuery;
+import org.jooq.UpdateSetStep;
+import org.jooq.conf.Settings;
+import org.jooq.exception.DataAccessException;
+import org.jooq.tools.JooqLogger;
+
+/**
+ * Thread safe proxy for {@link Factory}.
+ *
+ * The FactoryProxy operates as a thread-safe proxy for jOOQ's
+ * {@link Factory} objects. Instead of wrapping JDBC {@link Connection} objects,
+ * the FactoryProxy wraps a transaction-aware {@link DataSource}
+ * and creates a new Factory with a new Connection
+ * every time you use any of the operations from {@link FactoryOperations}
+ *
+ * Refer to the jOOQ manual to see possible operation modes for jOOQ with Spring
+ *
+ * @author Sergey Epik
+ * @author Lukas Eder
+ */
+public final class FactoryProxy implements FactoryOperations {
+
+ /**
+ * Generated UID
+ */
+ private static final long serialVersionUID = -8475057043526340066L;
+
+ private static JooqLogger log = JooqLogger.getLogger(FactoryProxy.class);
+ private transient DataSource dataSource;
+ private SQLDialect dialect;
+
+ @SuppressWarnings("deprecation")
+ private org.jooq.SchemaMapping schemaMapping;
+ private Settings settings;
+
+ // -------------------------------------------------------------------------
+ // Injected configuration
+ // -------------------------------------------------------------------------
+
+ public final void setDialect(SQLDialect dialect) {
+ this.dialect = dialect;
+ }
+
+ @SuppressWarnings("deprecation")
+ public final void setSchemaMapping(org.jooq.SchemaMapping schemaMapping) {
+ this.schemaMapping = schemaMapping;
+
+ log.warn("DEPRECATION", "org.jooq.SchemaMapping is deprecated as of jOOQ 2.0.5. Consider using jOOQ's runtime configuration org.jooq.conf.Settings instead");
+ }
+
+ public final void setSettings(Settings settings) {
+ this.settings = settings;
+ }
+
+ public final void setDataSource(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public final DataSource getDataSource() {
+ return this.dataSource;
+ }
+
+ // -------------------------------------------------------------------------
+ // Configuration API
+ // -------------------------------------------------------------------------
+
+ @Override
+ public final SQLDialect getDialect() {
+ return dialect;
+ }
+
+ @Override
+ @Deprecated
+ public final org.jooq.SchemaMapping getSchemaMapping() {
+ return schemaMapping;
+ }
+
+ @Override
+ public final Settings getSettings() {
+ return settings;
+ }
+
+ @Override
+ public final Connection getConnection() {
+ return getDelegate().getConnection();
+ }
+
+ @Override
+ public final void setConnection(Connection connection) {
+ getDelegate().setConnection(connection);
+ }
+
+ @Override
+ public final Map getData() {
+ return getDelegate().getData();
+ }
+
+ @Override
+ public final Object getData(String key) {
+ return getDelegate().getData(key);
+ }
+
+ @Override
+ public final Object setData(String key, Object value) {
+ return getDelegate().setData(key, value);
+ }
+
+ // -------------------------------------------------------------------------
+ // XXX FactoryOperations API
+ // -------------------------------------------------------------------------
+
+ @Override
+ public final > LoaderOptionsStep loadInto(Table table) {
+ return getDelegate().loadInto(table);
+ }
+
+ @Override
+ public final String render(QueryPart part) {
+ return getDelegate().render(part);
+ }
+
+ @Override
+ public final String renderNamedParams(QueryPart part) {
+ return getDelegate().renderNamedParams(part);
+ }
+
+ @Override
+ public final String renderInlined(QueryPart part) {
+ return getDelegate().renderInlined(part);
+ }
+
+ @Override
+ public final void attach(Attachable... attachables) {
+ getDelegate().attach(attachables);
+ }
+
+ @Override
+ public final void attach(Collection attachables) {
+ getDelegate().attach(attachables);
+ }
+
+ @Override
+ public final Query query(String sql) {
+ return getDelegate().query(sql);
+ }
+
+ @Override
+ public final Query query(String sql, Object... bindings) {
+ return getDelegate().query(sql, bindings);
+ }
+
+ @Override
+ public final SimpleSelectWhereStep selectFrom(Table table) {
+ return getDelegate().selectFrom(table);
+ }
+
+ @Override
+ public final SelectSelectStep select(Field>... fields) {
+ return getDelegate().select(fields);
+ }
+
+ @Override
+ public final SelectSelectStep selectZero() {
+ return getDelegate().selectZero();
+ }
+
+ @Override
+ public final SelectSelectStep selectOne() {
+ return getDelegate().selectOne();
+ }
+
+ @Override
+ public final SelectSelectStep selectCount() {
+ return getDelegate().selectCount();
+ }
+
+ @Override
+ public final SelectSelectStep selectDistinct(Field>... fields) {
+ return getDelegate().selectDistinct(fields);
+ }
+
+ @Override
+ public final SelectSelectStep select(Collection extends Field>> fields) {
+ return getDelegate().select(fields);
+ }
+
+ @Override
+ public final SelectSelectStep selectDistinct(Collection extends Field>> fields) {
+ return getDelegate().selectDistinct(fields);
+ }
+
+ @Override
+ public final SelectQuery selectQuery() {
+ return getDelegate().selectQuery();
+ }
+
+ @Override
+ public final SimpleSelectQuery selectQuery(TableLike table) {
+ return getDelegate().selectQuery(table);
+ }
+
+ @Override
+ public final InsertQuery insertQuery(Table into) {
+ return getDelegate().insertQuery(into);
+ }
+
+ @Override
+ public final InsertSetStep insertInto(Table into) {
+ return getDelegate().insertInto(into);
+ }
+
+ @Override
+ public final InsertValuesStep insertInto(Table into, Field>... fields) {
+ return getDelegate().insertInto(into, fields);
+ }
+
+ @Override
+ public final InsertValuesStep insertInto(Table into, Collection extends Field>> fields) {
+ return getDelegate().insertInto(into, fields);
+ }
+
+ @Override
+ @Deprecated
+ public final Insert insertInto(Table into, Select> select) {
+ return getDelegate().insertInto(into, select);
+ }
+
+ @Override
+ public final UpdateQuery updateQuery(Table table) {
+ return getDelegate().updateQuery(table);
+ }
+
+ @Override
+ public final UpdateSetStep update(Table table) {
+ return getDelegate().update(table);
+ }
+
+ @Override
+ public final MergeUsingStep mergeInto(Table table) {
+ return getDelegate().mergeInto(table);
+ }
+
+ @Override
+ public final DeleteQuery deleteQuery(Table table) {
+ return getDelegate().deleteQuery(table);
+ }
+
+ @Override
+ public final DeleteWhereStep delete(Table table) {
+ return getDelegate().delete(table);
+ }
+
+ @Override
+ public final Batch batch(Query... queries) {
+ return getDelegate().batch(queries);
+ }
+
+ @Override
+ public final Batch batch(Collection extends Query> queries) {
+ return getDelegate().batch(queries);
+ }
+
+ @Override
+ public final BatchBindStep batch(Query query) {
+ return getDelegate().batch(query);
+ }
+
+ @Override
+ public final > Truncate truncate(Table table) {
+ return getDelegate().truncate(table);
+ }
+
+ @Override
+ public final > R newRecord(UDT type) {
+ return getDelegate().newRecord(type);
+ }
+
+ @Override
+ public final > R newRecord(Table table) {
+ return getDelegate().newRecord(table);
+ }
+
+ @Override
+ public final > R newRecord(Table table, Object source) {
+ return getDelegate().newRecord(table, source);
+ }
+
+ @Override
+ public final Result fetch(ResultSet rs) {
+ return getDelegate().fetch(rs);
+ }
+
+ @Override
+ public final Result fetch(String sql) {
+ return getDelegate().fetch(sql);
+ }
+
+ @Override
+ public final Result fetch(String sql, Object... bindings) {
+ return getDelegate().fetch(sql, bindings);
+ }
+
+ @Override
+ public final Cursor fetchLazy(String sql) throws DataAccessException {
+ return getDelegate().fetchLazy(sql);
+ }
+
+ @Override
+ public final Cursor fetchLazy(String sql, Object... bindings) throws DataAccessException {
+ return getDelegate().fetchLazy(sql, bindings);
+ }
+
+ @Override
+ public final List> fetchMany(String sql) {
+ return getDelegate().fetchMany(sql);
+ }
+
+ @Override
+ public final List> fetchMany(String sql, Object... bindings) {
+ return getDelegate().fetchMany(sql, bindings);
+ }
+
+ @Override
+ public final Record fetchOne(String sql) {
+ return getDelegate().fetchOne(sql);
+ }
+
+ @Override
+ public final Record fetchOne(String sql, Object... bindings) {
+ return getDelegate().fetchOne(sql, bindings);
+ }
+
+ @Override
+ public final int execute(String sql) throws DataAccessException {
+ return getDelegate().execute(sql);
+ }
+
+ @Override
+ public final int execute(String sql, Object... bindings) throws DataAccessException {
+ return getDelegate().execute(sql, bindings);
+ }
+
+ @Override
+ public final ResultQuery resultQuery(String sql) throws DataAccessException {
+ return getDelegate().resultQuery(sql);
+ }
+
+ @Override
+ public final ResultQuery resultQuery(String sql, Object... bindings) throws DataAccessException {
+ return getDelegate().resultQuery(sql, bindings);
+ }
+
+ @Override
+ public final BigInteger lastID() {
+ return getDelegate().lastID();
+ }
+
+ @Override
+ public final T nextval(Sequence sequence) {
+ return getDelegate().nextval(sequence);
+ }
+
+ @Override
+ public final T currval(Sequence sequence) {
+ return getDelegate().currval(sequence);
+ }
+
+ @Override
+ public final int use(Schema schema) {
+ return getDelegate().use(schema);
+ }
+
+ @Override
+ public final int use(String schema) {
+ return getDelegate().use(schema);
+ }
+
+ @Override
+ public final Result fetch(Table table) {
+ return getDelegate().fetch(table);
+ }
+
+ @Override
+ public final Result fetch(Table table, Condition condition) {
+ return getDelegate().fetch(table, condition);
+ }
+
+ @Override
+ public final R fetchOne(Table table) {
+ return getDelegate().fetchOne(table);
+ }
+
+ @Override
+ public final R fetchOne(Table table, Condition condition) {
+ return getDelegate().fetchOne(table, condition);
+ }
+
+ @Override
+ public final R fetchAny(Table table) {
+ return getDelegate().fetchAny(table);
+ }
+
+ @Override
+ public final > int executeInsert(Table table, R record) {
+ return getDelegate().executeInsert(table, record);
+ }
+
+ @Override
+ public final > int executeUpdate(Table table, R record) {
+ return getDelegate().executeUpdate(table, record);
+ }
+
+ @Override
+ public final , T> int executeUpdate(Table table, R record, Condition condition) {
+ return getDelegate().executeUpdate(table, record, condition);
+ }
+
+ @Override
+ public final > int executeUpdateOne(Table table, R record) {
+ return getDelegate().executeUpdateOne(table, record);
+ }
+
+ @Override
+ public final , T> int executeUpdateOne(Table table, R record, Condition condition) {
+ return getDelegate().executeUpdateOne(table, record, condition);
+ }
+
+ @Override
+ public final > int executeDelete(Table table) {
+ return getDelegate().executeDelete(table);
+ }
+
+ @Override
+ public final , T> int executeDelete(Table table, Condition condition) {
+ return getDelegate().executeDelete(table, condition);
+ }
+
+ @Override
+ public final > int executeDeleteOne(Table table) {
+ return getDelegate().executeDeleteOne(table);
+ }
+
+ @Override
+ public final , T> int executeDeleteOne(Table table, Condition condition) {
+ return getDelegate().executeDeleteOne(table, condition);
+ }
+
+ @SuppressWarnings("deprecation")
+ private Factory getDelegate() {
+ if (dataSource == null || dialect == null) {
+ throw new DataAccessException("Both dataSource and dialect properties should be set");
+ }
+ try {
+ Class extends Factory> clazz = getDialect().getFactory();
+ Connection con = getDataSource().getConnection();
+
+ Constructor extends Factory> constructor;
+ if (schemaMapping == null) {
+ constructor = clazz.getConstructor(Connection.class);
+ return constructor.newInstance(con);
+ }
+ else {
+ constructor = clazz.getConstructor(Connection.class, org.jooq.SchemaMapping.class);
+ return constructor.newInstance(con, schemaMapping);
+ }
+ }
+ catch (Exception e) {
+ throw new DataAccessException("Failed to create jOOQ Factory", e);
+ }
+ }
+}