📄 voicedao.java
字号:
package com.gctech.sms.voice.dao;import java.sql.* ;import java.util.ArrayList; /* author:lijz@gctech.com.cn */ public class VoiceDAO { //-----Codes below generated by dao public int insert(Connection aConnection,VoiceValueObject aVoiceValueObject) throws SQLException { String sql = " INSERT INTO VOICE A ( A.ID, A.CATALOG_ID, A.DESCRIPTION, A.COUNT, A.CREATE_DATE, A.PRICE, A.TYPE, A.NAME, A.USER_ID, A.USER_NAME ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) " ; int result = 0; PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() ); if (aVoiceValueObject.getId() == null){ prepStmt.setNull(1, Types.INTEGER); }else{ prepStmt.setInt(1, aVoiceValueObject.getId().intValue() ); } if (aVoiceValueObject.getCatalogId() == null){ prepStmt.setNull(2, Types.INTEGER); }else{ prepStmt.setInt(2, aVoiceValueObject.getCatalogId().intValue() ); } if (aVoiceValueObject.getDescription() == null){ prepStmt.setNull(3, Types.VARCHAR); }else{ prepStmt.setString(3, aVoiceValueObject.getDescription() ); } if (aVoiceValueObject.getCount() == null){ prepStmt.setNull(4, Types.INTEGER); }else{ prepStmt.setInt(4, aVoiceValueObject.getCount().intValue() ); } if (aVoiceValueObject.getCreateDate() == null){ prepStmt.setNull(5, Types.TIMESTAMP); }else{ prepStmt.setTimestamp(5, new Timestamp(aVoiceValueObject.getCreateDate().getTime()) ); } if (aVoiceValueObject.getPrice() == null){ prepStmt.setNull(6, Types.INTEGER); }else{ prepStmt.setInt(6, aVoiceValueObject.getPrice().intValue() ); } if (aVoiceValueObject.getType() == null){ prepStmt.setNull(7, Types.INTEGER); }else{ prepStmt.setInt(7, aVoiceValueObject.getType().intValue() ); } if (aVoiceValueObject.getName() == null){ prepStmt.setNull(8, Types.VARCHAR); }else{ prepStmt.setString(8, aVoiceValueObject.getName() ); } if (aVoiceValueObject.getUserId() == null){ prepStmt.setNull(9, Types.INTEGER); }else{ prepStmt.setInt(9, aVoiceValueObject.getUserId().intValue() ); } if (aVoiceValueObject.getUserName() == null){ prepStmt.setNull(10, Types.VARCHAR); }else{ prepStmt.setString(10, aVoiceValueObject.getUserName() ); } result = prepStmt.executeUpdate(); prepStmt.close(); return result ; } public int update(Connection aConnection,VoiceValueObject aVoiceValueObject) throws SQLException { StringBuffer sql = new StringBuffer(" update VOICE A set " ); if(aVoiceValueObject.getCatalogId()!=null){ if(aVoiceValueObject.getCatalogId().doubleValue() == -1.0)sql.append(" A.CATALOG_ID= null,"); else sql.append(" A.CATALOG_ID=").append(aVoiceValueObject.getCatalogId()).append(","); } if(aVoiceValueObject.getDescription()!=null&&!aVoiceValueObject.getDescription().equals("")){ if(aVoiceValueObject.getDescription().equals("@_@"))sql.append( " A.DESCRIPTION= null,"); else sql.append(" A.DESCRIPTION='"+aVoiceValueObject.getDescription()+"',"); } if(aVoiceValueObject.getCount()!=null){ if(aVoiceValueObject.getCount().doubleValue() == -1.0)sql.append(" A.COUNT= null,"); else sql.append(" A.COUNT=").append(aVoiceValueObject.getCount()).append(","); } if(aVoiceValueObject.getCreateDate()!=null){ if(aVoiceValueObject.getCreateDate().getTime()!=0) sql.append(" A.CREATE_DATE=to_date('"+(aVoiceValueObject.getCreateDate().getYear()+1900)+"/"+(aVoiceValueObject.getCreateDate().getMonth()+1)+"/"+aVoiceValueObject.getCreateDate().getDate()+"/"+aVoiceValueObject.getCreateDate().getHours()+"/"+aVoiceValueObject.getCreateDate().getMinutes()+"/"+aVoiceValueObject.getCreateDate().getSeconds()+"','YYYY/MM/DD/HH24/MI/SS'),"); else sql.append(" A.CREATE_DATE=null,"); } if(aVoiceValueObject.getPrice()!=null){ if(aVoiceValueObject.getPrice().doubleValue() == -1.0)sql.append(" A.PRICE= null,"); else sql.append(" A.PRICE=").append(aVoiceValueObject.getPrice()).append(","); } if(aVoiceValueObject.getType()!=null){ if(aVoiceValueObject.getType().doubleValue() == -1.0)sql.append(" A.TYPE= null,"); else sql.append(" A.TYPE=").append(aVoiceValueObject.getType()).append(","); } if(aVoiceValueObject.getName()!=null&&!aVoiceValueObject.getName().equals("")){ if(aVoiceValueObject.getName().equals("@_@"))sql.append( " A.NAME= null,"); else sql.append(" A.NAME='"+aVoiceValueObject.getName()+"',"); } if(aVoiceValueObject.getUserId()!=null){ if(aVoiceValueObject.getUserId().doubleValue() == -1.0)sql.append(" A.USER_ID= null,"); else sql.append(" A.USER_ID=").append(aVoiceValueObject.getUserId()).append(","); } if(aVoiceValueObject.getUserName()!=null&&!aVoiceValueObject.getUserName().equals("")){ if(aVoiceValueObject.getUserName().equals("@_@"))sql.append( " A.USER_NAME= null,"); else sql.append(" A.USER_NAME='"+aVoiceValueObject.getUserName()+"',"); } //remove the last comma sql.setLength(sql.length()-1); sql .append( " where 1=1"); if(aVoiceValueObject.getId()!=null){ sql.append(" and A.ID=").append(aVoiceValueObject.getId()); } int result = 0; PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() ); result = prepStmt.executeUpdate(); prepStmt.close(); return result ; } public int updateByQueryValue(Connection aConnection,VoiceValueObject aVoiceValueObject,VoiceQueryValue aVoiceQueryValue) throws SQLException { StringBuffer sql = new StringBuffer(" update VOICE A set " ); if(aVoiceValueObject.getCatalogId()!=null){ if(aVoiceValueObject.getCatalogId().doubleValue() == -1.0)sql.append(" A.CATALOG_ID= null,"); else sql.append(" A.CATALOG_ID=").append(aVoiceValueObject.getCatalogId()).append(","); } if(aVoiceValueObject.getDescription()!=null&&!aVoiceValueObject.getDescription().equals("")){ if(aVoiceValueObject.getDescription().equals("@_@"))sql.append( " A.DESCRIPTION= null,"); else sql.append(" A.DESCRIPTION='"+aVoiceValueObject.getDescription()+"',"); } if(aVoiceValueObject.getCount()!=null){ if(aVoiceValueObject.getCount().doubleValue() == -1.0)sql.append(" A.COUNT= null,"); else sql.append(" A.COUNT=").append(aVoiceValueObject.getCount()).append(","); } if(aVoiceValueObject.getCreateDate()!=null){ if(aVoiceValueObject.getCreateDate().getTime()!=0) sql.append(" A.CREATE_DATE=to_date('"+(aVoiceValueObject.getCreateDate().getYear()+1900)+"/"+(aVoiceValueObject.getCreateDate().getMonth()+1)+"/"+aVoiceValueObject.getCreateDate().getDate()+"/"+aVoiceValueObject.getCreateDate().getHours()+"/"+aVoiceValueObject.getCreateDate().getMinutes()+"/"+aVoiceValueObject.getCreateDate().getSeconds()+"','YYYY/MM/DD/HH24/MI/SS'),"); else sql.append(" A.CREATE_DATE=null,"); } if(aVoiceValueObject.getPrice()!=null){ if(aVoiceValueObject.getPrice().doubleValue() == -1.0)sql.append(" A.PRICE= null,"); else sql.append(" A.PRICE=").append(aVoiceValueObject.getPrice()).append(","); } if(aVoiceValueObject.getType()!=null){ if(aVoiceValueObject.getType().doubleValue() == -1.0)sql.append(" A.TYPE= null,"); else sql.append(" A.TYPE=").append(aVoiceValueObject.getType()).append(","); } if(aVoiceValueObject.getName()!=null&&!aVoiceValueObject.getName().equals("")){ if(aVoiceValueObject.getName().equals("@_@"))sql.append( " A.NAME= null,"); else sql.append(" A.NAME='"+aVoiceValueObject.getName()+"',"); } if(aVoiceValueObject.getUserId()!=null){ if(aVoiceValueObject.getUserId().doubleValue() == -1.0)sql.append(" A.USER_ID= null,"); else sql.append(" A.USER_ID=").append(aVoiceValueObject.getUserId()).append(","); } if(aVoiceValueObject.getUserName()!=null&&!aVoiceValueObject.getUserName().equals("")){ if(aVoiceValueObject.getUserName().equals("@_@"))sql.append( " A.USER_NAME= null,"); else sql.append(" A.USER_NAME='"+aVoiceValueObject.getUserName()+"',"); } //remove the last comma sql.setLength(sql.length()-1); sql .append( " where 1=1"); String condition = aVoiceQueryValue.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,VoiceValueObject aVoiceValueObject) throws SQLException { StringBuffer sql = new StringBuffer(" delete from VOICE A where 1=1"); if(aVoiceValueObject.getId()!=null){ sql.append(" and A.ID=").append(aVoiceValueObject.getId()); } if(aVoiceValueObject.getCatalogId()!=null){ sql.append(" and A.CATALOG_ID=").append(aVoiceValueObject.getCatalogId()); } if(aVoiceValueObject.getDescription()!=null&&!aVoiceValueObject.getDescription().equals("")){ sql.append(" and A.DESCRIPTION='"+aVoiceValueObject.getDescription()).append("'"); } if(aVoiceValueObject.getCount()!=null){ sql.append(" and A.COUNT=").append(aVoiceValueObject.getCount()); } if(aVoiceValueObject.getCreateDate()!=null){ sql.append(" and A.CREATE_DATE=to_date('"+(aVoiceValueObject.getCreateDate().getYear()+1900)+"/"+(aVoiceValueObject.getCreateDate().getMonth()+1)+"/"+aVoiceValueObject.getCreateDate().getDate()+"','YYYY/MM/DD')"); } if(aVoiceValueObject.getPrice()!=null){ sql.append(" and A.PRICE=").append(aVoiceValueObject.getPrice()); } if(aVoiceValueObject.getType()!=null){ sql.append(" and A.TYPE=").append(aVoiceValueObject.getType()); } if(aVoiceValueObject.getName()!=null&&!aVoiceValueObject.getName().equals("")){ sql.append(" and A.NAME='"+aVoiceValueObject.getName()).append("'"); } if(aVoiceValueObject.getUserId()!=null){ sql.append(" and A.USER_ID=").append(aVoiceValueObject.getUserId()); } if(aVoiceValueObject.getUserName()!=null&&!aVoiceValueObject.getUserName().equals("")){ sql.append(" and A.USER_NAME='"+aVoiceValueObject.getUserName()).append("'"); } int result = 0; PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() ); result = prepStmt.executeUpdate(); prepStmt.close(); return result ; } public int deleteByQueryValue(Connection aConnection,VoiceQueryValue aVoiceQueryValue) throws SQLException { StringBuffer sql =new StringBuffer( " delete from VOICE A where 1=1 "); String condition = aVoiceQueryValue.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,VoiceValueObject aVoiceValueObject,int start,int end) throws SQLException { //---- variable sql be provided througth analyze the ValueObject StringBuffer sql = new StringBuffer("SELECT A.ID, A.CATALOG_ID, A.DESCRIPTION, A.COUNT, A.CREATE_DATE, A.PRICE, A.TYPE, A.NAME, A.USER_ID, A.USER_NAME FROM VOICE A WHERE 1 = 1 " ); if(aVoiceValueObject.getId()!=null){ sql.append(" and A.ID=").append(aVoiceValueObject.getId()); } if(aVoiceValueObject.getCatalogId()!=null){ sql.append(" and A.CATALOG_ID=").append(aVoiceValueObject.getCatalogId()); } if(aVoiceValueObject.getDescription()!=null&&!aVoiceValueObject.getDescription().equals("")){ sql.append(" and A.DESCRIPTION='"+aVoiceValueObject.getDescription()).append("'"); } if(aVoiceValueObject.getCount()!=null){ sql.append(" and A.COUNT=").append(aVoiceValueObject.getCount()); } if(aVoiceValueObject.getCreateDate()!=null){ sql.append(" and A.CREATE_DATE=to_date('"+(aVoiceValueObject.getCreateDate().getYear()+1900)+"/"+(aVoiceValueObject.getCreateDate().getMonth()+1)+"/"+aVoiceValueObject.getCreateDate().getDate()+"','YYYY/MM/DD')"); } if(aVoiceValueObject.getPrice()!=null){ sql.append(" and A.PRICE=").append(aVoiceValueObject.getPrice()); } if(aVoiceValueObject.getType()!=null){ sql.append(" and A.TYPE=").append(aVoiceValueObject.getType()); } if(aVoiceValueObject.getName()!=null&&!aVoiceValueObject.getName().equals("")){ sql.append(" and A.NAME='"+aVoiceValueObject.getName()).append("'"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -