Simple ops on embedded DB - NullPointerException

Hello all

Update: Sorry for the formatting… Please go here for nicer output:

http://pastebin.ca/341268


Using wildfire 3.1.1 on gentoo platform.

I am trying to create a simple java program to implement batch operations, such as deleting all users in the system. However, I am getting NullPointerException on most operations. My program is as shown on the link above.

I am going through the wildfire API, but with not much success. Here are the results of such a program.

wonderlight wildfire # time java -cp “/opt/wildfire/lib/wildfire.jar:.” Test

Constructor has been called.

Getting read-only status…false

Exception in thread “main” java.lang.NullPointerException

at org.jivesoftware.wildfire.user.DefaultUserProvider.getUsernames(DefaultUserProv ider.java:224)

at Test.getUsernames(Test.java:47)

at Test.main(Test.java:63)

real 0m30.452s

user 0m0.360s

sys 0m0.024s

Thanks for your time and help. If you have any working examples, feel free to point me in the right direction.

Best,

fred

Message was edited by: chapeaurouge

Message was edited by: chapeaurouge

Hi Fred,

it would help a lot if the line number you did post her would match the ones at http://pastebin.ca/341268

You execute “conn = new DefaultUserProvider();” two times, this makes no sense.

LG

Sorry

Here is the updated result, with correct lines:

wonderlight wildfire # time java -cp “/opt/wildfire/lib/wildfire.jar:.” Test

Constructor has been called.

Getting read-only status…false

Exception in thread “main” java.lang.NullPointerException

at org.jivesoftware.wildfire.user.DefaultUserProvider.getUsernames(DefaultUserProv ider.java:224)

at Test.getUsernames(Test.java:43)

at Test.main(Test.java:56)

real 0m30.450s

user 0m0.336s

sys 0m0.040s

Ok. I can the extra ones… but it doesn"t change the result.

Hi,

with Wildfire 3.1.1 your example fails with “The method getUsernames() is undefined for the type DefaultUserProvider” while using “Collection c = conn.getUsers();” works fine.

LG

ok. Still doesn"t work however, I get the same error message.

I am having the same error for getUserCount(). I am a bit lost… :X

I am using the following javadoc link: http://www.jivesoftware.org/builds/wildfire/docs/latest/documentation/javadoc/or g/jivesoftware/wildfire/user/DefaultUserProvider.html

Nevermind… I am getting another error now, which I will investigate. question though… why are the other methods not working and they are documented in the javadoc?

wonderlight wildfire # time java -cp “/opt/wildfire/lib/wildfire.jar:/opt/wildfire/lib/hsqldb.jar:.” Test

Constructor has been called.

Getting read-only status…false

Missing database schema for wildfire. Attempting to install…

java.sql.SQLException: Table not found in statement

at org.hsqldb.jdbc.Util.throwError(Unknown Source)

at org.hsqldb.jdbc.jdbcPreparedStatement.(Unknown Source)

at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)

at org.jivesoftware.database.AbstractConnection.prepareStatement(AbstractConnectio n.java:36)

at org.jivesoftware.wildfire.user.DefaultUserProvider.getUsernames(DefaultUserProv ider.java:224)

at org.jivesoftware.wildfire.user.DefaultUserProvider.getUsers(DefaultUserProvider .java:213)

at Test.getUsers(Test.java:43)

at Test.main(Test.java:56)

real 0m0.874s

user 0m0.752s

sys 0m0.040s

I am at a loss… I didn’'t do anything and I am getting these errors now (which might be making more sense?), even with the methods that were not working before… All I did was enable debug logs…

???

@javadoc: you’'re right, my classpath did contain some old Wildfire jar files. So for me it works also with c = conn.getUserCount();

Hi,

did you run Wildfire one time and did configure the database before you did try to access it using your progeam?

LG

Well, my installation dissapeared … I ran a wildfire restart, and all of a sudden, when accessing the admin interface, it showed me the setup routine… Indeed my DB file was gone.

I am in the process of reinstalling… Maybe these errors will go away. Will keep this thread updated.

Thanks for the help.

I reinstalled wildfire, this time with 3.2 beta2, just for fun. Embedded DB (for 100 users, i guess it’'s still ok?), reran that program, and still get

wonderlight wildfire_java # time java -cp “/opt/wildfire/lib/wildfire.jar:/opt/wildfire/lib/hsqldb.jar:.” Test

Constructor has been called.

Getting user count…Missing database schema for wildfire. Attempting to install…

java.sql.SQLException: Table not found in statement

at org.hsqldb.jdbc.Util.throwError(Unknown Source)

at org.hsqldb.jdbc.jdbcPreparedStatement.(Unknown Source)

at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)

at org.jivesoftware.database.AbstractConnection.prepareStatement(AbstractConnectio n.java:36)

at org.jivesoftware.wildfire.user.DefaultUserProvider.getUserCount(DefaultUserProv ider.java:197)

at Test.getCount(Test.java:32)

at Test.main(Test.java:54)

and so on. I have some users created, I am even currently logged in to wildfire.

is there something I am missing that I should do to point the program to the DB? Constructors do not accept argument, so I don’'t know.

Thanks.

Hi,

maybe

JiveGlobals.setHomeDirectory("/opt/wildfire");
JiveGlobals.setConfigName("conf/wildfire.xml");

works better.

LG

That did it

But now, another error, héhé… I guess a config value to set? I however have Supports multiple connections

open at once: Yes in the database section of the admin console.

wonderlight wildfire_java # time java -cp “/opt/wildfire/lib/wildfire.jar:/opt/wildfire/lib/hsqldb.jar:.” Test

Constructor has been called.

Getting user count…Failed to create new connections on startup. Attempt 0 of 3

java.sql.SQLException: The database is already in use by another process: org.hsqldb.persist.NIOLockFile@20462e09[file =/opt/wildfire/embedded-db/wildfire.lck, exists=true, locked=false, valid=false, fl =null]: java.lang.Exception: checkHeartbeat(): lock file /opt/wildfire/embedded-db/wildfire.lck is presumably locked by another process.

at org.hsqldb.jdbc.Util.sqlException(Unknown Source)

at org.hsqldb.jdbc.jdbcConnection.(ConnectionPool.java:88)

at org.jivesoftware.database.EmbeddedConnectionProvider.start(EmbeddedConnectionPr ovider.java:75)

at org.jivesoftware.database.DbConnectionManager.setConnectionProvider(DbConnectio nManager.java:459)

at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager .java:77)

at org.jivesoftware.wildfire.user.DefaultUserProvider.getUserCount(DefaultUserProv ider.java:196)

at Test.getCount(Test.java:32)

at Test.main(Test.java:54)

Hi,

do you want to run your program while Wildfire is running? This will fail as the database runs in embedded mode.

LG

ok I see.

I am marking this question as answered, thanks for all

I guess then that I would need to migrate to an external database for added flexibility, and maybe performance? Would a 100 users be a high number enough to justify the use of mysql for example?

Hi,

if you know how to run, backup and restore MySQL you may want to use it also for 3 users. If you like the HSQLDB you can run it in standalone mode and use JDBC connections (one for Wildfire, one of your application) to access it.

With 100 users it should be possible to stop the server at night and run the scripts you want to run.

Warning: As Wildfire uses a database cache it’'s never a good idea to modify database content via SQL while it is running.

LG