📄 membermanager.java
字号:
/**
* Created on 2004-5-9
*
*/
package com.airinbox.member.profile;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Startable;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.thread.ThreadSafe;
import com.airinbox.component.dbpool.PoolManager;
import com.airinbox.component.cache.CacheManager;
import com.airinbox.cache.*;
import java.util.*;
import java.sql.*;
/**
* @author Frank
*
*/
public abstract class MemberManager extends AbstractLogEnabled
implements Component,Composable,Configurable,Initializable,Startable,Disposable,ThreadSafe{
public static final String ROLE = "com.airinbox.member.MemberManager";
protected static MemberManager _self = null;
protected boolean initialized = false;
protected boolean disposed = false;
protected PoolManager m_poolManager ;
protected CacheManager m_cacheManager;
protected Cache m_cache;
/**
* 返回MemberManager的一个实例
* @return memberManager实例
*/
public static MemberManager getInstance() {
return _self;
}
/**
* Pass the <code>ComponentManager</code> to the <code>composer</code>.
* The <code>Composable</code> implementation should use the specified
* <code>ComponentManager</code> to acquire the components it needs for
* execution.
*
* @param manager The <code>ComponentManager</code> which this
* <code>Composable</code> uses.
*/
public void compose( ComponentManager componentManager ) throws ComponentException
{
if(initialized || disposed)
throw new ComponentException("compose failed cause initialized or disposed");
m_poolManager = (PoolManager)componentManager.lookup(PoolManager.ROLE);
m_cacheManager = (CacheManager)componentManager.lookup(CacheManager.ROLE);
}
/**
* Pass the <code>Configuration</code> to the <code>Configurable</code>
* class. This method must always be called after the constructor
* and before any other method.
*
* @param configuration the class configurations.
*/
public void configure( Configuration configuration ) throws ConfigurationException
{
if(initialized || disposed)
throw new ConfigurationException("configure failed cause initialized or disposed");
String cachename = configuration.getChild("cache-name").getValue("member.cache");
m_cache = m_cacheManager.getCache(cachename);
if(m_cache == null) {
throw new ConfigurationException("cache ["+cachename+"] not exists.");
}
}
/**
* Initialialize the component. Initialization includes
* allocating any resources required throughout the
* components lifecycle.
*
* @exception Exception if an error occurs
*/
public void initialize() throws Exception
{
if(initialized || disposed)
throw new Exception("initialize failed cause initialized or disposed");
initialized = true;
_self = this;
}
/**
* Starts the component.
*
* @exception Exception if Component can not be started
*/
public void start() throws Exception
{
if(!initialized || disposed)
throw new Exception("start failed cause not initialized or disposed");
}
/**
* Stops the component.
*
* @exception Exception if the Component can not be Stopped.
*/
public void stop() throws Exception
{
if(!initialized || disposed)
throw new Exception("stop failed cause not initialized or disposed");
}
/**
* The dispose operation is called at the end of a components lifecycle.
* This method will be called after Startable.stop() method (if implemented
* by component). Components use this method to release and destroy any
* resources that the Component owns.
*/
public void dispose()
{
if(!initialized || disposed) return;
disposed = true;
m_cache.clear();
}
/**
* 创建一个新的会员
* @param memid 会员的ID,此属性不能为空
* @param memName 会员的名称,可为空
* @param coins 会员的初试积分
* @param rate 会员的等级
* @return 新创建的会员实例
* @throws MemberAlreadyExistException
*/
public abstract void createMember(int memid, String memName,
long coins, int rate) throws MemberAlreadyExistException;
/**
* 由已知的record id或member id来获取会员
* @param id 已知的id
* @param type id的种类
* @see com.airinbox.member.database.DbMember
* @return
*/
public abstract Member getMember(long id, int type) throws MemberNotFoundException;
/**
* 得到所有会员的数目
* @return the amount of members
*/
public abstract int getMemberAmount();
/**
* 返回所有会员的列表
* @return the entire list of members
*/
public abstract ArrayList getMembers();
/**
* 返回会员列表
* @param startpos 开始位置
* @param length 会员列表的长度
* @return the list of macthed members
*/
public abstract ArrayList getMembers(int startpos, int length);
/**
* 返回所有积分超过coins的会员总数
* @param coins 比较的积分值
* @return the amount of matched members
*/
public abstract int getUpperMemberAmount(int coins);
/**
* 返回所有积分超过coins的会员
* @param coins
* @return the list of matched members
*/
public abstract ArrayList getUpperMembers(int coins);
/**
* 返回积分超越coins的用户列表
* @param coins 用来比较的积分
* @param start 起始位置
* @param length 列表长度
* @return the list of matched members
*/
public abstract ArrayList getUpperMembers(int coins, int start, int length);
/**
* 返回所有等级为rate的会员列表
* @param rate
* @return the list of rated members
*/
public abstract ArrayList getRatedMembers(int rate);
/**
* 返回所有超过(包含)rate的会员列表
* @param rate
* @return the list of matched members
*/
public abstract ArrayList getUpRatedMembers(int rate);
public abstract Connection getConnection() throws SQLException;
public Logger logger() {
return this.getLogger();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -