package it.acxent.news; import it.acxent.anag.Users; import it.acxent.db.ApplParmFull; import it.acxent.db.DBAdapter; import it.acxent.db.ResParm; 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.Calendar; public class NewsUsers extends DBAdapter implements Serializable { private static final long serialVersionUID = 6424449574380883136L; private long id_newsUsers; private long id_users; private long id_news; private Timestamp tmstInvio; private News news; private Users users; private String result; public NewsUsers(ApplParmFull newApplParmFull) { super(newApplParmFull); } public NewsUsers() {} protected ResParm checkDeleteCascade() { return new ResParm(true); } protected void deleteCascade() {} public Vectumerator findByCR(NewsUsersCR CR, int pageNumber, int pageRows) { String s_Sql_Find = "select A.* from NEWS_USERS AS A"; String s_Sql_Order = ""; WcString wc = new WcString(); if (CR.getId_news() > 0L) wc.addWc(" A.id_news = " + CR.getId_news()); if (CR.getId_users() > 0L) wc.addWc(" A.id_users = " + CR.getId_users()); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); return findRows(stmt, pageNumber, pageRows); } catch (SQLException e) { removeCPConnection(); handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public long getId_newsUsers() { return this.id_newsUsers; } public void setId_newsUsers(long id_newsUsers) { this.id_newsUsers = id_newsUsers; } public long getId_users() { return this.id_users; } public void setId_users(long id_users) { this.id_users = id_users; } public long getId_news() { return this.id_news; } public void setId_news(long id_news) { this.id_news = id_news; } public Timestamp getTmstInvio() { return this.tmstInvio; } public void setTmstInvio(Timestamp tmstInvio) { this.tmstInvio = tmstInvio; } public void findByNewsUsers(long l_id_news, long l_id_users) { String s_Sql_Find = "select A.* from NEWS_USERS AS A"; String s_Sql_Order = ""; WcString wc = new WcString(); wc.addWc(" A.id_news = " + l_id_news); wc.addWc(" A.id_users = " + l_id_users); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); findFirstRecord(stmt); } catch (SQLException e) { removeCPConnection(); handleDebug(e); } } public News getNews() { this.news = (News)getSecondaryObject(this.news, News.class, getId_news()); return this.news; } public void setNews(News news) { this.news = news; } public Users getUsers() { this.users = (Users)getSecondaryObject((DBAdapter)this.users, Users.class, getId_users()); return this.users; } public void setUsers(Users users) { this.users = users; } public Vectumerator findByNews(long l_id_news) { String s_Sql_Find = "select A.* from NEWS_USERS 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); } catch (SQLException e) { removeCPConnection(); handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public void findByUsers(long l_id_users) { String s_Sql_Find = "select A.* from NEWS_USERS AS A"; String s_Sql_Order = ""; WcString wc = new WcString(); wc.addWc(" A.id_users = " + l_id_users); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); findFirstRecord(stmt); } catch (SQLException e) { removeCPConnection(); handleDebug(e); } } public ResParm addUser(long l_id_news, long l_id_user, String result) { findByNewsUsers(l_id_news, l_id_user); setId_news(l_id_news); setId_users(l_id_user); setTmstInvio(new Timestamp(Calendar.getInstance().getTimeInMillis())); setResult(result); ResParm rp = save(); return rp; } public String getResult() { return (this.result == null) ? "" : this.result.trim(); } public void setResult(String result) { this.result = result; } }