[#1917] Add support for CUBRID 9.0's new features - Added and documented
support for CUBRID MERGE statement (Oracle syntax extensions)
This commit is contained in:
parent
4233980896
commit
27a3073b10
@ -41,10 +41,8 @@ import static java.util.Collections.emptyList;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.jooq.impl.Factory.currentUser;
|
||||
import static org.jooq.impl.Factory.falseCondition;
|
||||
import static org.jooq.impl.Factory.sum;
|
||||
import static org.jooq.impl.Factory.table;
|
||||
import static org.jooq.impl.Factory.trueCondition;
|
||||
import static org.jooq.impl.Factory.val;
|
||||
import static org.jooq.test.oracle.generatedclasses.multi_schema.Tables.T_BOOK_SALE;
|
||||
import static org.jooq.test.oracle.generatedclasses.test.Routines.f691cursorIn;
|
||||
@ -1115,83 +1113,6 @@ public class OracleTest extends jOOQAbstractTest<
|
||||
assertEquals(BigInteger.valueOf(1), ora().nextval(Sequences.S_961_BIG_INTEGER));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOracleMergeStatementExtensions() throws Exception {
|
||||
reset = false;
|
||||
TAuthorRecord author;
|
||||
|
||||
// Test updating with a positive condition
|
||||
// ---------------------------------------
|
||||
assertEquals(1,
|
||||
ora().mergeInto(T_AUTHOR)
|
||||
.usingDual()
|
||||
.on(T_AUTHOR.ID.equal(1))
|
||||
.whenMatchedThenUpdate()
|
||||
.set(T_AUTHOR.LAST_NAME, "Frisch")
|
||||
.where(T_AUTHOR.ID.equal(1))
|
||||
.execute());
|
||||
|
||||
author = create().fetchOne(T_AUTHOR, T_AUTHOR.ID.equal(1));
|
||||
assertEquals(2, create().selectCount().from(T_AUTHOR).fetchOne(0));
|
||||
assertEquals(1, (int) author.getId());
|
||||
assertEquals(AUTHOR_FIRST_NAMES.get(0), author.getFirstName());
|
||||
assertEquals("Frisch", author.getLastName());
|
||||
|
||||
// Test updating with a negative condition
|
||||
// ---------------------------------------
|
||||
assertEquals(0,
|
||||
ora().mergeInto(T_AUTHOR)
|
||||
.usingDual()
|
||||
.on(T_AUTHOR.ID.equal(1))
|
||||
.whenMatchedThenUpdate()
|
||||
.set(T_AUTHOR.LAST_NAME, "Frisch")
|
||||
.where(T_AUTHOR.ID.equal(3))
|
||||
.execute());
|
||||
|
||||
author = create().fetchOne(T_AUTHOR, T_AUTHOR.ID.equal(1));
|
||||
assertEquals(2, create().selectCount().from(T_AUTHOR).fetchOne(0));
|
||||
assertEquals(1, (int) author.getId());
|
||||
assertEquals(AUTHOR_FIRST_NAMES.get(0), author.getFirstName());
|
||||
assertEquals("Frisch", author.getLastName());
|
||||
|
||||
// Test deleting
|
||||
// -------------
|
||||
// ON DELETE CASCADE doesn't work with MERGE...?
|
||||
ora().delete(T_BOOK).execute();
|
||||
|
||||
assertEquals(1,
|
||||
ora().mergeInto(T_AUTHOR)
|
||||
.usingDual()
|
||||
.on(trueCondition())
|
||||
.whenMatchedThenUpdate()
|
||||
.set(T_AUTHOR.LAST_NAME, "Frisch")
|
||||
.where(T_AUTHOR.ID.equal(2))
|
||||
.deleteWhere(T_AUTHOR.ID.equal(2))
|
||||
.execute());
|
||||
|
||||
author = create().fetchOne(T_AUTHOR, T_AUTHOR.ID.equal(1));
|
||||
assertEquals(1, create().selectCount().from(T_AUTHOR).fetchOne(0));
|
||||
assertEquals(1, (int) author.getId());
|
||||
assertEquals(AUTHOR_FIRST_NAMES.get(0), author.getFirstName());
|
||||
assertEquals("Frisch", author.getLastName());
|
||||
|
||||
// Test inserting
|
||||
// --------------
|
||||
assertEquals(0,
|
||||
ora().mergeInto(T_AUTHOR)
|
||||
.usingDual()
|
||||
.on(trueCondition())
|
||||
.whenNotMatchedThenInsert(
|
||||
T_AUTHOR.ID,
|
||||
T_AUTHOR.FIRST_NAME,
|
||||
T_AUTHOR.LAST_NAME)
|
||||
.values(3, "Yvette", "Z'Graggen")
|
||||
.where(falseCondition())
|
||||
.execute());
|
||||
|
||||
// No tests on results
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOracleDateAsTimestamp() throws Exception {
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis() / 1000 * 1000);
|
||||
|
||||
@ -55,11 +55,13 @@ import static org.jooq.SQLDialect.SYBASE;
|
||||
import static org.jooq.impl.Factory.cast;
|
||||
import static org.jooq.impl.Factory.castNull;
|
||||
import static org.jooq.impl.Factory.count;
|
||||
import static org.jooq.impl.Factory.falseCondition;
|
||||
import static org.jooq.impl.Factory.inline;
|
||||
import static org.jooq.impl.Factory.max;
|
||||
import static org.jooq.impl.Factory.row;
|
||||
import static org.jooq.impl.Factory.select;
|
||||
import static org.jooq.impl.Factory.selectOne;
|
||||
import static org.jooq.impl.Factory.trueCondition;
|
||||
import static org.jooq.impl.Factory.val;
|
||||
import static org.jooq.impl.Factory.vals;
|
||||
|
||||
@ -874,7 +876,101 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testH2Merge() throws Exception {
|
||||
public void testMergeWithOracleSyntaxExtension() throws Exception {
|
||||
switch (getDialect()) {
|
||||
case ASE:
|
||||
case DB2:
|
||||
case DERBY:
|
||||
case FIREBIRD:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
case INGRES:
|
||||
case MYSQL:
|
||||
case POSTGRES:
|
||||
case SQLITE:
|
||||
case SQLSERVER:
|
||||
case SYBASE:
|
||||
log.info("SKIPPING", "Oracle-specific MERGE syntax test");
|
||||
return;
|
||||
}
|
||||
|
||||
jOOQAbstractTest.reset = false;
|
||||
A author;
|
||||
|
||||
// Test updating with a positive condition
|
||||
// ---------------------------------------
|
||||
assertEquals(1,
|
||||
create().mergeInto(TAuthor())
|
||||
.usingDual()
|
||||
.on(TAuthor_ID().equal(1))
|
||||
.whenMatchedThenUpdate()
|
||||
.set(TAuthor_LAST_NAME(), "Frisch")
|
||||
.where(TAuthor_ID().equal(1))
|
||||
.execute());
|
||||
|
||||
author = create().fetchOne(TAuthor(), TAuthor_ID().equal(1));
|
||||
assertEquals(2, create().selectCount().from(TAuthor()).fetchOne(0));
|
||||
assertEquals(1, (int) author.getValue(TAuthor_ID()));
|
||||
assertEquals(AUTHOR_FIRST_NAMES.get(0), author.getValue(TAuthor_FIRST_NAME()));
|
||||
assertEquals("Frisch", author.getValue(TAuthor_LAST_NAME()));
|
||||
|
||||
// Test updating with a negative condition
|
||||
// ---------------------------------------
|
||||
assertEquals(0,
|
||||
create().mergeInto(TAuthor())
|
||||
.usingDual()
|
||||
.on(TAuthor_ID().equal(1))
|
||||
.whenMatchedThenUpdate()
|
||||
.set(TAuthor_LAST_NAME(), "Frisch")
|
||||
.where(TAuthor_ID().equal(3))
|
||||
.execute());
|
||||
|
||||
author = create().fetchOne(TAuthor(), TAuthor_ID().equal(1));
|
||||
assertEquals(2, create().selectCount().from(TAuthor()).fetchOne(0));
|
||||
assertEquals(1, (int) author.getValue(TAuthor_ID()));
|
||||
assertEquals(AUTHOR_FIRST_NAMES.get(0), author.getValue(TAuthor_FIRST_NAME()));
|
||||
assertEquals("Frisch", author.getValue(TAuthor_LAST_NAME()));
|
||||
|
||||
// Test deleting
|
||||
// -------------
|
||||
// ON DELETE CASCADE doesn't work with MERGE...?
|
||||
create().delete(TBook()).execute();
|
||||
|
||||
assertEquals(1,
|
||||
create().mergeInto(TAuthor())
|
||||
.usingDual()
|
||||
.on(trueCondition())
|
||||
.whenMatchedThenUpdate()
|
||||
.set(TAuthor_LAST_NAME(), "Frisch")
|
||||
.where(TAuthor_ID().equal(2))
|
||||
.deleteWhere(TAuthor_ID().equal(2))
|
||||
.execute());
|
||||
|
||||
author = create().fetchOne(TAuthor(), TAuthor_ID().equal(1));
|
||||
assertEquals(1, create().selectCount().from(TAuthor()).fetchOne(0));
|
||||
assertEquals(1, (int) author.getValue(TAuthor_ID()));
|
||||
assertEquals(AUTHOR_FIRST_NAMES.get(0), author.getValue(TAuthor_FIRST_NAME()));
|
||||
assertEquals("Frisch", author.getValue(TAuthor_LAST_NAME()));
|
||||
|
||||
// Test inserting
|
||||
// --------------
|
||||
assertEquals(0,
|
||||
create().mergeInto(TAuthor())
|
||||
.usingDual()
|
||||
.on(trueCondition())
|
||||
.whenNotMatchedThenInsert(
|
||||
TAuthor_ID(),
|
||||
TAuthor_FIRST_NAME(),
|
||||
TAuthor_LAST_NAME())
|
||||
.values(3, "Yvette", "Z'Graggen")
|
||||
.where(falseCondition())
|
||||
.execute());
|
||||
|
||||
// No tests on results
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMergeWithH2SyntaxExtension() throws Exception {
|
||||
switch (getDialect()) {
|
||||
case ASE:
|
||||
case DERBY:
|
||||
|
||||
@ -1288,8 +1288,13 @@ public abstract class jOOQAbstractTest<
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testH2Merge() throws Exception {
|
||||
new InsertUpdateTests(this).testH2Merge();
|
||||
public void testMergeWithH2SyntaxExtension() throws Exception {
|
||||
new InsertUpdateTests(this).testMergeWithH2SyntaxExtension();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMergeWithOracleSyntaxExtension() throws Exception {
|
||||
new InsertUpdateTests(this).testMergeWithOracleSyntaxExtension();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.ORACLE;
|
||||
|
||||
/**
|
||||
@ -63,13 +64,13 @@ public interface MergeMatchedDeleteStep<R extends Record> extends MergeNotMatche
|
||||
* <code>WHEN MATCHED THEN UPDATE</code> clause.
|
||||
* <p>
|
||||
* <b>Note:</b> This syntax is only available for the
|
||||
* {@link SQLDialect#ORACLE} database!
|
||||
* {@link SQLDialect#CUBRID} and {@link SQLDialect#ORACLE} databases!
|
||||
* <p>
|
||||
* See <a href=
|
||||
* "http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9016.htm"
|
||||
* >http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9016.
|
||||
* htm</a> for a full definition of the Oracle <code>MERGE</code> statement
|
||||
*/
|
||||
@Support(ORACLE)
|
||||
@Support({ CUBRID, ORACLE })
|
||||
MergeNotMatchedStep<R> deleteWhere(Condition condition);
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.ORACLE;
|
||||
|
||||
/**
|
||||
@ -63,13 +64,13 @@ public interface MergeMatchedWhereStep<R extends Record> extends MergeNotMatched
|
||||
* <code>WHEN MATCHED THEN UPDATE</code> clause.
|
||||
* <p>
|
||||
* <b>Note:</b> This syntax is only available for the
|
||||
* {@link SQLDialect#ORACLE} database!
|
||||
* {@link SQLDialect#CUBRID} and {@link SQLDialect#ORACLE} databases!
|
||||
* <p>
|
||||
* See <a href=
|
||||
* "http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9016.htm"
|
||||
* >http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9016.
|
||||
* htm</a> for a full definition of the Oracle <code>MERGE</code> statement
|
||||
*/
|
||||
@Support(ORACLE)
|
||||
@Support({ CUBRID, ORACLE })
|
||||
MergeMatchedDeleteStep<R> where(Condition condition);
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.ORACLE;
|
||||
|
||||
/**
|
||||
@ -63,13 +64,13 @@ public interface MergeNotMatchedWhereStep<R extends Record> extends MergeFinalSt
|
||||
* <code>WHEN NOT MATCHED THEN INSERT</code> clause.
|
||||
* <p>
|
||||
* <b>Note:</b> This syntax is only available for the
|
||||
* {@link SQLDialect#ORACLE} database!
|
||||
* {@link SQLDialect#CUBRID} and {@link SQLDialect#ORACLE} databases!
|
||||
* <p>
|
||||
* See <a href=
|
||||
* "http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9016.htm"
|
||||
* >http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9016.
|
||||
* htm</a> for a full definition of the Oracle <code>MERGE</code> statement
|
||||
*/
|
||||
@Support(ORACLE)
|
||||
@Support({ CUBRID, ORACLE })
|
||||
MergeFinalStep<R> where(Condition condition);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user