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

📄 tb_feedbackdaoimpl.java

📁 一个完整的代码管理系统的源代码
💻 JAVA
字号:
/*
 * Copyright (c) 2008-2010 Tanming1003 Inc.
 * All rights reserved.
 * 
 * tanming1003<tanming1003@163.com>
 * 
 * 
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions 
 * are met:
 * 
 * Redistributions of source code must retain the above copyright 
 * notice, this list of conditions and the following disclaimer. 
 * Redistributions in binary form must reproduce the above copyright 
 * notice, this list of conditions and the following disclaimer in the 
 * documentation and/or other materials provided with the distribution. 
 * Neither the name of tanming1003 nor the names of its contributors 
 * may be used to endorse or promote products derived from this 
 * software without specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 */
package hunnu.edu.cn.product.common.db.dao.implement;

import hunnu.edu.cn.product.common.db.DBProcess;
import hunnu.edu.cn.product.common.db.DBUtil;
import hunnu.edu.cn.product.common.db.DBWrapper;
import hunnu.edu.cn.product.common.db.dao.TB_FEEDBACKDao;
import hunnu.edu.cn.product.common.db.model.TB_FEEDBACK;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import oracle.jdbc.OracleResultSet;
import oracle.sql.CLOB;

/**
 * @author tanming1003@163.com
 * @date 2008-10-16
 * @time 下午12:44:18
 * @project_name Product
 * @package_name hunnu.edu.cn.product.common.db.dao.implement
 * @file_name    TB_FEEDBACKDaoImpl.java
 * @version      1.0
 */
public class TB_FEEDBACKDaoImpl implements TB_FEEDBACKDao
{
	
	protected TB_FEEDBACKDaoImpl()
	{
		super();
	}
	
	@SuppressWarnings("deprecation")
	public boolean add(TB_FEEDBACK feedback)
	{
		DBProcess process=new DBWrapper();
		Connection connection=null;
		try
		{
			connection=process.getConnection();
			PreparedStatement statement;
            String insertSql="insert into TB_FEEDBACK values(?,?,?,?,?,?,?,?)";
            statement=connection.prepareStatement(insertSql);
            connection.setAutoCommit(false);
            statement.setBigDecimal(1,feedback.getPro_id());
            statement.setBigDecimal(2,feedback.getFeedback_id());
            statement.setBigDecimal(3,feedback.getUser_id());
            statement.setBigDecimal(4,feedback.getFeedback_level());
            statement.setClob(5, oracle.sql.CLOB.getEmptyCLOB());
            statement.setTimestamp(6, feedback.getFeedback_ymdhms().timestampValue());
            statement.setBigDecimal(7, feedback.getUpd_user_id());
            statement.setTimestamp(8,feedback.getUpd_ymdhms().timestampValue());
            statement.executeUpdate();
            String querySql="select feedback_content from TB_FEEDBACK where pro_id="+feedback.getPro_id()+" and feedback_id="+feedback.getFeedback_id()+" for update";
            statement=connection.prepareStatement(querySql);
            ResultSet resultSet=statement.executeQuery();
            if(resultSet.next())
            {
            	CLOB clob = ((OracleResultSet)resultSet).getCLOB(1);
            	clob.putString(1,feedback.getFeedback_content());
            	String sql="update TB_FEEDBACK set feedback_content=? where pro_id="+feedback.getPro_id()+" feedback_id="+feedback.getFeedback_id();
            	statement=connection.prepareStatement(sql);
            	statement.setClob(1, clob);
            	statement.executeUpdate();
            }
            connection.commit();
            statement.close();
            return true;
		}
		catch(SQLException e)
		{
			e.printStackTrace();
			return false;
		}
		finally
		{
			try
			{
				if(connection!=null)
				   process.closeConnection(connection);
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}
	}

	public List<TB_FEEDBACK> getAll()
	{
		DBProcess process=new DBWrapper();
		Connection connection=null;
		String sql="select pro_id,feedback_id from TB_FEEDBACK";
		List<TB_FEEDBACK> result=new ArrayList<TB_FEEDBACK>();
		try
		{
			connection=process.getConnection();
			PreparedStatement statement=connection.prepareStatement(sql);
			ResultSet rs=statement.executeQuery();
			while(rs.next())
			{
				TB_FEEDBACK feedback=getByID(rs.getInt(1),rs.getInt(2));
				result.add(feedback);
			}
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
	
		return result;
	}

	public TB_FEEDBACK getByID(int product_id, int feedback_id)
	{
		DBProcess process=new DBWrapper();
		Connection connection=null;
		String sql="select * from TB_FEEDBACK where pro_id=? and feedback_id=?";
		try
		{
			connection=process.getConnection();
			PreparedStatement statement=connection.prepareStatement(sql);
			statement.setInt(1, product_id);
			statement.setInt(2, feedback_id);
			ResultSet resultSet=statement.executeQuery();
			if(resultSet.next())
			{
				TB_FEEDBACK feedback=new TB_FEEDBACK();
				feedback.setPro_id(product_id);
				feedback.setFeedback_id(feedback_id);
				feedback.setUser_id(resultSet.getInt("user_id"));
				feedback.setFeedback_level(resultSet.getInt("feedback_level"));
				CLOB clob = ((OracleResultSet)resultSet).getCLOB("feedback_content");
				String feedback_content="";
				if(clob!=null)
				{
					Reader reader=clob.getCharacterStream();
					BufferedReader br=new BufferedReader(reader);
                    String s=null;
                    while((s=br.readLine())!=null)
                    	feedback_content+=s;
				}
				feedback.setFeedback_content(feedback_content);
				feedback.setFeedback_ymdhms(resultSet.getTimestamp("feedback_ymdhms"));
				feedback.setUpd_user_id(resultSet.getInt("upd_user_id"));
				feedback.setUpd_ymdhms(resultSet.getTimestamp("upd_ymdhms"));
				statement.close();
				return feedback;
			}
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				process.closeConnection(connection);
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}
		
		return null;
	}

	public boolean removes(int[] product_id, int[] feedback_id)
	{
		TB_FEEDBACK feedback[]=new TB_FEEDBACK[product_id.length];
		for(int i=0;i<feedback.length;i++)
		{
			feedback[i]=new TB_FEEDBACK();
			feedback[i].setPro_id(product_id[i]);
			feedback[i].setFeedback_id(feedback_id[i]);
		}
		return DBUtil.remove(feedback);
	}

	@SuppressWarnings("deprecation")
	public int update(TB_FEEDBACK feedback)
	{
		DBProcess process=new DBWrapper();
		Connection connection=null;
		String sql="update TB_FEEDBACK set user_id=?,feedback_level=?,feedback_content=empty_clob(),feedback_ymdhms=?,upd_user_id=?,upd_ymdhms=? where pro_id="+feedback.getPro_id()+" and feedback_id="+feedback.getFeedback_id();
		try
		{
			connection=process.getConnection();
			connection.setAutoCommit(false);
			PreparedStatement s=connection.prepareStatement(sql);
			s.setBigDecimal(3, feedback.getUser_id());
			s.setBigDecimal(4,feedback.getFeedback_level());
			s.setTimestamp(6, feedback.getFeedback_ymdhms().timestampValue());
			s.setBigDecimal(7,feedback.getUpd_user_id());
			s.setTimestamp(8,feedback.getUpd_ymdhms().timestampValue());
			int records=s.executeUpdate();
			String querySql="select feedback_content from TB_FEEDBACK where pro_id="+feedback.getPro_id()+" and feedback_id="+feedback.getFeedback_id()+" for update";
            s=connection.prepareStatement(querySql);
            ResultSet rs=s.executeQuery();
            if(rs.next())
            {
            	CLOB clob = ((OracleResultSet)rs).getCLOB(1);
            	clob.putString(1,feedback.getFeedback_content());
            	String ssql="update TB_FEEDBACK set feedback_content=? where pro_id="+feedback.getPro_id()+" and feedback_id="+feedback.getFeedback_id();
            	s=connection.prepareStatement(ssql);
            	s.setClob(1, clob);
            	s.executeUpdate();
            }
            connection.commit();
            s.close();
            return records;
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		return 0;
	}

	public boolean removeAll()
	{
		return DBUtil.removeAll(new TB_FEEDBACK());
	}

}

⌨️ 快捷键说明

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