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

📄 databasenode.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
字号:
/**
 * 
 */
package flow.graph.db.bean;

import flow.graph.db.SQLiteConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 *
 */
public class DataBaseNode {
	public static List selectNodes(Connection con, int parentid) throws SQLException {
		PreparedStatement stmt = null;
		ResultSet rest = null;
		List list = new ArrayList();
		String sql = "select * from workflow where t_parentid = ? order by t_id asc;";
		//System.out.println(sql);
		//System.out.println(parentid);
		try{
			stmt = con.prepareStatement(sql);
			stmt.setInt(1, parentid);
			rest = stmt.executeQuery();
			while(rest.next()){
				NodeBean flow = new NodeBean();
				//System.out.println(rest.getString("t_desc"));
				flow.setT_id(rest.getInt("t_id"));
				flow.setT_parentid(rest.getInt("t_parentid"));
				flow.setT_name(rest.getString("t_name"));
				flow.setT_desc(rest.getString("t_desc"));
				flow.setT_program(rest.getString("t_program"));
				flow.setT_graph(rest.getString("t_graph"));
				list.add(flow);
			}
			return list;
		} catch (SQLException e){
			throw e;
		}
		finally{
			try {
				if(rest != null)
					rest.close();
				if(stmt != null)
					stmt.close();
				if(con != null)
					con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				throw e;
			}
		}
	}
	
	public static NodeBean selectNodeIdByParentid(Connection con, int parentid) {
		PreparedStatement stmt = null;
		ResultSet rest = null;
		String sql = "select * from workflow where t_parentid = ? order by t_id desc limit 0, 1";
		try{
			stmt = con.prepareStatement(sql);
			stmt.setInt(1, parentid);
			rest = stmt.executeQuery();
			if(rest.next()){
				NodeBean flow = new NodeBean();
				flow.setT_id(rest.getInt("t_id"));
				flow.setT_parentid(rest.getInt("t_parentid"));
				flow.setT_name(rest.getString("t_name"));
				flow.setT_desc(rest.getString("t_desc"));
				flow.setT_program(rest.getString("t_program"));
				flow.setT_graph(rest.getString("t_graph"));
				return flow;
			}
			return null;
		} catch (SQLException e){
			System.out.println(e.getMessage());
			return null;
		}
		finally{
			try {
				if(rest != null)
					rest.close();
				if(stmt != null)
					stmt.close();
				if(con != null)
					con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static NodeBean insertNode(Connection con, NodeBean bean) throws SQLException {
		PreparedStatement stmt = null;
		ResultSet rest = null;
		String sql = "insert into workflow(t_parentid, t_name,t_desc,t_program, t_graph) values(?, ?, ?, ?, ?)";
		try{
			stmt = con.prepareStatement(sql);
			stmt.setInt(1, bean.getT_parentid());
			stmt.setString(2, bean.getT_name());
			stmt.setString(3, bean.getT_desc());
			stmt.setString(4, bean.getT_program());
			stmt.setString(5, bean.getT_graph());
			if(stmt.executeUpdate() > 0){
				sql = "select * from workflow order by t_id desc limit 0, 1";
				stmt = con.prepareStatement(sql);
				rest = stmt.executeQuery();
				if(rest.next()){
					NodeBean node = new NodeBean();
					node.setT_id(rest.getInt("t_id"));
					node.setT_parentid(rest.getInt("t_parentid"));
					node.setT_name(rest.getString("t_name"));
					node.setT_desc(rest.getString("t_desc"));
					node.setT_program(rest.getString("t_program"));
					node.setT_graph(rest.getString("t_graph"));
					return node;
				}
				else{
					throw new SQLException("NodeBean:insertNode-->get t_id failed!");
				}
			}
			else{
				throw new SQLException("DataBaseNode:insertNode update failed!");
			}
		} catch (SQLException e){
			throw e;
		}
		finally{
			try {
				if(rest != null)
					rest.close();
				if(stmt != null)
					stmt.close();
				if(con != null)
					con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				throw e;
			}
		}
	}
	
	public static int updateNode(Connection con, NodeBean bean) throws SQLException {
		PreparedStatement stmt = null;
		ResultSet rest = null;
		String sql = "update workflow set t_name = ?, t_desc = ?, t_program = ?, t_parentid = ?, t_graph = ? where t_id = ?";
		try{
			stmt = con.prepareStatement(sql);
			stmt.setString(1, bean.getT_name());
			stmt.setString(2, bean.getT_desc());
			stmt.setString(3, bean.getT_program());
			stmt.setString(4, bean.getT_graph());
			stmt.setInt(5, bean.getT_id());
			return stmt.executeUpdate();
		} catch (SQLException e){
			throw e;
		}
		finally{
			try {
				if(rest != null)
					rest.close();
				if(stmt != null)
					stmt.close();
				if(con != null)
					con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				throw e;
			}
		}
	}
	
	public static int updateNodeName(Connection con, NodeBean bean) throws SQLException {
		PreparedStatement stmt = null;
		ResultSet rest = null;
		String sql = "update workflow set t_desc = ? where t_id = ?";
		try{
			stmt = con.prepareStatement(sql);
			stmt.setString(1, bean.getT_desc());
			stmt.setInt(2, bean.getT_id());
			return stmt.executeUpdate();
		} catch (SQLException e){
			throw e;
		}
		finally{
			try {
				if(rest != null)
					rest.close();
				if(stmt != null)
					stmt.close();
				if(con != null)
					con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				throw e;
			}
		}
	}
	
	public static int updateNodeProgram(Connection con, NodeBean bean) throws SQLException {
		PreparedStatement stmt = null;
		ResultSet rest = null;
		String sql = "update workflow set t_program = ?, t_graph = ? where t_id = ?";
		try{
			stmt = con.prepareStatement(sql);
			stmt.setString(1, bean.getT_program());
			stmt.setString(2, bean.getT_graph());
			stmt.setInt(3, bean.getT_id());
			return stmt.executeUpdate();
		} catch (SQLException e){
			throw e;
		}
		finally{
			try {
				if(rest != null)
					rest.close();
				if(stmt != null)
					stmt.close();
				if(con != null)
					con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				throw e;
			}
		}
	}
	
	public static int deleteNode(Connection con, int id) throws SQLException {
		//删除业务节点,同时删除该业务下的所有节点
		//log.info("CardList.getList;type="+type);
		PreparedStatement stmt = null;
		ResultSet rest = null;
		String sql = "delete from workflow where t_id = ?";
		try{
			stmt = con.prepareStatement(sql);
			stmt.setInt(1, id);
			return stmt.executeUpdate();
		} catch (SQLException e){
			throw e;
		}
		finally{
			try {
				if(rest != null)
					rest.close();
				if(stmt != null)
					stmt.close();
				if(con != null)
					con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				throw e;
			}
		}
	}

	public static int deleteNodeByParent(Connection con, int id) throws SQLException {
		//删除业务节点,同时删除该业务下的所有节点
		//log.info("CardList.getList;type="+type);
		PreparedStatement stmt = null;
		ResultSet rest = null;
		String sql = "delete from workflow where t_parentid = ?";
		try{
			stmt = con.prepareStatement(sql);
			stmt.setInt(1, id);
			return stmt.executeUpdate();
		} catch (SQLException e){
			throw e;
		}
		finally{
			try {
				if(rest != null)
					rest.close();
				if(stmt != null)
					stmt.close();
				if(con != null)
					con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				throw e;
			}
		}
	}
}

⌨️ 快捷键说明

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