PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 0ms app.codeStats 0ms

/src/gisdcl/counties/CountyGeomDAO.java

https://bitbucket.org/iyusuf/schoolsearchgis
Java | 55 lines | 42 code | 8 blank | 5 comment | 4 complexity | 4a0425eea1d9fcb332ffba9185893d54 MD5 | raw file
 1package gisdcl.counties;
 2
 3import gisdcl.PMF;
 4import gisdcl.schools.DistrictIdToZip;
 5import gisdcl.schools.SchoolDistrictGeoprocessorsResource;
 6
 7import java.util.List;
 8import java.util.logging.Logger;
 9
10import javax.jdo.PersistenceManager;
11import javax.jdo.Query;
12
13public class CountyGeomDAO {
14	private static final Logger log = Logger.getLogger(CountyGeomDAO.class.getName());
15	
16	public CountyGeom getCountyByFips(String pFIPS) throws Exception{
17		log.info(" starting getCountyByFips method ");
18		
19		//DataStore
20		PersistenceManager pm = PMF.get().getPersistenceManager();
21		Query query = pm.newQuery(CountyGeom.class);
22	    query.setFilter("fips == pFIPS");
23	    //query.setOrdering("hireDate desc");
24	    query.declareParameters("String pFIPS");
25
26	    try {
27	        List<CountyGeom> results = (List<CountyGeom>) query.execute(pFIPS);
28	        if(results.size()==1){
29	        	CountyGeom e = results.get(0);
30	        	log.info("..................");
31                log.info("e.getCountyid()   : " + e.getCountyid());
32                log.info("e.getFips() 		: " + e.getFips());
33                log.info("e.getName()		: " + e.getName());
34                log.info("e.getGeom()		: " + e.getGeom());
35                return e;
36	        } else if (results.size()>1){
37	            log.info("More than two counties found in data base. Check database please. Counties found: "+ results.size() +" for fips: " + pFIPS);
38	            //return ("More than two counties found in data base. Check database please. Counties found: "+ results.size() +" for fips: " + pFIPS);
39	            return null;
40	        } else {
41	        	log.info("No counties found");
42	        	//return ("No counites found");
43	        	return null;
44	        }
45	    } catch (Exception e){
46	    	log.info("Exception at DAO DistrictIdToZip");
47	    	//return "Exception at DAO DistrictIdToZip";
48	    	throw e;
49	    }finally {
50	        query.closeAll();
51	        pm.close();
52	    }
53	}
54	
55}