Commit 68698550 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Comment and formatting fixes.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@39 b35dd754-fafc-0310-a699-88a17e54d16e
parent e6292c62
/**
* DbAuthToken.java
* November 17, 2000
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 1999-2001 CoolServlets, Inc. All rights reserved.
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is the proprietary information of CoolServlets, Inc.
* Use is subject to license terms.
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.auth.spi;
import org.jivesoftware.messenger.auth.AuthToken;
......
......@@ -3,11 +3,12 @@
* $Revision$
* $Date$
*
* Copyright (C) 1999-2001 CoolServlets, Inc. All rights reserved.
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is the proprietary information of CoolServlets, Inc.
* Use is subject to license terms.
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.auth.spi;
import org.jivesoftware.database.DbConnectionManager;
......
......@@ -3,11 +3,12 @@
* $Revision$
* $Date$
*
* Copyright (C) 1999-2003 CoolServlets, Inc. All rights reserved.
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is the proprietary information of CoolServlets, Inc.
* Use is subject to license terms.
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.auth.spi;
import org.jivesoftware.database.DbConnectionManager;
......@@ -31,15 +32,59 @@ import java.util.Date;
*/
public class DbGroupProvider implements GroupProvider {
private static final String INSERT_GROUP =
"INSERT INTO jiveGroup " +
"(name, description, groupID, creationDate, modificationDate) " +
"VALUES (?, ?, ?, ?, ?)";
private static final String LOAD_PROPERTIES =
"SELECT name, propValue FROM jiveGroupProp WHERE groupID=?";
private static final String LOAD_GROUP_BY_ID =
"SELECT name, description, groupID, creationDate, modificationDate " +
"FROM jiveGroup WHERE groupID=?";
private static final String DELETE_PROPERTY =
"DELETE FROM jiveGroupProp WHERE groupID=? AND name=?";
private static final String SAVE_GROUP =
"UPDATE jiveGroup SET name=?, description=?, creationDate=?, modificationDate=? " +
"WHERE groupID=?";
private static final String DELETE_GROUP_USERS =
"DELETE FROM jiveGroupUser WHERE groupID=?";
private static final String DELETE_GROUP =
"DELETE FROM jiveGroup WHERE groupID=?";
private static final String GROUP_COUNT = "SELECT count(*) FROM jiveGroup";
private static final String UPDATE_PROPERTY =
"UPDATE jiveGroupProp SET propValue=? WHERE name=? AND groupID=?";
private static final String INSERT_PROPERTY =
"INSERT INTO jiveGroupProp (groupID, name, propValue) VALUES (?, ?, ?)";
private static final String MEMBER_TEST =
"SELECT userID FROM jiveGroupUser " +
"WHERE groupID=? AND userID=? AND administrator=0";
private static final String ADMIN_TEST =
"SELECT userID FROM jiveGroupUser " +
"WHERE groupID=? AND userID=? AND administrator=1";
private static final String LOAD_ADMINS =
"SELECT userID FROM jiveGroupUser WHERE administrator=1 AND groupID=?";
private static final String LOAD_MEMBERS =
"SELECT userID FROM jiveGroupUser WHERE administrator=0 AND groupID=?";
private static final String GROUP_MEMBER_COUNT =
"SELECT count(*) FROM jiveGroupUser WHERE administrator =0";
private static final String GROUP_ADMIN_COUNT =
"SELECT count(*) FROM jiveGroupUser WHERE administrator =1";
private static final String SELECT_GROUP_BY_NAME =
"SELECT name, description, groupID, creationDate, modificationDate " +
"FROM jiveGroup WHERE name=?";
private static final String REMOVE_USER =
"DELETE FROM jiveGroupUser WHERE groupID=? AND userID=?";
private static final String UPDATE_USER =
"UPDATE jiveGroupUser SET administrator=? WHERE groupID=? userID=?";
private static final String ADD_USER =
"INSERT INTO jiveGroupUser (groupID, userID, administrator) VALUES (?, ?, ?)";
private static final String USER_GROUPS =
"SELECT groupID FROM jiveGroupUser WHERE userID=? AND administrator=0";
private static final String ALL_GROUPS = "SELECT groupID FROM jiveGroup";
public Group createGroup(String name)
throws UnauthorizedException, GroupAlreadyExistsException {
public Group createGroup(String name) throws UnauthorizedException,
GroupAlreadyExistsException
{
long now = System.currentTimeMillis();
Date nowDate = new Date(now);
long id = SequenceManager.nextID(JiveConstants.GROUP);
......@@ -47,7 +92,6 @@ public class DbGroupProvider implements GroupProvider {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(INSERT_GROUP);
......@@ -63,22 +107,10 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
if (group == null) {
throw new GroupAlreadyExistsException(name);
......@@ -86,12 +118,6 @@ public class DbGroupProvider implements GroupProvider {
return group;
}
private static final String LOAD_PROPERTIES =
"SELECT name, propValue FROM jiveGroupProp WHERE groupID=?";
private static final String LOAD_GROUP_BY_ID =
"SELECT name, description, groupID, creationDate, modificationDate " +
"FROM jiveGroup WHERE groupID=?";
public Group getGroup(long groupID) throws GroupNotFoundException {
Connection con = null;
PreparedStatement pstmt = null;
......@@ -116,7 +142,6 @@ public class DbGroupProvider implements GroupProvider {
group.setProperty(rs.getString(1), rs.getString(2));
}
}
}
catch (SQLException e) {
Log.error(e);
......@@ -133,22 +158,10 @@ public class DbGroupProvider implements GroupProvider {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
if (group == null) {
throw new GroupNotFoundException("Group with ID "
......@@ -157,12 +170,7 @@ public class DbGroupProvider implements GroupProvider {
return group;
}
private static final String SELECT_GROUP_BY_NAME =
"SELECT name, description, groupID, creationDate, modificationDate " +
"FROM jiveGroup WHERE name=?";
public Group getGroup(String name) throws GroupNotFoundException {
long id = 0;
Connection con = null;
PreparedStatement pstmt = null;
Group group = null;
......@@ -172,9 +180,7 @@ public class DbGroupProvider implements GroupProvider {
pstmt.setString(1, name);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
group = new GroupImpl(rs.getLong(3),
rs.getString(1),
rs.getString(2),
group = new GroupImpl(rs.getLong(3), rs.getString(1), rs.getString(2),
new java.util.Date(Long.parseLong(rs.getString(4).trim())),
new java.util.Date(Long.parseLong(rs.getString(5).trim())));
// Load any extended properties.
......@@ -194,22 +200,10 @@ public class DbGroupProvider implements GroupProvider {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
if (group == null) {
throw new GroupNotFoundException("Group with name "
......@@ -218,12 +212,7 @@ public class DbGroupProvider implements GroupProvider {
return group;
}
private static final String SAVE_GROUP =
"UPDATE jiveGroup SET name=?, description=?, creationDate=?, modificationDate=? "
+ "WHERE groupID=?";
public void updateGroup(Group group)
throws UnauthorizedException, GroupNotFoundException {
public void updateGroup(Group group) throws UnauthorizedException, GroupNotFoundException {
group.setModificationDate(new Date());
Connection con = null;
PreparedStatement pstmt = null;
......@@ -243,29 +232,12 @@ public class DbGroupProvider implements GroupProvider {
throw new GroupNotFoundException();
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
}
private static final String DELETE_GROUP_USERS =
"DELETE FROM jiveGroupUser WHERE groupID=?";
private static final String DELETE_GROUP =
"DELETE FROM jiveGroup WHERE groupID=?";
public void deleteGroup(long groupID) throws UnauthorizedException {
Connection con = null;
......@@ -290,22 +262,14 @@ public class DbGroupProvider implements GroupProvider {
abortTransaction = true;
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
DbConnectionManager.closeTransactionConnection(con, abortTransaction);
}
// Removing a group can change the permissions of all the users in that
// group. Therefore, expire permissions cache.
}
private static final String GROUP_COUNT = "SELECT count(*) FROM jiveGroup";
public int getGroupCount() {
int count = 0;
Connection con = null;
......@@ -323,28 +287,14 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return count;
}
private static final String ALL_GROUPS = "SELECT groupID FROM jiveGroup";
public LongList getGroups() {
LongList groups = new LongList();
Connection con = null;
......@@ -362,22 +312,10 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return groups;
}
......@@ -411,34 +349,18 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return groups;
}
private static final String USER_GROUPS =
"SELECT groupID FROM jiveGroupUser WHERE userID=? AND administrator=0";
public LongList getGroups(long entityID) {
Connection con = null;
PreparedStatement pstmt = null;
LongList groups = new LongList();
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(USER_GROUPS);
......@@ -452,29 +374,14 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return groups;
}
private static final String ADD_USER =
"INSERT INTO jiveGroupUser (groupID, userID, administrator) VALUES (?, ?, ?)";
public void createMember(long groupID, long entityID, boolean administrator)
throws UserAlreadyExistsException {
Connection con = null;
......@@ -493,27 +400,12 @@ public class DbGroupProvider implements GroupProvider {
throw new UserAlreadyExistsException(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
catch (Exception e) {
Log.error(e);
}
}
}
private static final String UPDATE_USER =
"UPDATE jiveGroupUser SET administrator=? WHERE groupID=? userID=?";
public void updateMember(long groupID, long entityID, boolean administrator) {
Connection con = null;
......@@ -531,28 +423,13 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
private static final String REMOVE_USER =
"DELETE FROM jiveGroupUser WHERE groupID=? AND userID=?";
public void deleteMember(long groupID, long entityID) {
Connection con = null;
PreparedStatement pstmt = null;
......@@ -568,30 +445,13 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
private static final String GROUP_MEMBER_COUNT =
"SELECT count(*) FROM jiveGroupUser WHERE administrator =0";
private static final String GROUP_ADMIN_COUNT =
"SELECT count(*) FROM jiveGroupUser WHERE administrator =1";
public int getMemberCount(long groupID, boolean adminsOnly) {
int count = 0;
Connection con = null;
......@@ -614,31 +474,14 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return count;
}
private static final String LOAD_ADMINS =
"SELECT userID FROM jiveGroupUser WHERE administrator=1 AND groupID=?";
private static final String LOAD_MEMBERS =
"SELECT userID FROM jiveGroupUser WHERE administrator=0 AND groupID=?";
public LongList getMembers(long groupID, boolean adminsOnly) {
Connection con = null;
PreparedStatement pstmt = null;
......@@ -661,30 +504,15 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return members;
}
public LongList getMembers(long groupID,
BasicResultFilter filter,
boolean adminsOnly) {
public LongList getMembers(long groupID, BasicResultFilter filter, boolean adminsOnly) {
Connection con = null;
PreparedStatement pstmt = null;
LongList members = new LongList();
......@@ -718,35 +546,14 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return members;
}
private static final String MEMBER_TEST =
"SELECT userID FROM jiveGroupUser " +
"WHERE groupID=? AND userID=? AND administrator=0";
private static final String ADMIN_TEST =
"SELECT userID FROM jiveGroupUser " +
"WHERE groupID=? AND userID=? AND administrator=1";
public boolean isMember(long groupID, long entityID, boolean adminsOnly) {
boolean member = false;
Connection con = null;
......@@ -770,29 +577,14 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return member;
}
private static final String INSERT_PROPERTY =
"INSERT INTO jiveGroupProp (groupID, name, propValue) VALUES (?, ?, ?)";
public void createProperty(long groupID, String name, String value) {
Connection con = null;
PreparedStatement pstmt = null;
......@@ -809,28 +601,13 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
private static final String UPDATE_PROPERTY =
"UPDATE jiveGroupProp SET propValue=? WHERE name=? AND groupID=?";
public void updateProperty(long groupID, String name, String value) {
Connection con = null;
PreparedStatement pstmt = null;
......@@ -847,28 +624,13 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
private static final String DELETE_PROPERTY =
"DELETE FROM jiveGroupProp WHERE groupID=? AND name=?";
public void deleteProperty(long groupID, String name) {
Connection con = null;
PreparedStatement pstmt = null;
......@@ -884,22 +646,10 @@ public class DbGroupProvider implements GroupProvider {
Log.error(e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
}
\ No newline at end of file
......@@ -15,8 +15,8 @@ import org.jivesoftware.messenger.auth.AuthProvider;
import org.jivesoftware.messenger.auth.UnauthorizedException;
/**
* <p>Implementation of auth provider interface for LDAP
* authentication service plug-in.</p>
* Implementation of auth provider interface for LDAP
* authentication service plug-in.
*
* @author Jim Berrettini
*/
......
......@@ -29,15 +29,16 @@ import javax.naming.NamingEnumeration;
import javax.naming.directory.*;
/**
* <p>LDAP implementation of the UserInfoProvider interface.</p>
* <p>The LdapUserIDProvider can operate in two modes -- in the pure LDAP mode, all user data is stored in the LDAP
* store. This mode generally requires modifications to the LDAP schema to accommodate data that Messenger needs.</p>
* <p>In the mixed mode, data that Messenger needs is stored locally.</p>
* LDAP implementation of the UserInfoProvider interface. The LdapUserIDProvider
* can operate in two modes -- in the pure LDAP mode, all user data is stored in
* the LDAP store. This mode generally requires modifications to the LDAP schema
* to accommodate data that Messenger needs. In the mixed mode, data that Messenger
* needs is stored locally.
*
* @author Jim Berrettini
*/
public class LdapUserInfoProvider implements UserInfoProvider {
private LdapManager manager;
private static final String LOAD_USER_BY_ID =
"SELECT name, nameVisible, email, emailVisible, " +
"creationDate, modificationDate FROM jiveUser WHERE userID=?";
......@@ -50,6 +51,8 @@ public class LdapUserInfoProvider implements UserInfoProvider {
"emailVisible=?, creationDate=?, modificationDate=? WHERE " +
"userID=?";
private LdapManager manager;
/**
* Constructor initializes the internal LdapManager instance.
*/
......@@ -112,22 +115,10 @@ public class LdapUserInfoProvider implements UserInfoProvider {
throw new UnauthorizedException();
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
......@@ -242,22 +233,10 @@ public class LdapUserInfoProvider implements UserInfoProvider {
+ id + " could not be loaded from the database.");
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return userInfo;
}
......@@ -273,7 +252,6 @@ public class LdapUserInfoProvider implements UserInfoProvider {
PreparedStatement pstmt = null;
Date now = new Date();
try {
// Add the user record in jiveUser
pstmt = con.prepareStatement(INSERT_USER);
pstmt.setLong(1, id);
......@@ -290,22 +268,10 @@ public class LdapUserInfoProvider implements UserInfoProvider {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return new BasicUserInfo(id,
"", // name
......
......@@ -10,16 +10,12 @@
*/
package org.jivesoftware.messenger.spi;
import org.jivesoftware.util.Cache;
import org.jivesoftware.util.CacheFactory;
import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.container.TrackInfo;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.Cache;
import org.jivesoftware.util.*;
import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.chatbot.ChatbotManager;
......@@ -73,10 +69,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// create caches - no size limit and never expire for presence caches
long HOUR = JiveConstants.HOUR;
onlineGuestCache = CacheFactory.createCache("Online Guests", -1, -1);
onlineUserCache = CacheFactory.createCache("Online Users", -1, -1);
foreignUserCache = CacheFactory.createCache("Foreign Users",
foreignCacheSize, HOUR);
onlineGuestCache = new DefaultCache("Online Guests", -1, -1);
onlineUserCache = new DefaultCache("Online Users", -1, -1);
foreignUserCache = new DefaultCache("Foreign Users", foreignCacheSize, HOUR);
}
public boolean isAvailable(User user) throws UnauthorizedException {
......
......@@ -10,9 +10,6 @@
*/
package org.jivesoftware.util;
import org.jivesoftware.util.*;
import org.jivesoftware.util.LinkedList;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
......@@ -27,14 +24,15 @@ import java.util.*;
* they were originally added to cache. When objects are added to cache, they
* are first wrapped by a CacheObject which maintains the following pieces
* of information:<ul>
*
* <li> The size of the object (in bytes).
* <li> A pointer to the node in the linked list that maintains accessed
* order for the object. Keeping a reference to the node lets us avoid
* linear scans of the linked list.
* <li> A pointer to the node in the linked list that maintains the age
* of the object in cache. Keeping a reference to the node lets us avoid
* linear scans of the linked list.</ul>
* <p/>
* linear scans of the linked list.</ul><p>
*
* To get an object from cache, a hash lookup is performed to get a reference
* to the CacheObject that wraps the real object we are looking for.
* The object is subsequently moved to the front of the accessed linked list
......@@ -81,7 +79,7 @@ public class DefaultCache implements Cache {
* Maintain the number of cache hits and misses. A cache hit occurs every
* time the get method is called and the cache contains the requested
* object. A cache miss represents the opposite occurence.<p>
* <p/>
*
* Keeping track of cache hits and misses lets one measure how efficient
* the cache is; the higher the percentage of hits, the more efficient.
*/
......@@ -102,12 +100,12 @@ public class DefaultCache implements Cache {
* @param maxLifetime the maximum amount of time objects can exist in
* cache before being deleted. -1 means objects never expire.
*/
protected DefaultCache(String name, int maxSize, long maxLifetime) {
public DefaultCache(String name, int maxSize, long maxLifetime) {
this.name = name;
this.maxCacheSize = maxSize;
this.maxLifetime = maxLifetime;
// Our primary data structure is a hash map. The default capacity of 11
// Our primary data structure is a HashMap. The default capacity of 11
// is too small in almost all cases, so we set it bigger.
map = new HashMap(103);
......@@ -328,16 +326,6 @@ public class DefaultCache implements Cache {
if (object instanceof Cacheable) {
return ((Cacheable)object).getCachedSize();
}
// Coherence puts DataInputStream objects in cache.
else if (object instanceof DataInputStream) {
int size = 1;
try {
size = ((DataInputStream)object).available();
}
catch (IOException ioe) {
}
return size;
}
// Check for other common types of objects put into cache.
else if (object instanceof Long) {
return CacheSizes.sizeOfLong();
......@@ -392,7 +380,7 @@ public class DefaultCache implements Cache {
// Determine the expireTime, which is the moment in time that elements
// should expire from cache. Then, we can do an easy to check to see
// if the expire time is greater than the expire time.
long expireTime = CacheFactory.currentTime - maxLifetime;
long expireTime = System.currentTimeMillis() - maxLifetime;
while (expireTime > node.timestamp) {
// Remove the object
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment