No Description

ResourceDao.java 15KB

    package com.ekexiu.portal.dao; import java.sql.Connection; import java.sql.SQLException; import java.util.List; import org.jfw.apt.orm.annotation.dao.DAO; import org.jfw.apt.orm.annotation.dao.method.From; import org.jfw.apt.orm.annotation.dao.method.OrderBy; import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith; import org.jfw.apt.orm.annotation.dao.method.operator.Insert; import org.jfw.apt.orm.annotation.dao.method.operator.SelectList; import org.jfw.apt.orm.annotation.dao.method.operator.Update; import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith; import org.jfw.apt.orm.annotation.dao.param.Set; import com.ekexiu.portal.po.Professor; import com.ekexiu.portal.po.Resource; @DAO public abstract class ResourceDao { @Insert public abstract int insert(Connection con,Resource resource) throws SQLException; @Update public abstract int update(Connection con,Resource resource) throws SQLException; @UpdateWith @From(Resource.class) public abstract int updateSubject(Connection con, String resourceId, @Set String subject) throws SQLException; @UpdateWith @From(Resource.class) public abstract int updateIndustry(Connection con, String resourceId, @Set String industry) throws SQLException; @UpdateWith @From(Resource.class) public abstract int updateDescp(Connection con, String resourceId, @Set String descp) throws SQLException; @UpdateWith @From(Resource.class) public abstract int updateHopePayMethod(Connection con, String resourceId, @Set String hopePayMethod) throws SQLException; @UpdateWith @From(Resource.class) public abstract int updateCooperationNotes(Connection con,String resourceId,@Set String cooperationNotes) throws SQLException; public com.ekexiu.portal.po.Resource query(java.sql.Connection con,java.lang.String resourceId) throws java.sql.SQLException{ int _m_1 = 1; String sql = "SELECT RESOURCE_ID,RESOURCE_NAME,RESOURCE.SUBJECT,RESOURCE.INDUSTRY,SUPPORTED_SERVICES,RESOURCE.DESCP,PROFESSOR_ID,ASCRIPTION,HOPE_PAY_METHOD,COOPERATION_NOTES,RESOURCE.CREATE_TIME,RESOURCE.MODIFY_TIME,PROFESSOR.NAME FROM RESOURCE LEFT JOIN PROFESSOR ON PROFESSOR_ID = PROFESSOR.ID WHERE RESOURCE_ID = ?"; java.sql.PreparedStatement ps = con.prepareStatement(sql); try{ ps.setString(_m_1++,resourceId); java.sql.ResultSet rs = ps.executeQuery(); try{ if(rs.next()){ com.ekexiu.portal.po.Resource _result = new com.ekexiu.portal.po.Resource(); _result.setResourceId(rs.getString(1)); _result.setResourceName(rs.getString(2)); java.lang.String _m_2 = rs.getString(3); if(rs.wasNull()){ _m_2 = null; } _result.setSubject(_m_2); java.lang.String _m_3 = rs.getString(4); if(rs.wasNull()){ _m_3 = null; } _result.setIndustry(_m_3); _result.setSupportedServices(rs.getString(5)); java.lang.String _m_4 = rs.getString(6); if(rs.wasNull()){ _m_4 = null; } _result.setDescp(_m_4); Professor professor = new Professor(); professor.setId(rs.getString(7)); _result.setAscription(rs.getString(8)); _result.setHopePayMethod(rs.getString(9)); java.lang.String _m_5 = rs.getString(10); if(rs.wasNull()){ _m_5 = null; } _result.setCooperationNotes(_m_5); _result.setCreateTime(rs.getString(11)); _result.setModifyTime(rs.getString(12)); professor.setName(rs.getString(13)); _result.setProfessor(professor); return _result; }else{ return null; } }finally{ try{rs.close();}catch(Exception _m_6){} } }finally{ try{ps.close();}catch(Exception _m_7){} } } public java.util.List<com.ekexiu.portal.po.Resource> query(java.sql.Connection con) throws java.sql.SQLException{ String sql = "SELECT RESOURCE_ID,RESOURCE_NAME,RESOURCE.SUBJECT,RESOURCE.INDUSTRY,SUPPORTED_SERVICES,RESOURCE.DESCP,PROFESSOR_ID,ASCRIPTION,HOPE_PAY_METHOD,COOPERATION_NOTES,RESOURCE.CREATE_TIME,RESOURCE.MODIFY_TIME,PROFESSOR.NAME FROM RESOURCE LEFT JOIN PROFESSOR ON PROFESSOR_ID = PROFESSOR.ID"; java.sql.PreparedStatement ps = con.prepareStatement(sql); try{ java.sql.ResultSet rs = ps.executeQuery(); try{ java.util.List<com.ekexiu.portal.po.Resource> _result = new java.util.ArrayList<com.ekexiu.portal.po.Resource>(); while(rs.next()){ com.ekexiu.portal.po.Resource _obj = new com.ekexiu.portal.po.Resource(); _obj.setResourceId(rs.getString(1)); _obj.setResourceName(rs.getString(2)); java.lang.String _m_1 = rs.getString(3); if(rs.wasNull()){ _m_1 = null; } _obj.setSubject(_m_1); java.lang.String _m_2 = rs.getString(4); if(rs.wasNull()){ _m_2 = null; } _obj.setIndustry(_m_2); _obj.setSupportedServices(rs.getString(5)); java.lang.String _m_3 = rs.getString(6); if(rs.wasNull()){ _m_3 = null; } _obj.setDescp(_m_3); Professor professor = new Professor(); professor.setId(rs.getString(7)); _obj.setAscription(rs.getString(8)); _obj.setHopePayMethod(rs.getString(9)); java.lang.String _m_4 = rs.getString(10); if(rs.wasNull()){ _m_4 = null; } _obj.setCooperationNotes(_m_4); _obj.setCreateTime(rs.getString(11)); _obj.setModifyTime(rs.getString(12)); professor.setName(rs.getString(13)); _obj.setProfessor(professor); _result.add(_obj); } return _result; }finally{ try{rs.close();}catch(Exception _m_5){} } }finally{ try{ps.close();}catch(Exception _m_6){} } } @SelectList public abstract List<Resource> queryPro(Connection con, String professorId) throws SQLException; @SelectList @OrderBy(" ORDER BY CREATE_TIME ") public abstract List<Resource> queryOrder(Connection con, String professorId) throws SQLException; @DeleteWith @From(Resource.class) public abstract int delete(Connection con, String resourceId) throws SQLException; /** * 分页查找所有资源,按资源名称排序 * @param key 查询内容(搜索框搜索内容-模糊查询) * @param subject 学术领域 * @param industry 研究方向 * @param pageSize * @param pageNo * @return * @throws java.sql.SQLException */ public org.jfw.util.PageQueryResult<com.ekexiu.portal.po.Resource> queryPage(java.sql.Connection con,java.lang.String key,java.lang.String subject,java.lang.String industry,int pageSize,int pageNo) throws java.sql.SQLException{ int _m_1 = 0; org.jfw.util.PageQueryResult<com.ekexiu.portal.po.Resource> _result = new org.jfw.util.PageQueryResult<com.ekexiu.portal.po.Resource>(); int _m_3 = 1; boolean _m_2 = null == key; boolean _m_4 = null == subject; boolean _m_5 = null == industry; StringBuilder sql = new StringBuilder(); boolean _m_7 = true; if(!_m_2){ _m_7 = false; sql.append(" WHERE RESOURCE_NAME LIKE ?"); } if(!_m_2){ if(_m_7){ _m_7 = false; sql.append(" WHERE SUPPORTED_SERVICES LIKE ?"); }else{ sql.append(" OR SUPPORTED_SERVICES LIKE ?"); } } if(!_m_2){ if(_m_7){ _m_7 = false; sql.append(" WHERE RESOURCE.DESCP LIKE ?"); }else{ sql.append(" OR RESOURCE.DESCP LIKE ?"); } } if(!_m_2){ if(_m_7){ _m_7 = false; sql.append(" WHERE COOPERATION_NOTES LIKE ?"); }else{ sql.append(" OR COOPERATION_NOTES LIKE ?"); } } if(!_m_4){ if(_m_7){ _m_7 = false; sql.append(" WHERE RESOURCE.SUBJECT = ?"); }else{ sql.append(" OR RESOURCE.SUBJECT = ?"); } } if(!_m_5){ if(_m_7){ _m_7 = false; sql.append(" WHERE RESOURCE.INDUSTRY = ?"); }else{ sql.append(" OR RESOURCE.INDUSTRY = ?"); } } StringBuilder _m_6 = sql; sql = new StringBuilder(); sql.append("SELECT COUNT(1) FROM RESOURCE"); if(_m_6.length()>0){ sql.append(_m_6); } java.sql.PreparedStatement ps = con.prepareStatement(sql.toString()); try{ if(!_m_2){ ps.setString(_m_3++,key); } if(!_m_2){ ps.setString(_m_3++,key); } if(!_m_2){ ps.setString(_m_3++,key); } if(!_m_2){ ps.setString(_m_3++,key); } if(!_m_4){ ps.setString(_m_3++,subject); } if(!_m_5){ ps.setString(_m_3++,industry); } _result.setPageSize(pageSize); java.sql.ResultSet _pageRs = ps.executeQuery(); try{ _pageRs.next(); _m_1 = _pageRs.getInt(1); }finally{ try{_pageRs.close();}catch(Exception _m_8){} } }finally{ try{ps.close();}catch(Exception _m_9){} } _result.setTotal(_m_1); if(0== _m_1){ _result.setPageNo(1); _result.setData(java.util.Collections.<com.ekexiu.portal.po.Resource>emptyList()); return _result; } _m_3 = 1; boolean _m_10 = (1 == pageNo); if(_m_10){ _result.setPageNo(1); sql = new StringBuilder(); sql.append("SELECT RESOURCE_ID,RESOURCE_NAME,RESOURCE.SUBJECT,RESOURCE.INDUSTRY,SUPPORTED_SERVICES,RESOURCE.DESCP,PROFESSOR_ID,ASCRIPTION,HOPE_PAY_METHOD,COOPERATION_NOTES,RESOURCE.CREATE_TIME,RESOURCE.MODIFY_TIME,PROFESSOR.NAME FROM RESOURCE LEFT JOIN PROFESSOR ON PROFESSOR_ID = PROFESSOR.ID"); if(_m_6.length()>0){ sql.append(_m_6); } sql.append(" ORDER BY RESOURCE_NAME"); sql.append(" LIMIT ").append(pageSize); }else{ int _m_11 = _m_1 / pageSize; if(_m_1 % pageSize != 0){ ++_m_11; } if(pageNo > _m_11){ pageNo = _m_11; } _result.setPageNo(pageNo); --pageNo; int _m_12 = (pageNo * pageSize); sql = new StringBuilder(); sql.append("SELECT RESOURCE_ID,RESOURCE_NAME,RESOURCE.SUBJECT,RESOURCE.INDUSTRY,SUPPORTED_SERVICES,RESOURCE.DESCP,PROFESSOR_ID,ASCRIPTION,HOPE_PAY_METHOD,COOPERATION_NOTES,RESOURCE.CREATE_TIME,RESOURCE.MODIFY_TIME,PROFESSOR.NAME FROM RESOURCE LEFT JOIN PROFESSOR ON PROFESSOR_ID = PROFESSOR.ID"); if(_m_6.length()>0){ sql.append(_m_6); } sql.append(" ORDER BY RESOURCE_NAME"); sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(_m_12); } ps = con.prepareStatement(sql.toString()); try{ if(!_m_2){ ps.setString(_m_3++,key); } if(!_m_2){ ps.setString(_m_3++,key); } if(!_m_2){ ps.setString(_m_3++,key); } if(!_m_2){ ps.setString(_m_3++,key); } if(!_m_4){ ps.setString(_m_3++,subject); } if(!_m_5){ ps.setString(_m_3++,industry); } java.sql.ResultSet rs = ps.executeQuery(); try{ java.util.List<com.ekexiu.portal.po.Resource> _m_13 = new java.util.ArrayList<com.ekexiu.portal.po.Resource>(); _result.setData(_m_13); int _m_14 = 0; while((_m_14<pageSize) && rs.next()){ ++_m_14; com.ekexiu.portal.po.Resource _obj = new com.ekexiu.portal.po.Resource(); _obj.setResourceId(rs.getString(1)); _obj.setResourceName(rs.getString(2)); java.lang.String _m_15 = rs.getString(3); if(rs.wasNull()){ _m_15 = null; } _obj.setSubject(_m_15); java.lang.String _m_16 = rs.getString(4); if(rs.wasNull()){ _m_16 = null; } _obj.setIndustry(_m_16); _obj.setSupportedServices(rs.getString(5)); java.lang.String _m_17 = rs.getString(6); if(rs.wasNull()){ _m_17 = null; } _obj.setDescp(_m_17); Professor professor = new Professor(); professor.setId(rs.getString(7)); _obj.setAscription(rs.getString(8)); _obj.setHopePayMethod(rs.getString(9)); java.lang.String _m_18 = rs.getString(10); if(rs.wasNull()){ _m_18 = null; } _obj.setCooperationNotes(_m_18); _obj.setCreateTime(rs.getString(11)); _obj.setModifyTime(rs.getString(12)); professor.setName(rs.getString(13)); _obj.setProfessor(professor); _m_13.add(_obj); } return _result; }finally{ try{rs.close();}catch(Exception _m_19){} } }finally{ try{ps.close();}catch(Exception _m_20){} } } }