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

📄 bigcatalogdao.java

📁 采用JAVA开发
💻 JAVA
字号:
package com.gctech.sms.voice.dao;import java.sql.* ;import java.util.ArrayList;  /* author:lijz@gctech.com.cn */  public class BigCatalogDAO {       //-----Codes below generated by dao     public int insert(Connection aConnection,BigCatalogValueObject aBigCatalogValueObject) throws SQLException  {       String sql = " INSERT INTO BIG_CATALOG A ( A.ID, A.NAME ) VALUES ( ?, ? )  " ;      int result = 0;      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      if (aBigCatalogValueObject.getId()  == null){        prepStmt.setNull(1, Types.INTEGER);      }else{        prepStmt.setInt(1, aBigCatalogValueObject.getId().intValue() );       }            if (aBigCatalogValueObject.getName()  == null){        prepStmt.setNull(2, Types.VARCHAR);      }else{        prepStmt.setString(2, aBigCatalogValueObject.getName() );       }      result = prepStmt.executeUpdate();      prepStmt.close();      return result ;     }     public int update(Connection aConnection,BigCatalogValueObject aBigCatalogValueObject) throws SQLException  {       StringBuffer sql = new StringBuffer(" update BIG_CATALOG A  set " );            if(aBigCatalogValueObject.getName()!=null&&!aBigCatalogValueObject.getName().equals("")){            if(aBigCatalogValueObject.getName().equals("@_@"))sql.append( " A.NAME= null,");            else sql.append(" A.NAME='"+aBigCatalogValueObject.getName()+"',");      }      //remove the last comma      sql.setLength(sql.length()-1);      sql .append( " where 1=1");      if(aBigCatalogValueObject.getId()!=null){      sql.append(" and A.ID=").append(aBigCatalogValueObject.getId());      }      int result = 0;      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      result = prepStmt.executeUpdate();      prepStmt.close();      return result ;     }     public int updateByQueryValue(Connection aConnection,BigCatalogValueObject aBigCatalogValueObject,BigCatalogQueryValue aBigCatalogQueryValue) throws SQLException  {       StringBuffer sql = new StringBuffer(" update BIG_CATALOG A  set " );            if(aBigCatalogValueObject.getName()!=null&&!aBigCatalogValueObject.getName().equals("")){            if(aBigCatalogValueObject.getName().equals("@_@"))sql.append( " A.NAME= null,");            else sql.append(" A.NAME='"+aBigCatalogValueObject.getName()+"',");      }      //remove the last comma      sql.setLength(sql.length()-1);      sql .append( " where 1=1");      String condition = aBigCatalogQueryValue.toSql();      sql.append(condition);      int result = 0;      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      result = prepStmt.executeUpdate();      prepStmt.close();      return result ;     }     public int delete(Connection aConnection,BigCatalogValueObject aBigCatalogValueObject) throws SQLException  {       StringBuffer sql = new StringBuffer(" delete  from  BIG_CATALOG A where 1=1");      if(aBigCatalogValueObject.getId()!=null){      sql.append(" and A.ID=").append(aBigCatalogValueObject.getId());      }      if(aBigCatalogValueObject.getName()!=null&&!aBigCatalogValueObject.getName().equals("")){      sql.append(" and A.NAME='"+aBigCatalogValueObject.getName()).append("'");      }      int result = 0;      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      result = prepStmt.executeUpdate();      prepStmt.close();      return result ;     }     public int deleteByQueryValue(Connection aConnection,BigCatalogQueryValue aBigCatalogQueryValue) throws SQLException  {       StringBuffer sql =new StringBuffer( " delete  from  BIG_CATALOG A where 1=1  ");      String condition = aBigCatalogQueryValue.toSql();      sql.append(condition);      int result = 0;      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      result = prepStmt.executeUpdate();      prepStmt.close();      return result ;     }     public ArrayList supplement(Connection aConnection,BigCatalogValueObject aBigCatalogValueObject,int start,int end) throws SQLException  {       //---- variable sql be provided througth analyze the ValueObject        StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME FROM BIG_CATALOG A WHERE 1 = 1 " );      if(aBigCatalogValueObject.getId()!=null){      sql.append(" and A.ID=").append(aBigCatalogValueObject.getId());      }      if(aBigCatalogValueObject.getName()!=null&&!aBigCatalogValueObject.getName().equals("")){      sql.append(" and A.NAME='"+aBigCatalogValueObject.getName()).append("'");      }      //-----Result between variable start and variable end      if (start != -1 && end != -1){      String mainSql = sql.toString();      sql = new StringBuffer("select * from ( select a.*,rownum as tmprow from (").append(mainSql).append(") a where rownum <=").append(end).append(") where tmprow>= ").append(start);      }      ResultSet rs = null;      ArrayList list = new ArrayList();      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      rs = prepStmt.executeQuery();      while( rs.next() ) {         BigCatalogValueObject model = new BigCatalogValueObject();        int intID = rs.getInt("ID");       if(!rs.wasNull()) model.setId(new Integer(intID));        String strNAME =rs.getString("NAME");       if(!rs.wasNull()) model.setName(strNAME.trim());        list.add(model);      }      rs.close();       prepStmt.close();      return list ;     }     public ArrayList supplements(Connection aConnection,BigCatalogValueObject[] manyBigCatalogValueObject,int start,int end) throws SQLException  {       //---- variable sql be provided througth analyze the ValueObject        StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME FROM BIG_CATALOG A WHERE 1 = 0 " );      for(int i=0;i<manyBigCatalogValueObject.length;i++){      sql.append( " or ( 1=1 ");      if(manyBigCatalogValueObject[i].getId()!=null){      sql.append(" and A.ID=").append(manyBigCatalogValueObject[i].getId());      }      if(manyBigCatalogValueObject[i].getName()!=null&&!manyBigCatalogValueObject[i].getName().equals("")){      sql.append(" and A.NAME='"+manyBigCatalogValueObject[i].getName()).append("'");      }      sql.append(")");      }      //-----Result between variable start and variable end      if (start != -1 && end != -1){      String mainSql = sql.toString();      sql = new StringBuffer("select * from ( select a.*,rownum as tmprow from (").append(mainSql).append(") a where rownum <=").append(end).append(") where tmprow>= ").append(start);      }      ResultSet rs = null;      ArrayList list = new ArrayList();      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      rs = prepStmt.executeQuery();      while( rs.next() ) {         BigCatalogValueObject model = new BigCatalogValueObject();        int intID = rs.getInt("ID");       if(!rs.wasNull()) model.setId(new Integer(intID));        String strNAME =rs.getString("NAME");       if(!rs.wasNull()) model.setName(strNAME.trim());        list.add(model);      }      rs.close();       prepStmt.close();      return list ;     }     public int size(Connection aConnection,BigCatalogQueryValue aBigCatalogQueryValue) throws SQLException  {       StringBuffer sql = new StringBuffer("select  count(*) tsize from BIG_CATALOG A where 1=1 " );      String condition = aBigCatalogQueryValue.toSql();      sql.append(condition);      ResultSet rs = null;      int  size = 0;      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      rs = prepStmt.executeQuery();      if(rs.next())  size = rs.getInt(1);      rs.close();       prepStmt.close();      return size ;     }     public ArrayList all(Connection aConnection) throws SQLException  {       StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME FROM BIG_CATALOG A WHERE 1 = 1 " );      ResultSet rs = null;      ArrayList list = new ArrayList();      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      rs = prepStmt.executeQuery();      while( rs.next() ) {         BigCatalogValueObject model = new BigCatalogValueObject();        int intID = rs.getInt("ID");       if(!rs.wasNull()) model.setId(new Integer(intID));        String strNAME =rs.getString("NAME");       if(!rs.wasNull()) model.setName(strNAME.trim());        list.add(model);      }      rs.close();       prepStmt.close();      return list ;     }     public ArrayList selectByQueryValue(Connection aConnection,BigCatalogQueryValue aBigCatalogQueryValue,int start,int end) throws SQLException  {       //---- variable sql be provided througth analyze the ValueObject        StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME FROM BIG_CATALOG A WHERE 1 = 1 " );      String condition = aBigCatalogQueryValue.toSql();      sql.append(condition);      //-----Result between variable start and variable end      if (start != -1 && end != -1){      String mainSql = sql.toString();      sql = new StringBuffer("select * from ( select a.*,rownum as tmprow from (").append(mainSql).append(") a where rownum <=").append(end).append(") where tmprow>= ").append(start);      }      ResultSet rs = null;      ArrayList list = new ArrayList();      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      rs = prepStmt.executeQuery();      while( rs.next() ) {         BigCatalogValueObject model = new BigCatalogValueObject();        int intID = rs.getInt("ID");       if(!rs.wasNull()) model.setId(new Integer(intID));        String strNAME =rs.getString("NAME");       if(!rs.wasNull()) model.setName(strNAME.trim());        list.add(model);      }      rs.close();       prepStmt.close();      return list ;     }     public BigCatalogValueObject getByPrimaryKey(Connection aConnection,Integer id) throws SQLException  {       String sql = "select * from BIG_CATALOG A where 1=1  and A.ID=?";      ResultSet rs = null;      ArrayList list = new ArrayList();      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      prepStmt.setInt(1,id.intValue());      rs = prepStmt.executeQuery();      while( rs.next() ) {         BigCatalogValueObject model = new BigCatalogValueObject();      model.setId(id);        String strNAME =rs.getString("NAME");       if(!rs.wasNull()) model.setName(strNAME.trim());        list.add(model);      }      rs.close();       prepStmt.close();      return list.size()==0?null:(BigCatalogValueObject)list.get(0) ;     }     public void  deleteByPrimaryKey(Connection aConnection,Integer id) throws SQLException  {       String sql = "delete  from BIG_CATALOG where 1=1   and ID=?";      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      prepStmt.setInt(1,id.intValue());       prepStmt.executeUpdate();     }       //-----Codes above generated by dao  } 

⌨️ 快捷键说明

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