[Trovacap-java-loginfo] jTrovaCap/java/uk/co/marcoratto/jtrovacap/hsqldb CapDAOException.java, NON
Brought to you by:
marcoratto
|
From: Marco R. <mar...@us...> - 2008-07-02 14:13:04
|
Update of /cvsroot/trovacap-java/jTrovaCap/java/uk/co/marcoratto/jtrovacap/hsqldb In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv26823/java/uk/co/marcoratto/jtrovacap/hsqldb Added Files: CapDAOException.java CapDAO.java Cap.hbm.xml Cap.java Removed Files: DbConnection.java TabCapDTO.java TabCapDAO.java Log Message: Update to release 1.2 --- DbConnection.java DELETED --- --- TabCapDAO.java DELETED --- --- NEW FILE: CapDAO.java --- /* * Copyright (C) 2007 Marco Ratto * * This file is part of the project trovacap-java. * * trovacap-java is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version. * * trovacap-java is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with trovacap-java; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package uk.co.marcoratto.jtrovacap.hsqldb; import java.sql.SQLException; import java.util.List; import org.apache.log4j.Logger; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.criterion.Order; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import uk.co.marcoratto.util.HibernateUtil; /** * This class provides methods to populate DB Table of CAP */ public class CapDAO { private Session session; private static CapDAO istance = null; private static Logger logger = Logger.getLogger("uk.co.marcoratto.jtrovacap"); private CapDAO() { } public static CapDAO getInstance() { if (istance == null) { istance = new CapDAO(); } return istance; } public int getTotal(String comune, String provincia, String toponimo, String cap) { int outValue = -1; this.session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(Cap.class); criteria.setProjection(Projections.rowCount()); if (comune != null) { criteria.add( Restrictions.or( Restrictions.like("comu", "%" + comune.toUpperCase() + "%"), Restrictions.like("fraz", "%" + comune.toUpperCase() + "%"))); } if (provincia != null) { criteria.add(Restrictions.eq("prov", provincia.toUpperCase())); } if (toponimo != null) { criteria.add(Restrictions.like("topo", "%" + toponimo.toUpperCase() + "%")); } if (cap != null) { criteria.add(Restrictions.like("capi", "%" + cap + "%")); } outValue = ((Integer) criteria.list().get(0)).intValue(); logger.debug("Total=" + outValue); session.getTransaction().commit(); return outValue; } public List<Cap> getElenco(String comune, String provincia, String toponimo, String cap) throws SQLException { this.session = HibernateUtil.getSessionFactory().getCurrentSession(); this.session.beginTransaction(); Criteria criteria = this.session.createCriteria(Cap.class); if (comune != null) { criteria.add( Restrictions.or( Restrictions.like("comu", "%" + comune.toUpperCase() + "%"), Restrictions.like("fraz", "%" + comune.toUpperCase() + "%"))); } if (provincia != null) { criteria.add(Restrictions.eq("prov", provincia.toUpperCase())); } if (toponimo != null) { criteria.add(Restrictions.like("topo", "%" + toponimo.toUpperCase() + "%")); } if (cap != null) { criteria.add(Restrictions.like("capi", "%" + cap + "%")); } List<Cap> l = (List<Cap>) criteria.list(); this.session.getTransaction().commit(); logger.debug("Total=" + l.size()); return l; } public List<String> getElencoProvince() throws CapDAOException { List<String> out; try { this.session = HibernateUtil.getSessionFactory().getCurrentSession(); this.session.beginTransaction(); Criteria criteria = this.session.createCriteria(Cap.class); criteria.addOrder(Order.asc("prov")); criteria.setProjection( Projections.projectionList() .add( Projections.groupProperty("prov"), "prov")); out = criteria.list(); this.session.getTransaction().commit(); logger.debug("Total=" + out.size()); } catch (Throwable t) { throw new CapDAOException(t); } return out; } } --- TabCapDTO.java DELETED --- --- NEW FILE: CapDAOException.java --- /* * Copyright (C) 2007 Marco Ratto * * This file is part of the project trovacap-java. * * trovacap-java is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version. * * trovacap-java is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with trovacap-java; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package uk.co.marcoratto.jtrovacap.hsqldb; public class CapDAOException extends Exception { public CapDAOException() { } public CapDAOException(String message) { super(message); } public CapDAOException(Throwable cause) { super(cause); } public CapDAOException(String message, Throwable cause) { super(message, cause); } } --- NEW FILE: Cap.java --- /* * Copyright (C) 2007 Marco Ratto * * This file is part of the project trovacap-java. * * trovacap-java is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version. * * trovacap-java is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with trovacap-java; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package uk.co.marcoratto.jtrovacap.hsqldb; /* * For Table TAB_CAP */ public class Cap { /* ID_CAP, PK */ private long id; /* PROV_CAP */ private String prov; /* COMU_CAP */ private String comu; /* COM2_CAP */ private String com2; /* FRAZ_CAP */ private String fraz; /* FRA2_CAP */ private String fra2; /* TOPO_CAP */ private String topo; /* TOP2_CAP */ private String top2; /* DUGT_CAP */ private String dugt; /* NCIV_CAP */ private String nciv; /* CAPI_CAP */ private String capi; public Cap() { } /* ID_CAP, PK */ public long getId() { return id; } public void setId(long l) { this.id = l; } /* PROV */ public String getProv() { return prov; } /* PROV */ public void setProv(String s) { this.prov = s; } /* COMU_CAP */ public String getComu() { return comu; } /* COMU_CAP */ public void setComu(String s) { this.comu = s; } /* COM2_CAP */ public String getCom2() { return com2; } /* COM2_CAP */ public void setCom2(String s) { this.com2 = s; } /* FRAZ_CAP */ public String getFraz() { return fraz; } /* FRAZ_CAP */ public void setFraz(String s) { this.fraz = s; } /* FRA2_CAP */ public String getFra2() { return fra2; } /* FRA2_CAP */ public void setFra2(String s) { this.fra2 = s; } /* TOPO_CAP */ public String getTopo() { return topo; } /* TOPO_CAP */ public void setTopo(String s) { this.topo = s; } /* TOP2_CAP */ public String getTop2() { return top2; } /* TOP2_CAP */ public void setTop2(String s) { this.top2 = s; } /* DUGT_CAP */ public String getDugt() { return dugt; } /* DUGT_CAP */ public void setDugt(String s) { this.dugt = s; } /* NCIV_CAP */ public String getNciv() { return nciv; } /* NCIV_CAP */ public void setNciv(String s) { this.nciv = s; } /* CAPI_CAP */ public String getCapi() { return capi; } /* CAPI_CAP */ public void setCapi(String s) { this.capi = s; } } --- NEW FILE: Cap.hbm.xml --- <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="uk.co.marcoratto.jtrovacap.hsqldb.Cap" table="CAP"> <id name="id" column="ID"> <generator class="assigned"/> </id> <property name="prov" type="string"/> <property name="comu" type="string" column="COMU"/> <property name="com2" type="string" column="COM2"/> <property name="fraz" type="string" column="FRAZ"/> <property name="fra2" type="string" column="FRA2"/> <property name="topo" type="string" column="TOPO"/> <property name="top2" type="string" column="TOP2"/> <property name="dugt" type="string" column="DUGT"/> <property name="nciv" type="string" column="NCIV"/> <property name="capi" type="string" column="CAPI"/> </class> </hibernate-mapping> |