[Pljava-dev] Unable to find static method error

From: brightpony at gmail(dot)com ( 马皓明 )
To:
Subject: [Pljava-dev] Unable to find static method error
Date: 2008-04-24 18:19:38
Message-ID: 542c32f50804241119k115d718ejde17e63ff9ae4c32@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

Hello, everyone. I'm a newbie to pljava, and I came across "Unable to find
static method" error.

I've build a jar called myproject-pljava.jar, and there is a Test.java in
myproject-pljava.jar like this:

public class Test {
public static Timestamp getTimestamp() {
return new Timestamp(System.currentTimeMillis());
}
}

And there is a IndexSyncTrigger.java in myproject-pljava.jar ( I want to use
pljava to write some triggers to keep Lucene index synchronized with the
data in DB. ) which denpends other jars such as spring.jar,
commons-configurations.jar.

I can call Test.getTimestamp from SQL and it works well. But when I tried to
call IndexSyncTrigger.getTimestamp and IndexSyncTrigger.getBeansCount, I
always got an error:

Error: Unable to find static method
com.mycompany.myproject.pljava.IndexSyncTrigger.getTimestamp with signature
()Ljava/sql/Timestamp;

********** Error **********

Error: Unable to find static method
com.mycompany.myproject.pljava.IndexSyncTrigger.getTimestamp with signature
()Ljava/sql/Timestamp;
SQL state: XX000

----------------------------------------------------------------------------------------------

I've put all of the dependent jars to a dir and config them in the
postgresql.conf, just like this:

custom_variable_classes = 'pljava'

pljava.classpath =
'/opt/pljava-classpath/pljava.jar:/opt/pljava-classpath/commons-collections.jar:/opt/pljava-classpath/lucene-analyzers-2.2.0.jar:/opt/pljava-classpath/commons-configuration-1.3.jar:/opt/pljava-classpath/lucene-core-2.2.0.jar:/opt/pljava-classpath/commons-io.jar:/opt/pljava-classpath/jakarta-oro-2.0.8.jar:/opt/pljava-classpath/lucene-memory-2.2.0.jar:/opt/pljava-classpath/commons-lang.jar:/opt/pljava-classpath/jchardet-1.0.jar:/opt/pljava-classpath/pljava.jar:/opt/pljava-classpath/commons-logging.jar:/opt/pljava-classpath/log4j-1.2.14.jar:/opt/pljava-classpath/spring.jar:/opt/pljava-classpath/classes:/opt/pljava-classpath/terrier-lexer.jar'

And the deployment descriptor and the IndexSyncTrigger.java are here:

SQLActions[] = {
"BEGIN INSTALL
CREATE SCHEMA myproject_pljava;
BEGIN PostgreSQL SET search_path TO myproject_pljava,public END
postgreSQL;

CREATE FUNCTION myproject_pljava.tk_getTimestamp()
RETURNS timestamp
AS 'com.mycompany.myproject.pljava.IndexSyncTrigger.getTimestamp'
LANGUAGE javaU;
CREATE FUNCTION myproject_pljava.tk_testgetTimestamp()
RETURNS timestamp
AS 'com.mycompany.myproject.pljava.Test.getTimestamp'
LANGUAGE javaU;
CREATE FUNCTION tk_getBeansCount()
RETURNS int4
AS 'com.mycompany.myproject.pljava.IndexSyncTrigger.getBeansCount'
LANGUAGE javaU;
END INSTALL",
"BEGIN REMOVE
DROP SCHEMA myproject_pljava CASCADE;
END REMOVE"
}

public class IndexSyncTrigger {

private static final String NAME_COL = "name";

private static final String ALIAS_COL = "alias";

private static final String ID = "id";

private static final String TYPE = "type";

private static final String CITY_ID = "city_id";

private static ApplicationContext context = new
ClassPathXmlApplicationContext(
new String[] { "pljavaContext.xml" });

private static Indexer indexer = (Indexer)
context.getBean("myprojectIndexer");

private static PoiDocument getDocument(ResultSet rs, String table)
throws SQLException {
String name = rs.getString(NAME_COL);

String alias = rs.getString(ALIAS_COL);

Long id = rs.getLong(ID);

String type = rs.getString(TYPE);

String cityId = rs.getString(CITY_ID);

return new PoiDocument(table, id, cityId, name, alias, type);
}

public static void update(TriggerData td) throws SQLException {
checkTd(td);

if (!td.isFiredByUpdate())
throw new TriggerException(td, "must be fired by update event");

String table = td.getTableName();
PoiDocument newDoc = getDocument(td.getOld(), table);
PoiDocument oldDoc = getDocument(td.getNew(), table);

indexer.update(oldDoc, newDoc);
}

private static void checkTd(TriggerData td) throws SQLException,
TriggerException {
if (td.isFiredForStatement())
throw new TriggerException(td, "can't process STATEMENT
events");

if (td.isFiredBefore())
throw new TriggerException(td, "must be fired after event");
}

public static void delete(TriggerData td) throws SQLException {
checkTd(td);
if (!td.isFiredByDelete())
throw new TriggerException(td, "must be fired by delete event");
indexer.delete(getDocument(td.getOld(), td.getTableName()));
}

public static void add(TriggerData td) throws SQLException {
checkTd(td);
if (!td.isFiredByInsert())
throw new TriggerException(td, "must be fired by insert event");
indexer.add(getDocument(td.getNew(), td.getTableName()));
}

public static void flush() throws SQLException {
indexer.flush();
}

public static void optimize() throws SQLException {
indexer.optimize();
}

public static int getBeansCount() {
return context.getBeanDefinitionCount();
}

public static Timestamp getTimestamp() {
return new Timestamp(System.currentTimeMillis());
}
}

BTW, I'm using postgresql 8.2 on Ubuntu 8.04, and pljava 1.4.

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20080425/0b9d9631/attachment.html>

Browse pljava-dev by date

  From Date Subject
Next Message Hauke Luckow 2008-04-25 16:20:37 [Pljava-dev] Problem PL/Java installation
Previous Message Alexander Wöhrer 2008-04-22 13:26:45 [Pljava-dev] stack depth limit exceeded - patch possible?