[#1584] Code generation error with Oracle UDT static functions
This commit is contained in:
parent
e44416aed6
commit
7a56784539
@ -238,7 +238,7 @@ public class DefaultGenerator extends AbstractGenerator {
|
||||
}
|
||||
|
||||
if (database.getUDTs(schema).size() > 0) {
|
||||
generateUDTDefinitions(schema);
|
||||
generateUDTRecords(schema);
|
||||
}
|
||||
|
||||
if (database.getUDTs(schema).size() > 0) {
|
||||
@ -743,12 +743,12 @@ public class DefaultGenerator extends AbstractGenerator {
|
||||
/**
|
||||
* Generating UDT record classes
|
||||
*/
|
||||
protected void generateUDTDefinitions(SchemaDefinition schema) {
|
||||
protected void generateUDTRecords(SchemaDefinition schema) {
|
||||
log.info("Generating UDT records");
|
||||
|
||||
for (UDTDefinition udt : database.getUDTs(schema)) {
|
||||
try {
|
||||
generateUDTDefinition(udt);
|
||||
generateUDTRecord(udt);
|
||||
} catch (Exception e) {
|
||||
log.error("Error while generating UDT record " + udt, e);
|
||||
}
|
||||
@ -757,7 +757,7 @@ public class DefaultGenerator extends AbstractGenerator {
|
||||
watch.splitInfo("UDT records generated");
|
||||
}
|
||||
|
||||
protected void generateUDTDefinition(UDTDefinition udt) {
|
||||
protected void generateUDTRecord(UDTDefinition udt) {
|
||||
log.info("Generating UDT record", strategy.getFileName(udt, Mode.RECORD));
|
||||
|
||||
GenerationWriter out = new GenerationWriter(strategy.getFile(udt, Mode.RECORD));
|
||||
@ -783,14 +783,20 @@ public class DefaultGenerator extends AbstractGenerator {
|
||||
|
||||
// [#799] Oracle UDT's can have member procedures
|
||||
for (RoutineDefinition routine : udt.getRoutines()) {
|
||||
|
||||
// Instance methods ship with a SELF parameter at the first position
|
||||
// [#1584] Static methods don't have that
|
||||
boolean instance = routine.getInParameters().size() > 0
|
||||
&& routine.getInParameters().get(0).getInputName().toUpperCase().equals("SELF");
|
||||
|
||||
try {
|
||||
if (!routine.isSQLUsable()) {
|
||||
// Instance execute() convenience method
|
||||
printConvenienceMethodProcedure(out, routine, true);
|
||||
printConvenienceMethodProcedure(out, routine, instance);
|
||||
}
|
||||
else {
|
||||
// Instance execute() convenience method
|
||||
printConvenienceMethodFunction(out, routine, true);
|
||||
printConvenienceMethodFunction(out, routine, instance);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -125,6 +125,7 @@ import org.jooq.test.oracle.generatedclasses.test.tables.records.VLibraryRecord;
|
||||
import org.jooq.test.oracle.generatedclasses.test.tables.records.XUnusedRecord;
|
||||
import org.jooq.test.oracle.generatedclasses.test.udt.OInvalidType;
|
||||
import org.jooq.test.oracle.generatedclasses.test.udt.UAddressType;
|
||||
import org.jooq.test.oracle.generatedclasses.test.udt.UAuthorType;
|
||||
import org.jooq.test.oracle.generatedclasses.test.udt.UInvalidTable;
|
||||
import org.jooq.test.oracle.generatedclasses.test.udt.UInvalidType;
|
||||
import org.jooq.test.oracle.generatedclasses.test.udt.UStreetType;
|
||||
@ -1019,6 +1020,8 @@ public class jOOQOracleTest extends jOOQAbstractTest<
|
||||
|
||||
@Test
|
||||
public void testOracleMemberProcedures() throws Exception {
|
||||
jOOQAbstractTest.reset = false;
|
||||
|
||||
UAuthorTypeRecord author1;
|
||||
UAuthorTypeRecord author2;
|
||||
|
||||
@ -1074,6 +1077,24 @@ public class jOOQOracleTest extends jOOQAbstractTest<
|
||||
assertEquals(1, (int) author1.getId());
|
||||
assertEquals("George", author1.getFirstName());
|
||||
assertEquals("Orwell", author1.getLastName());
|
||||
|
||||
// [#1584] Test STATIC MEMBER procedure calls
|
||||
UAuthorTypeRecord author3 = UAuthorType.newAuthor(ora(), 3, "first", "last");
|
||||
assertEquals(3, (int) author3.getId());
|
||||
assertEquals("first", author3.getFirstName());
|
||||
assertEquals("last", author3.getLastName());
|
||||
|
||||
UAuthorTypeRecord author4 = UAuthorType.getAuthor(ora(), 3);
|
||||
assertEquals(author3, author4);
|
||||
assertEquals(3, (int) author4.getId());
|
||||
assertEquals("first", author4.getFirstName());
|
||||
assertEquals("last", author4.getLastName());
|
||||
|
||||
UAuthorTypeRecord author5 = ora().select(UAuthorType.getAuthor(3)).fetchOne(UAuthorType.getAuthor(3));
|
||||
assertEquals(author3, author5);
|
||||
assertEquals(3, (int) author5.getId());
|
||||
assertEquals("first", author5.getFirstName());
|
||||
assertEquals("last", author5.getLastName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -127,7 +127,14 @@ CREATE OR REPLACE TYPE u_author_type AS OBJECT (
|
||||
book2 OUT u_book_type,
|
||||
books OUT u_book_table),
|
||||
|
||||
member function count_books return number
|
||||
member function count_books return number,
|
||||
static procedure new_author (
|
||||
p_id number,
|
||||
p_first_name varchar2,
|
||||
p_last_name varchar2,
|
||||
p_author OUT u_author_type),
|
||||
|
||||
static function get_author (p_id number) return u_author_type
|
||||
)
|
||||
/
|
||||
|
||||
@ -205,6 +212,28 @@ CREATE OR REPLACE TYPE BODY u_author_type AS
|
||||
|
||||
return r;
|
||||
end count_books;
|
||||
|
||||
static procedure new_author (
|
||||
p_id number,
|
||||
p_first_name varchar2,
|
||||
p_last_name varchar2,
|
||||
p_author OUT u_author_type) is
|
||||
result u_author_type;
|
||||
begin
|
||||
insert into t_author (id, first_name, last_name)
|
||||
values (p_id, p_first_name, p_last_name);
|
||||
|
||||
p_author := get_author(p_id);
|
||||
end new_author;
|
||||
|
||||
static function get_author (p_id number) return u_author_type is
|
||||
result u_author_type;
|
||||
begin
|
||||
result := u_author_type(p_id, null, null);
|
||||
result.load;
|
||||
return result;
|
||||
end get_author;
|
||||
|
||||
end;
|
||||
/
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user