From: | Thomas Hill <Thomas(dot)K(dot)Hill(at)t-online(dot)de> |
---|---|
To: | "\"Welty, Richard\" edsonrichter(at)hotmail(dot)com peter(at)2ndquadrant(dot)com" <rwelty(at)ltionline(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Experiences with pl/Java |
Date: | 2012-11-19 19:55:25 |
Message-ID: | 50AA8EAD.7050900@t-online.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks to all for providing feedback and sharing opinions. Looks like
you have gone much further on it than I thought someone would have. So I
think I might spend some more time with it, but not plan to use it for
my application in a production environment.
My initial attempts were to try to re-use/port some simple procedures
which are running fine on Apache Derby, but then I got stuck quite early
in the process and could not find documentation showing how things needs
to be done and helping me to understand what I am doing wrong.
My first use case was calling a procedure which does not have any
parameter and this I actually got to run, i.e.
public static String CURRENT_CLIENTID() throws SQLException {
String vcFKClientID = "000";
return vcFKClientID;
}
CREATE OR REPLACE FUNCTION rte."CURRENT_CLIENTID"()
RETURNS character varying AS
'onlyPostgreSQLPk.Functions.CURRENT_CLIENTID'
LANGUAGE java VOLATILE SECURITY DEFINER
COST 100;
ALTER FUNCTION rte."CURRENT_CLIENTID"()
OWNER TO postgres;
=> select rte."CURRENT_CLIENTID"() returns '000'
My second use case was to create a procedure with an out parameter, i.e.
public static void SP_getNextID(int iNextVal[], String vcIDName)
throws SQLException {
Connection conn = getDefaultConnection();
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
String cSQL = "SELECT \"LastValue\" \n" + "FROM rte.\"TBL_IDs\"
\n"
+ "WHERE \"IDName\" = '" + vcIDName + "'\n";
ResultSet rs = stmt.executeQuery(cSQL);
while (rs.next()) {
iNextVal[0] = rs.getInt(1) + 1;
rs.updateInt("LastValue", iNextVal[0]);
rs.updateRow();
}
rs.close();
stmt.close();
return;
}
CREATE OR REPLACE FUNCTION rte."SP_getNextID"(OUT "iNextID" integer, IN
"vcIDName" character varying)
RETURNS integer AS
'allDatabasesPk.Procedures.SP_getNextID(int[], java.lang.String)'
The static method seems to be found. But when calling the function using
pgadmin and issuing a 'Select rte."SP_getNextID"('xy');' I am getting error
Too many parameters - expected 1
which I find confusing as I am only passing one parameter!?
I tried some variations I could think of, but without success.
Unfortunately I have not found an exmaple anywhere on the web showing
how this needs to be done.
Would be great if someone could have a look at above and spot what I am
doing wrong.
Thanks a lot in advance.
Kind regards
Thomas
Am 19.11.2012 20:19, schrieb Welty, Richard:
> Edson Richter [edsonrichter(at)hotmail(dot)com] writes:
>> Em 19/11/2012 15:26, Welty, Richard escreveu:
>>> PL/Java requires that the methods being directly called from PostgreSQL are static.
>>> while i don't disagree with the advice, PL/Java is limited in this respect.
>> :-) as I said, I know little about pl/Java... thanks for pointing this out.
>> So, after calling the static method, probably inside the static methods,
>> the programmer will create his/her logic. Writing this logic considering
>> GC behavior would make your apps more stable.
>> I would recommend to not use any Java library that keeps "caches" (ones
>> like EclipseLink or Hibernate), unless you know exactly how to configure
>> caches and soft/weak references - and their limitations.
> i would probably recommend severely limiting what you try to do in PL/Java.
>
> in my particular project, the overall goal was incrementally doing push updates to an Apache
> Solr search engine. this entailed building xml descriptions of the update that was required,
> sending it with an http request (which required untrusted pl/java), and providing a recovery & retry
> mechanism in case the http request failed, which limited itself to using the provided jdbc.
>
> i got it working and working well, but i put a lot of care into insuring that the garbage collecter
> never got stressed very hard and i didn't try to do more than was strictly necessary. i'd argue
> that if you find yourself wanting to use hibernate or eclipselink down in PL/Java, you should
> rethink your application design.
>
> richard
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2012-11-19 19:59:19 | Re: Split_part on a CR |
Previous Message | Jeff Ross | 2012-11-19 19:49:17 | Split_part on a CR |