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