Directly manipulate database data to add friends to OpenFire users

Source: Internet
Author: User

[Size=large]openfire enables friend addition and group management.


Mainly based on two table implementations: Ofroster,ofrostergroups.


Ofroster: Used to record a friend relationship (a pair of friends with two records to achieve)
Ofrostergroups: Used to record buddy groups


Special Note: OpenFire the user's primary key is the natural primary key, namely username. The self-increment ID is not used.


Let's take a look at the official (http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/database-guide.html) Description of the two tables:
Ofroster (Friends List)
[Table]
| column name | type | length | description |
|rosterid | Number |N/A | Numbered roster (PRIMARY key) |
|username | VARCHAR |32 | user name |
|jid | TEXT |n/a | Address List entry |
|sub | Number |n/a | Subscription Status Entry |
|ask | Number |n/a | Sell status Entry |
|recv | Number |N/A | Whistleblowing indicates access to the roster received request |
|nick | VARCHAR |255 | Nickname assigned to this register entry |
[/table]
Ofrostergroups (an entry in the group's friends list)
[Table]
| column name | type | length | description |
|rosterid | Number |n/a | Book numbers (primary key) |
|rank | Number |n/a | Position entry (PRIMARY key) |
|groupname | VARCHAR |255 | user-defined name, this roster group |
[/table]
Can't you see? Don't worry, we'll analyze it slowly.


Assume that there is User A, User B.


When a applies plus B as a friend (for example, a adds B to the group of good relatives). Two records are inserted in the Ofroster table,


Rosterid Username Jid Sub Ask recv Nick


1 A 0 0-1 B
2 B 0-1 1 null


Insert a record into the ofrostergroups table at the same time


Rosterid Rank GroupName


1 0 family members


When B agrees to add a as a friend and set it as a family group, the two records just inserted in the Ofroster table will be modified as follows:


Rosterid Username Jid Sub Ask recv Nick


1 A 1-1 1 B
2 B 2 0-1 null


Also insert a record into the ofrostergroups table.


Rosterid Rank GroupName


2 0 Family


So far, the relationship between the two sides has been set up.


Question: 1. What does B mean? No action is made. Next time, if B plus a is a friend, it will be the same as performing the agreed action.


2. How do I find all my friends, and groups, for a person?


All of a user's friend information is available in Ofroster based on username. Then find the grouped names in the Ofrostergroups table based on the rosterid of each record.


3. When the user adds an empty buddy group, does the ofrostergroups table insert a record?


Do not plug in, the test found that there is no actual insertion of a record, but the user can see the group name, what's going on? Speculation may be stored in the session. The test found that when the user creates an empty buddy group, then goes offline, and then comes online, it finds that the buddy Group has disappeared. It's a good indication that when a friend group is empty, there is no docking.


Let's talk about what each field means:
Askstatus
-No pending Add Friend request.
The roster item has no pending subscription requests.
0-There is a pending add friend request.
The roster item has a been asked for permission to subscribe and its presence and no response has been received.
1-estimated that there is no reply to the delete request now
The roster owner has asked the roster item to being unsubscribed from its presence notifications but hasn ' t yet received Conf I rmation.
Recvstatus
+ has replied to add Friend request
There is no subscriptions that has been received but not presented to the user.
1-received a friend request but did not reply to a friend
The server has received a SUBSCRIBE request, but have not forwarded it to the user.
2-estimated that there was no reply to the delete request.
The server has received a unsubscribe request, but have not forwarded it to the user.
Substatus
You should delete this friend
Indicates that the roster item is should be removed.
0-No friend relationship established
No subscription is established.
1-user has made friend request
The roster owner has a subscription to the roster item ' s presence.
2-Receive friend requests and add friends
The roster item has a subscription to the roster owner ' s presence.
3-Friends have been added to each other
The roster item and the owner have a mutual subscription.


After knowing this, we generally understand the process of adding a friend, and here's how we code [/size]
[code= "java"]public static void Main (string[] args) {
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try {
Class.forName ("Oracle.jdbc.driver.OracleDriver");
New Oracle.jdbc.driver.OracleDriver ();
conn = Drivermanager.getconnection ("JDBC:ORACLE:THIN:@192.168.1.85:1521:ORCL", "Test", "test");
stmt = Conn.createstatement ();
AAA and Eee Add friends to each other
String sql= "INSERT into ofroster values (' + ', ' eee ', ' [email protected] ', ' 3 ', '-1 ', '-1 ', ' aaa ')";
Stmt.execute (SQL);
String sql2= "INSERT into ofroster values (' + ', ' aaa ', ' [email protected] ', ' 3 ', '-1 ', '-1 ', ' eee ')";
Stmt.execute (SQL2);
Put AAA and Eee in a friend group
String sql3= "INSERT into ofrostergroups values (' + ', ' 0 ', ' Friend ')";
Stmt.execute (SQL3);
String sql4= "INSERT into ofrostergroups values (' + ', ' 0 ', ' Friend ')";
Stmt.execute (SQL4);
} catch (ClassNotFoundException e) {
E.printstacktrace ();
} catch (SQLException e) {
E.printstacktrace ();
} finally {
try {
if (rs! = null) {
Rs.close ();
rs = null;
}
if (stmt! = null) {
Stmt.close ();
stmt = null;
}
IF (conn! = null) {
Conn.close ();
conn = null;
}
} catch (SQLException e) {
E.printstacktrace ();
}
}
} [/code]
[Size=large] This is my use of JDBC Direct operation of the database operations, at first it seems not possible, and then I added a openfire officially provided by a plugin: Subscriptionplugin, the main implementation of the plugin automatically added a friend's function. Once added, it will be done.
Can I have any questions [/size]

Directly manipulate database data to add friends to OpenFire users

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.