📄 logqueryimpl.java
字号:
package cn.edu.buaa.ieguam.logmanage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import cn.edu.buaa.ieguam.logmanage.PojoTitle;
import cn.edu.buaa.ieguam.logmanage.ResultFormat;
import cn.edu.buaa.ieguam.logmanage.ResultFormat.ColBean;
import cn.edu.buaa.ieguam.logmanage.MBeanTree;
import cn.edu.buaa.ieguam.logmanage.LogTreeImpl;
import cn.edu.buaa.ieguam.logmanage.MBean;
import cn.edu.buaa.ieguam.logmanage.NewSelectTreeDef;
import cn.edu.buaa.ieguam.logmanage.LogSqlDef;
import cn.edu.buaa.ieguam.logmanage.MBeanPage;
import cn.edu.buaa.ieguam.logmanage.pojos.*;
/**
* 日志组合查询功能
* @author tongxiaodong
* Creation time:Apr 23, 2007 10:34:17 PM
*/
public class LogQueryImpl implements LogTreeImpl
{
private ReadTreeMBean optimizingDef = null;
private LogSqlDef readingDef = null;
private MBeanInfoSetting mBInfoSetting = null;
private MBeanTree logTree = null;//need user
private Map mBeanMap = null;//need user
private MBeanPage mBeanPage = null;//need user
private List showQueue = null;//need user
private PojoTitle pojoTitle = null;//need user
private StringBuffer sql = null;
public LogQueryImpl()
{
this.optimizingDef = new NewSelectTreeDef();
this.readingDef = new LogSqlDef();//设置读取树节点的实现类
this.mBInfoSetting = new MBeanInfoSetting();//查询条件设置类
this.logTree = new MBeanTree();
this.mBeanMap = new HashMap();
this.showQueue = new ArrayList();
this.mBeanPage = new MBeanPage();
this.pojoTitle = new PojoTitle();
}
public LogQueryImpl(LogSqlDef readingDef)
{
this.optimizingDef = new NewSelectTreeDef();
this.readingDef = readingDef;//设置读取树节点的实现类
this.mBInfoSetting = new MBeanInfoSetting();//查询条件设置类
this.logTree = new MBeanTree();
this.mBeanMap = new HashMap();
this.showQueue = new ArrayList();
this.mBeanPage = new MBeanPage();
this.pojoTitle = new PojoTitle();
}
public LogQueryImpl(ReadTreeMBean optimizingDef,LogSqlDef readingDef)
{
this.optimizingDef = optimizingDef;//设置树的重构实现类
this.readingDef = readingDef;//设置读取树节点的实现类
this.mBInfoSetting = new MBeanInfoSetting();//查询条件设置类
this.logTree = new MBeanTree();
this.mBeanMap = new HashMap();
this.showQueue = new ArrayList();
this.mBeanPage = new MBeanPage();
this.pojoTitle = new PojoTitle();
}
/**
* Getting and setting methods
* @return
*/
public MBeanTree getLogTree()
{
return this.logTree;
}
public void setLogTree(MBeanTree logTree)
{
this.logTree = logTree;
}
public ReadTreeMBean getOptimizingDef()
{
return this.optimizingDef;
}
public void setOptimizingDef(ReadTreeMBean optimizingDef)
{
this.optimizingDef = optimizingDef;
}
public ReadTreeMBean getReadingDef()
{
return this.readingDef;
}
public void setReadingDef(LogSqlDef readingDef)
{
this.readingDef = readingDef;
}
public Map getMBeanMap()
{
return this.mBeanMap;
}
public void setMBeanMap(Map mBeanMap)
{
this.mBeanMap = mBeanMap;
}
public PojoTitle getPojoTitle()
{
return this.pojoTitle;
}
public void setPojoTitle(PojoTitle pojoTitle)
{
this.pojoTitle = pojoTitle;
}
public MBeanPage getMBeanPage()
{
return this.mBeanPage;
}
public void setMBeanPage(MBeanPage mBeanPage)
{
this.mBeanPage = mBeanPage;
}
public List getShowQueue()
{
return this.showQueue;
}
public void setShowQueue(List showQueue)
{
this.showQueue = showQueue;
}
/**
* Implementing methods
*/
/**
* 建立Pojo对象管理映射图
* @param pojoName
* @param pojo
*/
public void assignMBean(String pojoName,String tableName,Pojo pojo)
{
MBean mBean = new MBean();
mBean.setPojo(pojo);
mBean.setPojoName(pojoName);
mBean.setTableName(tableName);
mBean.setDegree("sleep");//初始状态设置为“sleep”
this.mBeanMap.put(pojoName,mBean);
}
/**
* 创建属性名-SubBean(为属性名-表字段名-字段值的复合数据类型)的映射
*
*/
public void createOrmMap(String pojoName,String pojoCol,String tableCol)
{
MBean mBean = (MBean)this.mBeanMap.get(pojoName);
MBean.SubBean subBean = null;
//设置各属性名-表字段名-表字段值的映射,,其中tableCol表属性名设为“数据库表名+字段名”
subBean = mBean.initSubBean(pojoName,pojoCol,tableCol,null,null);
mBean.getOrmMap().put(pojoCol,subBean);
}
/**
* 创建fromMBean到destMBean的外键-表映射图
*/
public void createFkmMap(String fromMBean,String fromCol,String destMBean,String destCol)
{
MBean fromOne = (MBean)this.mBeanMap.get(fromMBean);
MBean destOne = (MBean)this.mBeanMap.get(destMBean);
fromOne.addOneFkm(fromCol, destOne, destCol);
}
/**
*
*
*/
public void createPkm(String pojoName,String pkPojoCol)
{
MBean mBean = (MBean) this.mBeanMap.get(pojoName);
mBean.setPkName(pkPojoCol);
}
/**
* 设置Pojo对象某个属性对应的查询条件,例如:Pojo对象winLog的属性ip的查询条件为 =‘127.0.0.1’
* @param pojoName
* @param pojoCol
* @param operationChar 为 "=",">","<",">=","<="
* @param value
*/
public void setQueryValue(String pojoName,String pojoCol,String logicSymbol,Object value)
{
MBean mBean = (MBean)this.mBeanMap.get(pojoName);
if (mBean == null)
{
return;
}
if (mBean != null && mBean.getDegree().equals("work") == false)
{
mBean.setDegree("work");
}
this.mBInfoSetting.settingColQuery(mBean,pojoCol,logicSymbol,value);
}
/**
* 设置Pojo对象属性到另一个Pojo对象属性的查询条件,例如 A.hostname = B.operator
* @param fromPojo
* @param fromCol
* @param logicSymbol
* @param toPojo
* @param toCol
*/
public void setQueryRelation(String fromPojo,String fromCol,String toPojo,String toCol)
{
MBean mBeanFrom = (MBean)this.mBeanMap.get(fromPojo);
MBean mBeanTo = (MBean)this.mBeanMap.get(toPojo);
if (mBeanFrom==null || mBeanTo==null)
{
return;
}
if (mBeanFrom.getDegree().equals("work") == false)
{
mBeanFrom.setDegree("work");
}
if (mBeanTo.getDegree().equals("work") == false)
{
mBeanTo.setDegree("work");
}
this.mBInfoSetting.settingColQuery(mBeanFrom,fromCol,mBeanTo,toCol);
}
/**
* 设置查询语句中Select部分要查询的字段
* @param pojoName Pojo对象名
* @param pojoCol 与字段对应的属性名
*/
public void assignSelectCol(String pojoName,String pojoCol)
{
MBean mBean = (MBean)this.mBeanMap.get(pojoName);
if (mBean == null)
{
return;
}
if (mBean.getDegree().equals("work") == false)
{
mBean.setDegree("work");
}
this.mBInfoSetting.settingColView(mBean,pojoCol);
}
/**
* 供用户调用
* 设置显示的顺序字段,List中的元素类型为ResultFormat.ColBean
* @return
*/
public void assignShowQueue(String pojoName,String pojoCol)
{
if (this.showQueue == null)
{
this.showQueue = new ArrayList();
}
ResultFormat format = new ResultFormat();
ResultFormat.ColBean showColBean = null;
showColBean = format.new ColBean();
showColBean.setPojoName(pojoName);
showColBean.setPojoCol(pojoCol);
this.showQueue.add(showColBean);
}
/**
* 根据显示队列showQueue和mBeanPage中的format,返回与该format对应的viewQueueMap
* viewQueueMap的key由format.getColList()的index决定;value是ColBean类型,且顺序与showQueue一致
* @return
*/
private List assignViewQueue(ResultFormat format)
{
List viewQueue = new ArrayList();
ResultFormat.ColBean queueColBean = null;
ResultFormat.ColBean formatColBean = null;
ResultFormat.ColBean newColBean = null;
Iterator iterQueue = null;
Iterator iterFormat = null;
boolean flag = false;
iterQueue = this.showQueue.iterator();
while(iterQueue.hasNext())
{
queueColBean = (ResultFormat.ColBean) iterQueue.next();
iterFormat = format.getColList().iterator();
while(iterFormat.hasNext())
{
formatColBean = (ResultFormat.ColBean) iterFormat.next();
if(formatColBean.getPojoName().equals(queueColBean.getPojoName()) && formatColBean.getPojoCol().equals(queueColBean.getPojoCol()))
{
viewQueue.add(queueColBean);
break;
}
}
}
return viewQueue;
}
/**
* 为相关属性字段添加标题名称,便于页面显示时,给出标题。例如“user”可命名为“用户名”
* @param pojoName
* @param pojoCol
* @param title
*/
public void addColTitle(String pojoName,String pojoCol,String title)
{
if (this.pojoTitle.getTitles().get(pojoName) == null)
{
this.pojoTitle.addPojoMap(pojoName);
}
this.pojoTitle.addTitle(pojoName, pojoCol, title);
}
/**
* 在MBeanPage的viewQueueList中设置数据库表字段名在查询结果表格中的标题名称,例如“userName”对应标题为“用户名”
* @param pageBean
*/
private void assignTitle()
{
if (this.pojoTitle==null || this.mBeanPage==null)
{
return;
}
String colTitle = null;
List viewQueue = null;
ResultFormat.ColBean colBean = null;
Iterator iterViewQueue = this.mBeanPage.getViewQueueList().iterator();
while (iterViewQueue.hasNext())
{
viewQueue = (List) iterViewQueue.next();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -