Open
Description
This is actually a question.
In order to support the mapping of fields of array type, Hibernate ORM run some queries to create a custom type. For example, for supporting integer arrays, it runs:
create or replace type IntegerArray as varying array(127) of number(10,0)
create or replace function IntegerArray_cmp(a in IntegerArray, b in IntegerArray) return number deterministic is begin if a is null or b is null then return null; end if; for i in 1 .. least(a.count,b.count) loop if a(i) is null or b(i) is null then return null;elsif a(i)>b(i) then return 1;elsif a(i)<b(i) then return -1; end if; end loop; if a.count=b.count then return 0; elsif a.count>b.count then return 1; else return -1; end if; end;
create or replace function IntegerArray_distinct(a in IntegerArray, b in IntegerArray) return number deterministic is begin if a is null and b is null then return 0; end if; if a is null or b is null or a.count <> b.count then return 1; end if; for i in 1 .. a.count loop if (a(i) is null)<>(b(i) is null) or a(i)<>b(i) then return 1; end if; end loop; return 0; end;
create or replace function IntegerArray_position(arr in IntegerArray, elem in number, startPos in number default 1) return number deterministic is begin if arr is null then return null; end if; if elem is null then for i in startPos .. arr.count loop if arr(i) is null then return i; end if; end loop; else for i in startPos .. arr.count loop if arr(i)=elem then return i; end if; end loop; end if; return 0; end;
create or replace function IntegerArray_length(arr in IntegerArray) return number deterministic is begin if arr is null then return null; end if; return arr.count; end;
create or replace function IntegerArray_concat(arr0 in IntegerArray,arr1 in IntegerArray,arr2 in IntegerArray default IntegerArray(),arr3 in IntegerArray default IntegerArray(),arr4 in IntegerArray default IntegerArray()) return IntegerArray deterministic is res IntegerArray; begin if arr0 is null or arr1 is null or arr2 is null or arr3 is null or arr4 is null then return null; end if; select * bulk collect into res from (select * from table(arr0) union all select * from table(arr1) union all select * from table(arr2) union all select * from table(arr3) union all select * from table(arr4)); return res; end;
create or replace function IntegerArray_contains(haystack in IntegerArray, needle in IntegerArray, nullable in number) return number deterministic is found number(1,0); begin if haystack is null or needle is null then return null; end if; for i in 1 .. needle.count loop found := 0; for j in 1 .. haystack.count loop if nullable = 1 and needle(i) is null and haystack(j) is null or needle(i)=haystack(j) then found := 1; exit; end if; end loop; if found = 0 then return 0; end if;end loop; return 1; end;
create or replace function IntegerArray_overlaps(haystack in IntegerArray, needle in IntegerArray, nullable in number) return number deterministic is begin if haystack is null or needle is null then return null; end if; if needle.count = 0 then return 1; end if; for i in 1 .. needle.count loop for j in 1 .. haystack.count loop if nullable = 1 and needle(i) is null and haystack(j) is null or needle(i)=haystack(j) then return 1; end if; end loop; end loop; return 0; end;
create or replace function IntegerArray_get(arr in IntegerArray, idx in number) return number deterministic is begin if arr is null or idx is null or arr.count < idx then return null; end if; return arr(idx); end;
create or replace function IntegerArray_set(arr in IntegerArray, idx in number, elem in number) return IntegerArray deterministic is res IntegerArray:=IntegerArray(); begin if arr is not null then for i in 1 .. arr.count loop res.extend; res(i) := arr(i); end loop; for i in arr.count+1 .. idx loop res.extend; end loop; else for i in 1 .. idx loop res.extend; end loop; end if; res(idx) := elem; return res; end;
create or replace function IntegerArray_remove(arr in IntegerArray, elem in number) return IntegerArray deterministic is res IntegerArray:=IntegerArray(); begin if arr is null then return null; end if; if elem is null then for i in 1 .. arr.count loop if arr(i) is not null then res.extend; res(res.last) := arr(i); end if; end loop; else for i in 1 .. arr.count loop if arr(i) is null or arr(i)<>elem then res.extend; res(res.last) := arr(i); end if; end loop; end if; return res; end;
create or replace function IntegerArray_remove_index(arr in IntegerArray, idx in number) return IntegerArray deterministic is res IntegerArray:=IntegerArray(); begin if arr is null or idx is null then return arr; end if; for i in 1 .. arr.count loop if i<>idx then res.extend; res(res.last) := arr(i); end if; end loop; return res; end;
create or replace function IntegerArray_slice(arr in IntegerArray, startIdx in number, endIdx in number) return IntegerArray deterministic is res IntegerArray:=IntegerArray(); begin if arr is null or startIdx is null or endIdx is null then return null; end if; for i in startIdx .. least(arr.count,endIdx) loop res.extend; res(res.last) := arr(i); end loop; return res; end;
create or replace function IntegerArray_replace(arr in IntegerArray, old in number, elem in number) return IntegerArray deterministic is res IntegerArray:=IntegerArray(); begin if arr is null then return null; end if; if old is null then for i in 1 .. arr.count loop res.extend; res(res.last) := coalesce(arr(i),elem); end loop; else for i in 1 .. arr.count loop res.extend; if arr(i) = old then res(res.last) := elem; else res(res.last) := arr(i); end if; end loop; end if; return res; end;
create or replace function IntegerArray_trim(arr in IntegerArray, elems number) return IntegerArray deterministic is res IntegerArray:=IntegerArray(); begin if arr is null or elems is null then return null; end if; if arr.count < elems then raise_application_error (-20000, 'number of elements to trim must be between 0 and '||arr.count); end if;for i in 1 .. arr.count-elems loop res.extend; res(i) := arr(i); end loop; return res; end;
create or replace function IntegerArray_fill(elem in number, elems number) return IntegerArray deterministic is res IntegerArray:=IntegerArray(); begin if elems is null then return null; end if; if elems<0 then raise_application_error (-20000, 'number of elements must be greater than or equal to 0'); end if;for i in 1 .. elems loop res.extend; res(i) := elem; end loop; return res; end;
create or replace function IntegerArray_positions(arr in IntegerArray, elem in number) return sdo_ordinate_array deterministic is res sdo_ordinate_array:=sdo_ordinate_array(); begin if arr is null then return null; end if; if elem is null then for i in 1 .. arr.count loop if arr(i) is null then res.extend; res(res.last):=i; end if; end loop; else for i in 1 .. arr.count loop if arr(i)=elem then res.extend; res(res.last):=i; end if; end loop; end if; return res; end;
create or replace function IntegerArray_to_string(arr in IntegerArray, sep in varchar2) return varchar2 deterministic is res varchar2(4000):=''; begin if arr is null or sep is null then return null; end if; for i in 1 .. arr.count loop if arr(i) is not null then if length(res)<>0 then res:=res||sep; end if; res:=res||arr(i); end if; end loop; return res; end;
With the Oracle Vert.x SQL client, I can do the same and I can create the table with the new defined type.
The problem arise when I try to insert an array in the table. I have the exception:
java.sql.SQLException: ORA-17004: Invalid column type
In the JDBC driver, there are dedicated methods for the creation of a new array and it's possible to specify the name of the custom type when setting the value in the prepared statement.
Is it possible to do something similar with the Vert.x client?