[#2399] Remove support for the USE statement
This commit is contained in:
parent
8d9a40ad19
commit
3f1e2af10a
@ -40,14 +40,11 @@ import static java.util.Collections.nCopies;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.jooq.impl.DSL.count;
|
||||
import static org.jooq.impl.DSL.sum;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Record1;
|
||||
@ -94,39 +91,6 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUse() throws Exception {
|
||||
switch (dialect()) {
|
||||
case ASE:
|
||||
case CUBRID:
|
||||
case FIREBIRD:
|
||||
case SQLITE:
|
||||
case SQLSERVER:
|
||||
log.info("SKIPPING", "USE test");
|
||||
return;
|
||||
}
|
||||
|
||||
DSLContext factory = create();
|
||||
factory.use(schema().getName());
|
||||
|
||||
Result<?> result =
|
||||
factory.select(TBook_AUTHOR_ID(), count())
|
||||
.from(TBook())
|
||||
.join(TAuthor())
|
||||
.on(TBook_AUTHOR_ID().equal(TAuthor_ID()))
|
||||
.where(TAuthor_YEAR_OF_BIRTH().greaterOrEqual(TAuthor_ID()))
|
||||
.groupBy(TBook_AUTHOR_ID())
|
||||
.having(count().greaterOrEqual(1))
|
||||
.orderBy(TBook_AUTHOR_ID().desc())
|
||||
.fetch();
|
||||
|
||||
assertEquals(Arrays.asList(2, 1), result.getValues(TBook_AUTHOR_ID()));
|
||||
assertEquals(Arrays.asList(2, 2), result.getValues(count()));
|
||||
|
||||
String sql = factory.select(TBook_AUTHOR_ID()).from(TAuthor()).getSQL();
|
||||
assertFalse(sql.toLowerCase().contains(TAuthor().getSchema().getName().toLowerCase()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableMapping() throws Exception {
|
||||
Settings settings = new Settings()
|
||||
|
||||
@ -904,19 +904,11 @@ public abstract class jOOQAbstractTest<
|
||||
return "";
|
||||
}
|
||||
|
||||
// IMPORTANT! Make this the first test, to prevent side-effects
|
||||
@Test
|
||||
public void testInsertIdentity() throws Exception {
|
||||
new InsertUpdateTests(this).testInsertIdentity();
|
||||
}
|
||||
|
||||
|
||||
// IMPORTANT! Make this the an early test, to check for attaching side-effects
|
||||
@Test
|
||||
public void testUse() throws Exception {
|
||||
new SchemaAndMappingTests(this).testUse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableMapping() throws Exception {
|
||||
new SchemaAndMappingTests(this).testTableMapping();
|
||||
|
||||
@ -4285,72 +4285,6 @@ public interface DSLContext {
|
||||
@Support({ CUBRID, DB2, FIREBIRD, H2, INGRES, ORACLE, POSTGRES, SYBASE })
|
||||
<T extends Number> T currval(Sequence<T> sequence) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Use a schema as the default schema of the underlying connection.
|
||||
* <p>
|
||||
* This has two effects.
|
||||
* <ol>
|
||||
* <li>The <code>USE [schema]</code> statement is executed on those RDBMS
|
||||
* that support this</li>
|
||||
* <li>The supplied {@link Schema} is used as the default schema resulting
|
||||
* in omitting that schema in rendered SQL.</li>
|
||||
* </ol>
|
||||
* <p>
|
||||
* The <code>USE [schema]</code> statement translates to the various
|
||||
* dialects as follows:
|
||||
* <table>
|
||||
* <tr>
|
||||
* <th>Dialect</th>
|
||||
* <th>Command</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>DB2</td>
|
||||
* <td><code>SET SCHEMA [schema]</code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Derby:</td>
|
||||
* <td><code>SET SCHEMA [schema]</code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>H2:</td>
|
||||
* <td><code>SET SCHEMA [schema]</code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>HSQLDB:</td>
|
||||
* <td><code>SET SCHEMA [schema]</code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>MySQL:</td>
|
||||
* <td><code>USE [schema]</code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Oracle:</td>
|
||||
* <td><code>ALTER SESSION SET CURRENT_SCHEMA = [schema]</code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Postgres:</td>
|
||||
* <td><code>SET SEARCH_PATH = [schema]</code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Sybase:</td>
|
||||
* <td><code>USE [schema]</code></td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, SYBASE, ORACLE, POSTGRES, SYBASE })
|
||||
int use(Schema schema) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Use a schema as the default schema of the underlying connection.
|
||||
*
|
||||
* @see #use(Schema)
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, SYBASE, ORACLE, POSTGRES, SYBASE })
|
||||
int use(String schema) throws DataAccessException;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX Global Record factory
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -50,7 +50,6 @@ import static org.jooq.SQLDialect.POSTGRES;
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
import static org.jooq.SQLDialect.SQLSERVER;
|
||||
import static org.jooq.SQLDialect.SYBASE;
|
||||
import static org.jooq.conf.SettingsTools.getRenderMapping;
|
||||
import static org.jooq.impl.DSL.field;
|
||||
import static org.jooq.impl.DSL.fieldByName;
|
||||
import static org.jooq.impl.DSL.trueCondition;
|
||||
@ -1494,62 +1493,6 @@ class DSLContextImpl implements DSLContext, Serializable {
|
||||
return select(currval).fetchOne(currval);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, SYBASE, ORACLE, POSTGRES, SYBASE })
|
||||
public final int use(Schema schema) throws DataAccessException {
|
||||
int result = 0;
|
||||
|
||||
try {
|
||||
String schemaName = render(schema);
|
||||
|
||||
switch (configuration.dialect()) {
|
||||
case DB2:
|
||||
case DERBY:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
result = query("set schema " + schemaName).execute();
|
||||
break;
|
||||
|
||||
case ASE:
|
||||
case MYSQL:
|
||||
case SYBASE:
|
||||
result = query("use " + schemaName).execute();
|
||||
break;
|
||||
|
||||
case ORACLE:
|
||||
result = query("alter session set current_schema = " + schemaName).execute();
|
||||
break;
|
||||
|
||||
case POSTGRES:
|
||||
result = query("set search_path = " + schemaName).execute();
|
||||
break;
|
||||
|
||||
// SQL Server do not support such a syntax for selecting
|
||||
// schemata, only for selecting databases
|
||||
case SQLSERVER:
|
||||
break;
|
||||
|
||||
// CUBRID and SQLite don't have any schemata
|
||||
case CUBRID:
|
||||
case SQLITE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
getRenderMapping(configuration.settings()).setDefaultSchema(schema.getName());
|
||||
configuration.schemaMapping().use(schema);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, SYBASE, ORACLE, POSTGRES, SYBASE })
|
||||
public final int use(String schema) throws DataAccessException {
|
||||
return use(new SchemaImpl(schema));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX Global Record factory
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user