1aea75a169a3d8785eb0b4b4970e904ea5b2aba1.svn-base 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.chinacreator.process.dao;
  2. import java.sql.SQLException;
  3. import java.util.List;
  4. import org.springframework.cache.annotation.Cacheable;
  5. import org.springframework.stereotype.Component;
  6. import com.chinacreator.common.dao.CacheableDao;
  7. import com.chinacreator.common.support.cache.annotation.CacheName;
  8. import com.chinacreator.process.bean.AreaInfo;
  9. import com.chinacreator.process.util.DataSource;
  10. import com.frameworkset.common.poolman.PreparedDBUtil;
  11. @Component
  12. @CacheName("AreaInfo")
  13. public class CallerAreacodeDao extends CacheableDao{
  14. /**
  15. * 初始化缓存
  16. * @throws SQLException
  17. */
  18. @SuppressWarnings("unchecked")
  19. // @PostConstruct
  20. public void loadCache() throws SQLException {
  21. PreparedDBUtil pdb = new PreparedDBUtil();
  22. String sql = "select * from TB_CALLER_AREACODE ";
  23. List<AreaInfo> AreaInfos = pdb.executeSelectForList(DataSource.SDK, sql, AreaInfo.class);
  24. for(AreaInfo areaInfos : AreaInfos) {
  25. addCache("AreaInfo", areaInfos.getCallerhead(), areaInfos);
  26. }
  27. }
  28. @Cacheable(value="AreaInfo", key="#callerhead")
  29. public AreaInfo findByCallerhead(String callerhead) {
  30. System.out.println("从数据库读取数据");
  31. PreparedDBUtil pdb = new PreparedDBUtil();
  32. String sql = "select * from TB_CALLER_AREACODE where CALLERHEAD = ?";
  33. try {
  34. pdb.preparedSelect(DataSource.SDK, sql);
  35. pdb.setString(1, callerhead);
  36. return (AreaInfo) pdb.executePreparedForObject(AreaInfo.class);
  37. } catch (SQLException e) {
  38. e.printStackTrace();
  39. }
  40. return null;
  41. }
  42. }