Commit a79899d5 authored by Alex Mateescu's avatar Alex Mateescu Committed by alexm

OF-701 Added PersistableMap abstract class to make more visible the fact that...

OF-701 Added PersistableMap abstract class to make more visible the fact that group properties are actually being persisted.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13748 b35dd754-fafc-0310-a699-88a17e54d16e
parent cf8a124e
......@@ -13,6 +13,7 @@ import java.util.Set;
import org.jivesoftware.database.DbConnectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jivesoftware.util.PersistableMap;
import org.xmpp.packet.JID;
/**
......@@ -255,11 +256,11 @@ public abstract class AbstractGroupProvider implements GroupProvider {
* @param name The target group
* @return The properties for the given group
*/
public Map<String,String> loadProperties(Group group) {
public PersistableMap<String,String> loadProperties(Group group) {
// custom map implementation persists group property changes
// whenever one of the standard mutator methods are called
String name = group.getName();
DefaultGroupPropertyMap<String,String> result = new DefaultGroupPropertyMap<String,String>(group);
PersistableMap<String,String> result = new DefaultGroupPropertyMap<String,String>(group);
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
......
......@@ -14,6 +14,7 @@ import java.util.Set;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.util.Immutable;
import org.jivesoftware.util.PersistableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -29,7 +30,7 @@ import org.slf4j.LoggerFactory;
* @param <V> Property value
*/
public class DefaultGroupPropertyMap<K,V> extends HashMap<K,V> {
public class DefaultGroupPropertyMap<K,V> extends PersistableMap<K,V> {
private static final long serialVersionUID = 3128889631577167040L;
private static final Logger logger = LoggerFactory.getLogger(DefaultGroupPropertyMap.class);
......
......@@ -38,6 +38,7 @@ import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable;
import org.jivesoftware.util.cache.CannotCalculateSizeException;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.jivesoftware.util.PersistableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
......@@ -59,7 +60,7 @@ public class Group implements Cacheable, Externalizable {
private transient GroupProvider provider;
private transient GroupManager groupManager;
private transient Map<String, String> properties;
private transient PersistableMap<String, String> properties;
private String name;
private String description;
......@@ -221,7 +222,7 @@ public class Group implements Cacheable, Externalizable {
*
* @return the extended properties.
*/
public Map<String,String> getProperties() {
public PersistableMap<String,String> getProperties() {
synchronized (this) {
if (properties == null) {
properties = provider.loadProperties(this);
......@@ -321,7 +322,7 @@ public class Group implements Cacheable, Externalizable {
* Collection implementation that notifies the GroupProvider of any
* changes to the collection.
*/
private class MemberCollection extends AbstractCollection {
private class MemberCollection extends AbstractCollection<JID> {
private Collection<JID> users;
private boolean adminCollection;
......@@ -383,12 +384,11 @@ public class Group implements Cacheable, Externalizable {
}
@Override
public boolean add(Object member) {
public boolean add(JID user) {
// Do nothing if the provider is read-only.
if (provider.isReadOnly()) {
return false;
}
JID user = (JID) member;
// Find out if the user was already a group user.
boolean alreadyGroupUser;
if (adminCollection) {
......
......@@ -23,6 +23,7 @@ package org.jivesoftware.openfire.group;
import java.util.Collection;
import java.util.Map;
import org.jivesoftware.util.PersistableMap;
import org.xmpp.packet.JID;
/**
......@@ -279,6 +280,6 @@ public interface GroupProvider {
* @param group The target group
* @return The properties for the given group
*/
Map<String,String> loadProperties(Group group);
PersistableMap<String,String> loadProperties(Group group);
}
\ No newline at end of file
package org.jivesoftware.util;
import java.util.HashMap;
import java.util.Map;
/**
* This acts as a tag interface. It has no functionality, but it serves to make more clear the
* intention to pass around a special type of map.
*
* @param <K> key. see {@link Map}
* @param <V> value. see {@link Map}
*/
public abstract class PersistableMap<K, V> extends HashMap<K, V> {
private static final long serialVersionUID = 1L;
/**
* Custom method to put properties into the map, optionally without
* triggering persistence. This is used when the map is being
* initially loaded from the database.
*
* @param key The property name
* @param value The property value
* @param persist True if the changes should be persisted to the database
* @return The original value or null if the property did not exist
*/
public abstract V put(K key, V value, boolean persist);
}
\ 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