agora inbox for pljava-dev@postgresql.org
help / color / mirror / Atom feed[Pljava-dev] Possible to override default type mappings?
3+ messages / 0 participants
[nested] [flat]
* [Pljava-dev] Possible to override default type mappings?
@ 2006-08-07 00:51
2006-08-14 22:41 ` [Pljava-dev] Possible to override default type mappings?
0 siblings, 1 reply; 3+ messages in thread
From: @ 2006-08-07 00:51 UTC (permalink / raw)
Hello,
In order to use a pre-existing Java library which works with specialized
implementations of the basic SQL types (varchar, int, etc.), I am trying
to override the default type mappings for these types to use our
specialized classes instead of java.lang.String, java.lang.Integer, etc.
Is this possible? I keep getting an error:
test_db=# select indexOf('ABC', 'A');
ERROR: No java type mapping installed for "test.character"
I have used SQLJ to install my jar with a deployment descriptor which
adds the type mappings and creates my "indexOf(varchar, varchar)" function:
select sqlj.add_type_mapping('int', 'test.integer');
select sqlj.add_type_mapping('varchar', 'test.character');
create function indexOf(varchar, varchar) returns int
as 'test.character.indexOf(test.character, test.character)'
language java;
There are no errors at this stage and it looks as though the type
mappings were set up correctly:
test_db=# select * from sqlj.typemap_entry;
mapid | javaname | sqlname
-------+----------------+--------------------
46 | test.integer | pg_catalog.int4
47 | test.character | pg_catalog.varchar
I also use sqlj.set_classpath to set my classpath to my installed jar,
which reports no error.
I am testing with PL/Java version 1.3.0 on SUSE Linux 10, PG 8.1.3
(though I will need to support this configuration with PG 8.1.4 on
multiple Linux distros).
Thanks in advance for any help.
Regards,
Eric Faulhaber
^ permalink raw reply [nested|flat] 3+ messages in thread
* [Pljava-dev] Possible to override default type mappings?
2006-08-07 00:51 [Pljava-dev] Possible to override default type mappings?
@ 2006-08-14 22:41 `
2006-08-15 14:37 ` [Pljava-dev] Possible to override default type mappings?
0 siblings, 1 reply; 3+ messages in thread
From: @ 2006-08-14 22:41 UTC (permalink / raw)
Eric Faulhaber wrote:
> Hello,
>
> In order to use a pre-existing Java library which works with specialized
> implementations of the basic SQL types (varchar, int, etc.), I am trying
> to override the default type mappings for these types to use our
> specialized classes instead of java.lang.String, java.lang.Integer, etc.
>
> Is this possible? I keep getting an error:
>
No, it's not possible and that's very intentional. I can't see any use-case where replacing
the default mapping for a basic type would make sense. Perhaps you could elaborate this?
Would using SQL domains help you?
> There are no errors at this stage and it looks as though the type
> mappings were set up correctly:
>
> test_db=# select * from sqlj.typemap_entry;
> mapid | javaname | sqlname
> -------+----------------+--------------------
> 46 | test.integer | pg_catalog.int4
> 47 | test.character | pg_catalog.varchar
>
Hmm, it should yield and error. I'll have to look into that.
Regards,
Thomas Hallgren
^ permalink raw reply [nested|flat] 3+ messages in thread
* [Pljava-dev] Possible to override default type mappings?
2006-08-07 00:51 [Pljava-dev] Possible to override default type mappings?
2006-08-14 22:41 ` [Pljava-dev] Possible to override default type mappings?
@ 2006-08-15 14:37 `
0 siblings, 0 replies; 3+ messages in thread
From: @ 2006-08-15 14:37 UTC (permalink / raw)
Thomas Hallgren wrote:
> Eric Faulhaber wrote:
>> Hello,
>>
>> In order to use a pre-existing Java library which works with specialized
>> implementations of the basic SQL types (varchar, int, etc.), I am trying
>> to override the default type mappings for these types to use our
>> specialized classes instead of java.lang.String, java.lang.Integer, etc.
>>
>> Is this possible? I keep getting an error:
>>
> No, it's not possible and that's very intentional. I can't see any
> use-case where replacing the default mapping for a basic type would make
> sense. Perhaps you could elaborate this? Would using SQL domains help you?
>
My question was based on my initial [mis]understanding that the type
mapping was one-way. That is, I thought the mappings were isolated
within the scope of PL/Java only, such that the backend could use
standard SQL types, and would leave it to PL/Java to perform the mapping
to/from a custom Java class for function parameters and return values.
I didn't realize that a custom type defined with PL/Java was "installed"
into the backend using PG's UDT architecture. I see now that this is
the case and that it would be problematic/dangerous to redefine the
basic types in the backend.
The reason for all this is that we have an existing Java library which
uses non-J2SE wrappers for int, double, boolean, etc. These are
necessary to support the very specialized semantics of a runtime
environment for a legacy application. We actually want to keep default
types in the database schema, but map these to our specialized types in
the JVM only. Our wrapper types are a middle tier necessity only, we
don't want to "pollute" the backend with them. I believe SQL domains
are meant to solve a different problem and are not appropriate here.
I was trying to avoid re-implementing our existing function library to
use J2SE wrapper types. My compromise was to create a "shim" API
exclusively for PL/Java's use, which accepts and returns only primitives
or J2SE wrappers, but which creates instances of our custom types and
invokes methods in our existing library under the covers. It works
generally, but it adds an extra layer which is tedious to maintain.
Nevertheless, it is worth the effort, given the advantages of executing
the functions at the server.
>> There are no errors at this stage and it looks as though the type
>> mappings were set up correctly:
>>
>> test_db=# select * from sqlj.typemap_entry;
>> mapid | javaname | sqlname
>> -------+----------------+--------------------
>> 46 | test.integer | pg_catalog.int4
>> 47 | test.character | pg_catalog.varchar
>>
> Hmm, it should yield and error. I'll have to look into that.
>
> Regards,
> Thomas Hallgren
Thanks for your response, and thanks for creating and supporting a
useful and innovative project.
Regards,
Eric Faulhaber
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2006-08-15 14:37 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-07 00:51 [Pljava-dev] Possible to override default type mappings?
2006-08-14 22:41 `
2006-08-15 14:37 `
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox