Project

General

Profile

"setData" in JDBCRepository fail at the beginning

Keren Meir
Added over 5 years ago

hi,

I'm trying to set data in db by "void setData(BareJID user, String subnode, String key, String value)" function as mention in

http://www.tigase.org/content/tigase-db-schema-explained#comments

I defined:

@JDBCRepository repos = new JDBCRepository();

repos.setData(session.getBareJID(), "root", "example", "example");@

I got exception at the line "DataRepository repo = data_repo.takeRepoHandle(user_id);" in the beginning of "setData" function.

After the exception was catch I see that repo = tigase.db.NonAuthUserRepositoryImpl@19cc92f

What is the problem and what do I need to change?

Here is the log:

2013-08-13 15:44:46 WorkerThread.run() SEVERE: tigase.server.xmppsession.SessionManager$ProcessorWorkerThread,(presence Queue Worker 1) Exception during packet processing: from=c2s@aaa.aaa.aaa.com/127.0.0.1_5222_127.0.0.1_64731, to=sess-man@aaa.aaa.aaa.com, DATA=

5

15b3209e5f74c14c9c93e47156c6ef5fd273e70c

, SIZE=313, XMLNS=jabber:client, PRIORITY=PRESENCE, PERMISSION=NONE, TYPE=null

java.lang.NullPointerException

at tigase.db.jdbc.JDBCRepository.setData(JDBCRepository.java:1077)

at tigase.xmpp.impl.Presence.process(Presence.java:866)

at tigase.server.xmppsession.SessionManager$ProcessorWorkerThread.process(SessionManager.java:2135)

at tigase.util.WorkerThread.run(WorkerThread.java:132)

Replies (11)

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 5 years ago

The user repository has to be properly initialized with a Db connection string and other settings. You should not create it's instance manually. Please use the API. What API? It depends on what you are actually trying to do.

Are you coding a new component or a plugin or what?

Added by Keren Meir over 5 years ago

I'm trying to save the user's presence to 'tig_pairs' table in db.

How do I initialized the user repository?

Can you show me the documentation please?

Thank you

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 5 years ago

Could you please tell more on how are you trying to save the presence in DB? How do you intercept the presence, what part of system? Depending on how you do it, a different API should be used.

Added by Keren Meir over 5 years ago

Sorry, I forgot to mention:

I'm writing the code in the presence plugin: xmpp/impl/presence.java.

In the process method I save the status in a String and want to save it to db.

Need some more details?

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 5 years ago

If you write a plugin code, than you should use API exposed to plugins. Usually you want to update DB through XMPPResourceConnection.setData/getData methods. More details should be available in the JavaDoc documentation.

This way you do not have to worry about DB initialization and stuff like this.

Also, my suggestion is, that instead of modifying Tigase existing code, write your own plugin and load on to the server. Much less trouble during upgrading installation to a new software version.

Added by Keren Meir over 5 years ago

Thank you for your answer.

I'll check it out.

Where can I find the JavaDoc documentation? in the code itself the Javadoc is missing...

And according to new plugin - I asked before if you suggest me to write a new plugin or changing existing one, and I got an answer:

https://projects.tigase.org/boards/4/topics/119

"2. in my opinion it would be the best to extend current presence plugin and override only necessary parts; however adding new kind of presence (as per Show Element) could be more of a client side addition."

Isn't that mean that I extend my existing presence plugin?

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 5 years ago

Did you edit the post? I have a different content in an email notification....

Anyway.

Where can I find the JavaDoc documentation? in the code itself the Javadoc is missing...

Actually the XMPPResourceConnection extends RepositoryAccess which does have these methods (setData/getData) and there is JavaDoc for these methods.

And according to new plugin - I asked before if you suggest me to write a new plugin or changing existing one, and I got an answer:

https://projects.tigase.org/boards/4/topics/119

"2. in my opinion it would be the best to extend current presence plugin and override only necessary parts; however adding new kind of presence (as per Show Element) could be more of a client side addition."

Isn't that mean that I extend my existing presence plugin?

Please do not mix 2 topic, continue discussion on each subject within it's own forum topic to avoid confusion.

I meant to write own plugin, not extending existing Presence plugin. You can have many plugins loaded and running at the same time, each of them executing own, custom processing.

Added by Keren Meir over 5 years ago

Hi,

Yes, I edited the post because I found the set/get function (as you said, on RepositoryAccess)

According to the plugin, do you mean that for every presence mechanism that I want to add, is it better to add a new plugin?

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 5 years ago

The main thing is that you do not edit and modify the Tigase own files. Otherwise upgrading to a new version will always be a pain as you will have to edit over and over again Tigase's files. If you keep your code separately then you just copy JAR file with your files and that's it.

Wether you keep all your custom logic within a single plugin or multiple is a matter of your preference. I prefer to keep code small and simple, so each plugin or class is responsible for a single task.

Added by Keren Meir over 5 years ago

Ok. Thanks :)

Added by Keren Meir over 5 years ago

.

    (1-11/11)