267 lines
7.5 KiB
Java
267 lines
7.5 KiB
Java
package it.acxent.anag;
|
|
|
|
import com.google.gson.Gson;
|
|
import it.acxent.anag.json.JsonComune;
|
|
import it.acxent.db.ApplParmFull;
|
|
import it.acxent.db.WcString;
|
|
import it.acxent.util.Vectumerator;
|
|
import java.io.Serializable;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.SQLException;
|
|
import java.sql.Timestamp;
|
|
import java.util.Vector;
|
|
|
|
public class Comune extends _AnagAdapter implements Serializable {
|
|
private static final long serialVersionUID = -8455737960994074428L;
|
|
|
|
private long id_comune;
|
|
|
|
private String id_regione;
|
|
|
|
private String codice;
|
|
|
|
private String descrizione;
|
|
|
|
private String provincia;
|
|
|
|
private String cap;
|
|
|
|
private String codiceComune;
|
|
|
|
private String codiceZona;
|
|
|
|
private Regione regione;
|
|
|
|
private long id_zona;
|
|
|
|
private Zona zona;
|
|
|
|
private String codiceTarga;
|
|
|
|
public Comune(ApplParmFull newApplParmFull) {
|
|
super(newApplParmFull);
|
|
}
|
|
|
|
public Comune() {}
|
|
|
|
public void setId_comune(long newId_comune) {
|
|
this.id_comune = newId_comune;
|
|
}
|
|
|
|
public void setId_regione(String newId_regione) {
|
|
this.id_regione = newId_regione;
|
|
setRegione(null);
|
|
}
|
|
|
|
public void setCodice(String newCodice) {
|
|
this.codice = newCodice;
|
|
}
|
|
|
|
public void setDescrizione(String newDescrizione) {
|
|
this.descrizione = newDescrizione;
|
|
}
|
|
|
|
public void setProvincia(String newProvincia) {
|
|
this.provincia = newProvincia;
|
|
}
|
|
|
|
public void setCap(String newCap) {
|
|
this.cap = newCap;
|
|
}
|
|
|
|
public void setCodiceComune(String newCodiceComune) {
|
|
this.codiceComune = newCodiceComune;
|
|
}
|
|
|
|
public void setCodiceZona(String newCodiceZona) {
|
|
this.codiceZona = newCodiceZona;
|
|
}
|
|
|
|
public long getId_comune() {
|
|
return this.id_comune;
|
|
}
|
|
|
|
public String getId_regione() {
|
|
return (this.id_regione == null) ? "" : this.id_regione.trim();
|
|
}
|
|
|
|
public String getCodice() {
|
|
return (this.codice == null) ? "" : this.codice.trim();
|
|
}
|
|
|
|
public String getDescrizione() {
|
|
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
|
}
|
|
|
|
public String getProvincia() {
|
|
return (this.provincia == null) ? "" : this.provincia.trim();
|
|
}
|
|
|
|
public String getCap() {
|
|
return (this.cap == null) ? "" : this.cap.trim();
|
|
}
|
|
|
|
public String getCodiceComune() {
|
|
return (this.codiceComune == null) ? "" : this.codiceComune.trim();
|
|
}
|
|
|
|
public String getCodiceZona() {
|
|
return (this.codiceZona == null) ? "" : this.codiceZona.trim();
|
|
}
|
|
|
|
public void setRegione(Regione newRegione) {
|
|
this.regione = newRegione;
|
|
}
|
|
|
|
public Regione getRegione() {
|
|
this.regione = (Regione)getSecondaryObject(this.regione, Regione.class, getId_regione());
|
|
return this.regione;
|
|
}
|
|
|
|
protected void deleteCascade() {}
|
|
|
|
public Vectumerator findByCR(ComuneCR CR, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from COMUNE AS A";
|
|
String s_Sql_Order = " order by A.descrizione";
|
|
if (CR.getFlgOrderBy() == 1L)
|
|
s_Sql_Order = " order by A.lastUpdTmst";
|
|
WcString wc = new WcString();
|
|
if (!CR.getSearchTxt().trim().isEmpty())
|
|
wc.addWc("(A.descrizione like '%" + prepareSqlString(CR.getSearchTxt()) + "%' or A.codice like '%" +
|
|
prepareSqlString(CR.getSearchTxt()) + "%')");
|
|
if (!CR.getDescrizioneS().trim().isEmpty())
|
|
wc.addWc("(A.descrizione like '%" + CR.getDescrizioneS() + "%' or A.codice like '%" + CR.getDescrizioneS() + "%')");
|
|
if (!CR.getId_regioneS().isEmpty())
|
|
wc.addWc("A.id_regione='" + CR.getId_regioneS() + "'");
|
|
if (CR.getLastUpdTmst() != null)
|
|
wc.addWc("A.lastUpdTmst>?");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
if (CR.getLastUpdTmst() != null)
|
|
stmt.setTimestamp(1, CR.getLastUpdTmst());
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public String getDescrizioneCompleta() {
|
|
return getCodice() + " " + getCodice();
|
|
}
|
|
|
|
public Vectumerator findByProv(String l_provincia) {
|
|
String s_Sql_Find = "select A.descrizione from COMUNE AS A";
|
|
String s_Sql_Order = " order by A.provincia";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.provincia='" + l_provincia + "'");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
return findRows(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public Vectumerator<Comune> findByProvCom(String l_provincia, String l_comuneDesc) {
|
|
String s_Sql_Find = "select A.* from COMUNE AS A";
|
|
String s_Sql_Order = " order by A.provincia";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.provincia='" + l_provincia + "'");
|
|
wc.addWc("A.descrizione='" + l_comuneDesc + "'");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
return findRows(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public void findByCap(String l_cap) {
|
|
String s_Sql_Find = "select A.* from COMUNE AS A";
|
|
String s_Sql_Order = " order by A.provincia";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.cap='" + l_cap + "'");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
findFirstRecord(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
|
|
public void findByCodice(String l_codice) {
|
|
String s_Sql_Find = "select A.* from COMUNE AS A";
|
|
String s_Sql_Order = " order by A.provincia";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.codice='" + l_codice + "'");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
findFirstRecord(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
|
|
public Vectumerator findProvince() {
|
|
String s_Sql_Find = "select A.provincia from COMUNE AS A";
|
|
String s_Sql_Order = " order by A.provincia";
|
|
WcString wc = new WcString();
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
return findRows(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public long getId_zona() {
|
|
return this.id_zona;
|
|
}
|
|
|
|
public void setId_zona(long id_zona) {
|
|
this.id_zona = id_zona;
|
|
setZona(null);
|
|
}
|
|
|
|
public Zona getZona() {
|
|
return this.zona;
|
|
}
|
|
|
|
public void setZona(Zona zona) {
|
|
this.zona = zona;
|
|
}
|
|
|
|
public String getJson(long l_tmst, int nPage) {
|
|
int pageRow = 40;
|
|
Comune bean = new Comune(getApFull());
|
|
ComuneCR CR = new ComuneCR(getApFull());
|
|
Vector<JsonComune> vecJ = new Vector<>();
|
|
if (l_tmst > 0L)
|
|
CR.setLastUpdTmst(new Timestamp(l_tmst));
|
|
CR.setFlgOrderBy(1L);
|
|
Vectumerator<Comune> vec = bean.findByCR(CR, nPage, pageRow);
|
|
while (vec.hasMoreElements()) {
|
|
Comune row = (Comune)vec.nextElement();
|
|
JsonComune jrow = new JsonComune();
|
|
jrow.setId_comune(row.getId_comune());
|
|
jrow.setDescrizione(row.getDescrizione());
|
|
jrow.setLastUpdTmst(row.getLastUpdTmst().getTime());
|
|
vecJ.add(jrow);
|
|
}
|
|
Gson gson = new Gson();
|
|
String res = gson.toJson(vecJ);
|
|
return res;
|
|
}
|
|
|
|
public String getCodiceTarga() {
|
|
return (this.codiceTarga == null) ? "" : this.codiceTarga.trim();
|
|
}
|
|
|
|
public void setCodiceTarga(String codiceTarga) {
|
|
this.codiceTarga = codiceTarga;
|
|
}
|
|
}
|