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

📄 smallcatalogdao.java

📁 采用JAVA开发
💻 JAVA
字号:
package com.gctech.sms.voice.dao;import java.sql.* ;import java.util.ArrayList;  /* author:lijz@gctech.com.cn */  public class SmallCatalogDAO {       //-----Codes below generated by dao     public int insert(Connection aConnection,SmallCatalogValueObject aSmallCatalogValueObject) throws SQLException  {       String sql = " INSERT INTO SMALL_CATALOG A ( A.ID, A.NAME, A.BIG_ID ) VALUES ( ?, ?, ? )  " ;      int result = 0;      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      if (aSmallCatalogValueObject.getId()  == null){        prepStmt.setNull(1, Types.INTEGER);      }else{        prepStmt.setInt(1, aSmallCatalogValueObject.getId().intValue() );       }            if (aSmallCatalogValueObject.getName()  == null){        prepStmt.setNull(2, Types.VARCHAR);      }else{        prepStmt.setString(2, aSmallCatalogValueObject.getName() );       }      if (aSmallCatalogValueObject.getBigId()  == null){        prepStmt.setNull(3, Types.INTEGER);      }else{        prepStmt.setInt(3, aSmallCatalogValueObject.getBigId().intValue() );       }            result = prepStmt.executeUpdate();      prepStmt.close();      return result ;     }     public int update(Connection aConnection,SmallCatalogValueObject aSmallCatalogValueObject) throws SQLException  {       StringBuffer sql = new StringBuffer(" update SMALL_CATALOG A  set " );            if(aSmallCatalogValueObject.getName()!=null&&!aSmallCatalogValueObject.getName().equals("")){            if(aSmallCatalogValueObject.getName().equals("@_@"))sql.append( " A.NAME= null,");            else sql.append(" A.NAME='"+aSmallCatalogValueObject.getName()+"',");      }      if(aSmallCatalogValueObject.getBigId()!=null){            if(aSmallCatalogValueObject.getBigId().doubleValue() == -1.0)sql.append(" A.BIG_ID= null,");            else sql.append("  A.BIG_ID=").append(aSmallCatalogValueObject.getBigId()).append(",");      }      //remove the last comma      sql.setLength(sql.length()-1);      sql .append( " where 1=1");      if(aSmallCatalogValueObject.getId()!=null){      sql.append(" and A.ID=").append(aSmallCatalogValueObject.getId());      }      int result = 0;      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      result = prepStmt.executeUpdate();      prepStmt.close();      return result ;     }     public int updateByQueryValue(Connection aConnection,SmallCatalogValueObject aSmallCatalogValueObject,SmallCatalogQueryValue aSmallCatalogQueryValue) throws SQLException  {       StringBuffer sql = new StringBuffer(" update SMALL_CATALOG A  set " );            if(aSmallCatalogValueObject.getName()!=null&&!aSmallCatalogValueObject.getName().equals("")){            if(aSmallCatalogValueObject.getName().equals("@_@"))sql.append( " A.NAME= null,");            else sql.append(" A.NAME='"+aSmallCatalogValueObject.getName()+"',");      }      if(aSmallCatalogValueObject.getBigId()!=null){            if(aSmallCatalogValueObject.getBigId().doubleValue() == -1.0)sql.append(" A.BIG_ID= null,");            else sql.append("  A.BIG_ID=").append(aSmallCatalogValueObject.getBigId()).append(",");      }      //remove the last comma      sql.setLength(sql.length()-1);      sql .append( " where 1=1");      String condition = aSmallCatalogQueryValue.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,SmallCatalogValueObject aSmallCatalogValueObject) throws SQLException  {       StringBuffer sql = new StringBuffer(" delete  from  SMALL_CATALOG A where 1=1");      if(aSmallCatalogValueObject.getId()!=null){      sql.append(" and A.ID=").append(aSmallCatalogValueObject.getId());      }      if(aSmallCatalogValueObject.getName()!=null&&!aSmallCatalogValueObject.getName().equals("")){      sql.append(" and A.NAME='"+aSmallCatalogValueObject.getName()).append("'");      }      if(aSmallCatalogValueObject.getBigId()!=null){      sql.append(" and A.BIG_ID=").append(aSmallCatalogValueObject.getBigId());      }      int result = 0;      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      result = prepStmt.executeUpdate();      prepStmt.close();      return result ;     }     public int deleteByQueryValue(Connection aConnection,SmallCatalogQueryValue aSmallCatalogQueryValue) throws SQLException  {       StringBuffer sql =new StringBuffer( " delete  from  SMALL_CATALOG A where 1=1  ");      String condition = aSmallCatalogQueryValue.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,SmallCatalogValueObject aSmallCatalogValueObject,int start,int end) throws SQLException  {       //---- variable sql be provided througth analyze the ValueObject        StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME, A.BIG_ID FROM SMALL_CATALOG A WHERE 1 = 1 " );      if(aSmallCatalogValueObject.getId()!=null){      sql.append(" and A.ID=").append(aSmallCatalogValueObject.getId());      }      if(aSmallCatalogValueObject.getName()!=null&&!aSmallCatalogValueObject.getName().equals("")){      sql.append(" and A.NAME='"+aSmallCatalogValueObject.getName()).append("'");      }      if(aSmallCatalogValueObject.getBigId()!=null){      sql.append(" and A.BIG_ID=").append(aSmallCatalogValueObject.getBigId());      }      //-----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() ) {         SmallCatalogValueObject model = new SmallCatalogValueObject();        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());        int intBIG_ID = rs.getInt("BIG_ID");       if(!rs.wasNull()) model.setBigId(new Integer(intBIG_ID));        list.add(model);      }      rs.close();       prepStmt.close();      return list ;     }     public ArrayList supplements(Connection aConnection,SmallCatalogValueObject[] manySmallCatalogValueObject,int start,int end) throws SQLException  {       //---- variable sql be provided througth analyze the ValueObject        StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME, A.BIG_ID FROM SMALL_CATALOG A WHERE 1 = 0 " );      for(int i=0;i<manySmallCatalogValueObject.length;i++){      sql.append( " or ( 1=1 ");      if(manySmallCatalogValueObject[i].getId()!=null){      sql.append(" and A.ID=").append(manySmallCatalogValueObject[i].getId());      }      if(manySmallCatalogValueObject[i].getName()!=null&&!manySmallCatalogValueObject[i].getName().equals("")){      sql.append(" and A.NAME='"+manySmallCatalogValueObject[i].getName()).append("'");      }      if(manySmallCatalogValueObject[i].getBigId()!=null){      sql.append(" and A.BIG_ID=").append(manySmallCatalogValueObject[i].getBigId());      }      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() ) {         SmallCatalogValueObject model = new SmallCatalogValueObject();        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());        int intBIG_ID = rs.getInt("BIG_ID");       if(!rs.wasNull()) model.setBigId(new Integer(intBIG_ID));        list.add(model);      }      rs.close();       prepStmt.close();      return list ;     }     public int size(Connection aConnection,SmallCatalogQueryValue aSmallCatalogQueryValue) throws SQLException  {       StringBuffer sql = new StringBuffer("select  count(*) tsize from SMALL_CATALOG A where 1=1 " );      String condition = aSmallCatalogQueryValue.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, A.BIG_ID FROM SMALL_CATALOG A WHERE 1 = 1 " );      ResultSet rs = null;      ArrayList list = new ArrayList();      PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() );      rs = prepStmt.executeQuery();      while( rs.next() ) {         SmallCatalogValueObject model = new SmallCatalogValueObject();        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());        int intBIG_ID = rs.getInt("BIG_ID");       if(!rs.wasNull()) model.setBigId(new Integer(intBIG_ID));        list.add(model);      }      rs.close();       prepStmt.close();      return list ;     }     public ArrayList selectByQueryValue(Connection aConnection,SmallCatalogQueryValue aSmallCatalogQueryValue,int start,int end) throws SQLException  {       //---- variable sql be provided througth analyze the ValueObject        StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME, A.BIG_ID FROM SMALL_CATALOG A WHERE 1 = 1 " );      String condition = aSmallCatalogQueryValue.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() ) {         SmallCatalogValueObject model = new SmallCatalogValueObject();        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());        int intBIG_ID = rs.getInt("BIG_ID");       if(!rs.wasNull()) model.setBigId(new Integer(intBIG_ID));        list.add(model);      }      rs.close();       prepStmt.close();      return list ;     }     public SmallCatalogValueObject getByPrimaryKey(Connection aConnection,Integer id) throws SQLException  {       String sql = "select * from SMALL_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() ) {         SmallCatalogValueObject model = new SmallCatalogValueObject();      model.setId(id);        String strNAME =rs.getString("NAME");       if(!rs.wasNull()) model.setName(strNAME.trim());        int intBIG_ID = rs.getInt("BIG_ID");       if(!rs.wasNull()) model.setBigId(new Integer(intBIG_ID));        list.add(model);      }      rs.close();       prepStmt.close();      return list.size()==0?null:(SmallCatalogValueObject)list.get(0) ;     }     public void  deleteByPrimaryKey(Connection aConnection,Integer id) throws SQLException  {       String sql = "delete  from SMALL_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 + -