Regalamiunsorriso/decompiled-libs/www/acxent-common-1.0.1/it/acxent/news/AllegatoNews.java

157 lines
4.3 KiB
Java

package it.acxent.news;
import it.acxent.db.ApplParmFull;
import it.acxent.db.DBAdapter;
import it.acxent.db.ResParm;
import it.acxent.db.WcString;
import it.acxent.util.StringTokenizer;
import it.acxent.util.Vectumerator;
import java.io.File;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class AllegatoNews extends DBAdapter implements Serializable {
private long id_allegatoNews;
private long id_news;
private long clickThroughAN;
private String nomeFile;
private News news;
public AllegatoNews(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public AllegatoNews() {}
public void setId_allegatoNews(long newId_allegato) {
this.id_allegatoNews = newId_allegato;
}
public void setId_news(long newId_news) {
this.id_news = newId_news;
setNews(null);
}
public void setNomeFile(String newNomeFile) {
this.nomeFile = newNomeFile;
}
public long getId_allegatoNews() {
return this.id_allegatoNews;
}
public long getId_news() {
return this.id_news;
}
public String getNomeFile() {
return (this.nomeFile == null) ? "" : this.nomeFile;
}
public String getNomeFileCompleto() {
return getNomeFileCompleto(getDocBase() + getDocBase());
}
public String getNomeFileCompleto(String l_path) {
return l_path + l_path + "_" + getId_news();
}
public String getNomeFileRel() {
return getParm("NEWS_ATTACH_PATH").getTesto() + getParm("NEWS_ATTACH_PATH").getTesto() + "_" + getId_news();
}
public void setNews(News newNews) {
this.news = newNews;
}
public News getNews() {
this.news = (News)getSecondaryObject(this.news, News.class, getId_news());
return this.news;
}
protected ResParm checkDeleteCascade() {
return new ResParm(true);
}
protected void deleteCascade() {
new File(getNomeFileCompleto()).delete();
}
public Vectumerator findByCR(AllegatoNewsCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from ALLEGATO_NEWS AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
if (!CR.getSearchTxt().trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = st.nextToken();
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
if (st.hasMoreTokens())
txt.append(" and ");
}
txt.append(")");
wc.addWc(txt.toString());
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findById_news(long l_id_news, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from ALLEGATO_NEWS AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_news=" + l_id_news);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public void findByNewsNomeFile(long l_id_news, String l_id_nomeFile) {
String s_Sql_Find = "select A.* from ALLEGATO_NEWS AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_news=" + l_id_news);
wc.addWc("A.nomeFile='" + l_id_nomeFile + "'");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public long getClickThroughAN() {
return this.clickThroughAN;
}
public void setClickThroughAN(long clickThroughAN) {
this.clickThroughAN = clickThroughAN;
}
public void addClickThrough(String ipAddress, String entryPoint) {
try {
if (getDBState() == 1)
synchronized (this) {
setClickThroughAN(getClickThroughAN() + 1L);
save();
}
} catch (Exception e) {
handleDebug(e);
}
}
}