⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logqueryimpl.java

📁 具备多表组合查询组件功能。通过将表字段与表间关系映射到对象关系及属性
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			Iterator iterCol = viewQueue.iterator();
			while(iterCol.hasNext())
			{
				colBean = (ResultFormat.ColBean)iterCol.next();
				colTitle = this.pojoTitle.getTitle(colBean.getPojoName(), colBean.getPojoCol());
				if (colTitle != null)
				{
					colBean.setTitle(colTitle);	
				}						
			}
		}
			
	}
	
	/**
	 * 构建初始树
	 * @return 根节点root
	 */
	public MBean initTree(MBean root)
	{
		this.logTree.setRoot(root);
		return root;
	}
	
	/**
	 * 构建初始树
	 * @return 根节点root的Pojo名称
	 */
	public void initTree(String rootName)
	{
		MBean mBean = (MBean) this.mBeanMap.get(rootName);
		this.logTree.setRoot(mBean);
	}
	
	/**
	 * 设置树中各节点的关系
	 * @param fatherPojo 父节点的Pojo对象名
	 * @param side 值为 “left”或“right” 左或右孩子节点
	 * @param childPojo 子节点的Pojo对象名
	 */
	public void setMBeanRelation(String fatherPojo,String side,String childPojo)
	{
		MBean father = (MBean)this.mBeanMap.get(fatherPojo);
		MBean child = (MBean)this.mBeanMap.get(childPojo);
		
		/********************************/
		//System.out.println("father pojoName :"+father.getPojoName());
		//System.out.println("child pojoName :"+child.getPojoName());
		/**********************************/
		if (side.equals("left"))
		{
			father.getLeftChildList().add(child);
		}
		if (side.equals("right"))
		{
			father.getRightChildList().add(child);
		}
		child.setFather(father);
		
	}
	
	/**
	 * 依据应用,重构并优化初始树
	 * @return
	 */
	private void optimizeTree()
	{
	
		if (this.logTree == null)
		{
			return;		
		}
		
		this.logTree.setReadDef(this.optimizingDef);//定义参数为newTreeDef型接口的logtree
		this.logTree.deepPostOrderTraverse();//后序遍历并改造基础logtree				
		this.refreshMBean();//刷新各MBean节点中的childNum(leftNum、rightNum)值		
		
	}
	
	/**
	 * 遍历后,刷新重置MBean节点的参数
	 */
	private void refreshMBean()
	{
		//this.device.refreshChildNum();
		Iterator iter = this.mBeanMap.values().iterator();
		MBean mBean = null;
		while (iter.hasNext())
		{
			mBean = (MBean) iter.next();
			mBean.refreshChildNum();
		}

	}
	
	/**
	 * 遍历树,生成Sql查询语句
	 * @return
	 */
	public StringBuffer createSql()
	{
		
		this.optimizeTree();
		this.readingDef.setResultFormat(new ResultFormat());//设置获取查询结果的ResuleFormat对象
		this.logTree.setReadDef(this.readingDef);//定义参数为logSqlDef型接口的logtree	
		this.logTree.deepPostOrderTraverse();//后序遍历LogTree
		this.sql =  new StringBuffer(this.readingDef.makeQuerySql());//返回Sql语句
		return this.sql;	
	}
	
	public MBeanPage assignPage()
	{
		if (this.mBeanPage == null)
		{
			return null;
		}
		int index = -1;
		ResultFormat format = null;
		
		this.mBeanPage.getQuerySqlList().add(this.sql);//设置sql语句集合
		index = this.mBeanPage.getQuerySqlList().indexOf(this.sql);
		format = this.readingDef.getResultFormat();
		this.mBeanPage.getFormatList().add(index,format);//设置选择字段集合
		
        //设置viewQueueList
			
		List viewQueue = null;
		
		//要求和format在List中的索引号保持一致。
		viewQueue = this.assignViewQueue(format);
		this.mBeanPage.getViewQueueList().add(this.mBeanPage.getFormatList().indexOf(format),viewQueue);		
		this.assignTitle();//设置viewQueueList中字段对应的标题
		
	    //设置当前页码为1	
		//this.mBeanPage.setCurPate(1);					
		return this.mBeanPage;
		
	}

	
	/**
	 * 依据查询处理,创建MBeanPage类型实例
	 * @return
	 */
/*
	public MBeanPage createPage()
	{	
       
		if(this.mBeanPage == null)
		{
			return null;
		}
			
		//设置viewQueueList
		
		Iterator iterFormat = this.mBeanPage.getFormatList().iterator();
		ResultFormat format = null;
		Map viewQueue = null;
		while (iterFormat.hasNext())
		{
			format = (ResultFormat)iterFormat.next();
			//要求和format在List中的索引号保持一致。
			viewQueue = this.assignViewQueue(format);
			this.mBeanPage.getViewQueueList().add(this.mBeanPage.getFormatList().indexOf(format),viewQueue);
			
		}
		this.assignTitle();//设置viewQueueList中字段对应的标题
		
	    //设置当前页码为1	
		//this.mBeanPage.setCurPate(1);					
		return this.mBeanPage;
	}
*/
	
	/**
	 * 依据显示顺序showQueue,输出查询到的字段集合。
	 * @param obj
	 * @param format
	 * @return 属性值数组。
	 */
	public Object[] getDataByShowQueue(Object[] obj,ResultFormat format)
	{
		
		ResultFormat.ColBean showColBean = null;
		ResultFormat.ColBean forColBean = null;
		
		
		int queueSize = this.showQueue.size();
			
		
		Object[] showObj = new Object[queueSize];
		int forColSize = 0;
		int iShow = 0;
		int iFor = 0;
			
		for (iShow=0;iShow<queueSize;iShow++)
		{
			showObj[iShow] = null;
			showColBean = (ResultFormat.ColBean)this.showQueue.get(iShow);
			forColSize = format.getColList().size();
			
			for (iFor=0;iFor<forColSize;iFor++)
			{
				forColBean = (ResultFormat.ColBean) format.getCol(iFor);
				if (forColBean.getPojoName().equals(showColBean.getPojoName()) && forColBean.getPojoCol().equals(showColBean.getPojoCol()))
				{
					showObj[iShow] = obj[iFor];
					/**************************************************/
				/*
					System.out.println("************* test 2 *");
					System.out.println("ShowQueue size is :"+queueSize);
					System.out.println("forColList size is :"+forColSize);
					System.out.println("***********************init data is :");
					System.out.println(obj[iFor].toString());
					System.out.println("********************** new  data is :");
					System.out.println(showObj[iShow].toString());
					System.exit(0);
				*/
					/************************************************/
					break;
				}
			}	
		}
			
		return showObj;
	}
	
	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception 
	{
		// TODO Auto-generated method stub
        //TestLogTreeImpl logTreeImpl = new TestLogTreeImpl("select");//日志查询用后序遍历LogTree
		LogQueryImpl query = new LogQueryImpl();
		/*************************************************************/
	/*
		Pojo auditInfo = null;
		Pojo winLog = null;
		query.assignMBean("auditInfo", "AUDITINFO", auditInfo);
		query.createPkm("auditInfo", "id");
		query.createOrmMap("auditInfo", "id", "AUDITINFO.ID");
		query.setQueryCondition("auditInfo", "id", "=", 123456);
		query.assignSelectCol("auditInfo","id");
		
		query.assignMBean("winLog", "WINLOG", winLog);
		query.createPkm("winLog", "id");
		query.createOrmMap("winLog", "id", "WINLOG.ID");
		query.createOrmMap("winLog", "auditId", "WINLOG.AUDITID");
		query.createFkmMap("winLog", "auditId", "auditInfo", "id");	
		query.assignSelectCol("winLog", "id");
		query.assignSelectCol("winLog", "auditId");
		query.assignShowQueue("winLog", "id");
		
		query.setMBeanRelation("auditInfo", "right", "winLog");
		
		query.initTree("auditInfo");
		
		StringBuffer sql = query.createSql();
		MBeanPage page = query.createPage(); 
	*/
		/************************************************************/
		
		Main main = new Main();
		LogType logType = new LogType();
		Application application = new Application();
		OpType opType = new OpType();
		Operation operation = new Operation();
		Windows windows = new Windows();
		
		//定义MBean
		query.assignMBean("main", "MAIN", main);
		query.assignMBean("logType", "LOGTYPE", logType);
		query.assignMBean("application", "APPLICATION", application);
		query.assignMBean("opType", "OPTYPE", opType);
		query.assignMBean("operation", "OPERATION", operation);
		query.assignMBean("windows", "WINDOWS", windows);
		
		//定义树中节点的父子关系
		query.setMBeanRelation("main", "left", "logType");
		query.setMBeanRelation("main", "right", "application");
		query.setMBeanRelation("main", "right", "windows");
		query.setMBeanRelation("application", "left", "opType");
		query.setMBeanRelation("application", "right", "operation");
		
		//建立节点树
		query.initTree("main");
		
		
		//设置主键属性
		query.createPkm("main", "id");
		query.createPkm("logType", "id");
		query.createPkm("application", "id");
		query.createPkm("opType", "id");
		query.createPkm("operation", "id");
		query.createPkm("windows", "id");
		
		//设置对象-关系映射
		query.createOrmMap("main", "id", "MAIN.ID");
		query.createOrmMap("main", "logTypeNo", "MAIN.LOGTYPENO");
		
		query.createOrmMap("logType", "id", "LOGTYPE.ID");
		query.createOrmMap("logType", "descr", "LOGTYPE.DESCR");
		
		query.createOrmMap("application", "id", "APPLICATION.ID");
		query.createOrmMap("application", "mainId", "APPLICATION.MAINID");
		query.createOrmMap("application", "opNo", "APPLICATION.OPNO");
		query.createOrmMap("application", "sqls", "APPLICATION.SQLS");
		
		query.createOrmMap("opType", "id", "OPTYPE.ID");
		query.createOrmMap("opType", "descr", "OPTYPE.DESCR");
		
		query.createOrmMap("operation", "id", "OPERATION.ID");
		query.createOrmMap("operation", "appId", "OPERATION.APPID");
		query.createOrmMap("operation", "oldValue", "OPERATION.OLDVALUE");
		
		query.createOrmMap("windows", "id", "WINDOWS.ID");
		query.createOrmMap("windows", "mainId", "WINDOWS.MAINID");
		query.createOrmMap("windows", "types", "WINDOWS.TYPES");
		
		//设置外键映射
		query.createFkmMap("main", "logTypeNo", "logType", "id");
		query.createFkmMap("windows", "mainId", "main", "id");
		query.createFkmMap("application", "mainId", "main", "id");
		query.createFkmMap("application", "opNo", "opType", "id");
		query.createFkmMap("operation", "appId", "application", "id");
		
		//设置需要查询的属性字段
		query.assignSelectCol("main","id");
		query.assignSelectCol("main","logTypeNo");
		
		query.assignSelectCol("logType","id");
		query.assignSelectCol("logType","descr");
		
		query.assignSelectCol("application","id");
		query.assignSelectCol("application","mainId");
		query.assignSelectCol("application","opNo");
		query.assignSelectCol("application","sqls");
		
		query.assignSelectCol("opType","id");
		query.assignSelectCol("opType","descr");
		
		query.assignSelectCol("operation","id");
		query.assignSelectCol("operation","appId");
		query.assignSelectCol("operation","oldValue");
		
		query.assignSelectCol("windows","id");
		query.assignSelectCol("windows","mainId");
		query.assignSelectCol("windows","types");
		
		//设置页面中需要显示的属性字段
		query.assignShowQueue("main", "id");
		query.assignShowQueue("logType", "id");
		query.assignShowQueue("application", "id");
		query.assignShowQueue("operation", "id");
		query.assignShowQueue("opType", "id");
		query.assignShowQueue("windows", "id");
		
		//设置查询条件
		query.setQueryValue("main", "id", "=", 25);
		query.setQueryRelation("logType", "descr", "=", "WindowsLog");
		query.setQueryRelation("logType", "descr", "opType", "descr");
		
		//生成Sql语句
		StringBuffer sql = query.createSql();
		
		System.out.println("SQL is :"+sql.toString());
		
		//建立MBeanPage
		MBeanPage page = query.assignPage();
		page.resetPage();
		
		
		
		

	}
	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -