/** Business index */
public String idb = null;
/** Business Unit */
public long idbunit = LSDConstants.invalide_idx;
/** Business Owner */
public String idowner = null;
/** Limit of time validity */
public Timestamp limitdate = null;
/** Extended fields for Business */
protected static final String[] fieldsext = {"IDMETIER","IDBUNIT","IDOWNER","LIMITDATE"};
/** Index for extended fields for Business */
public static final int ridb = 0;
/** Index for extended fields for Business */
public static final int ridbunit = 1;
/** Index for extended fields for Business */
public static final int ridowner = 2;
/** Index for extended fields for Business */
public static final int rlimitdate = 3;
/** Values to add to allfields (replace select *) */
public static final String allFieldsExt = ","+fieldsext[ridb]+","+fieldsext[ridbunit]+
","+fieldsext[ridowner]+","+fieldsext[rlimitdate]+" ";
/** Where condition in " condition " format which will be added
* to " WHERE Legacy = ? AND condition " and that must returns 1 unique document. */
public static String getWhereClause = fieldsext[ridb]+" = ? ";
/** Set for all fields except fields used in getWhereClause */
public static String getFieldsSetExt = ","+fieldsext[ridbunit]+
" = ?,"+fieldsext[ridowner]+" = ?,"+fieldsext[rlimitdate]+" = ? ";
/** Set for all fields */
public static String getFieldsSetAllExt = ","+fieldsext[ridb]+" = ?,"+fieldsext[ridbunit]+
"= ?,"+fieldsext[ridowner]+"= ?,"+fieldsext[rlimitdate]+" = ? ";
/** Set values as NULL (or empty) including where clause */
public static String getFieldsSetExtNULL = ","+fieldsext[ridb]+" = NULL,"+fieldsext[ridbunit]+
"= "+LSDConstants.invalide_idx+","+fieldsext[ridowner]+"=NULL,"+
fieldsext[rlimitdate]+" = NULL ";
/** @see openlsd.database.business.LSDBusiness#getAllFieldsExt() */
public String getAllFieldsExt() {
return allFieldsExt;
}
/** @see openlsd.database.business.LSDBusiness#getFieldsExt(int) */
public String getFieldsExt(int number) {
return fieldsext[number];
}
/** @see openlsd.database.business.LSDBusiness#getFieldsSetAllExt() */
public String getFieldsSetAllExt() {
return getFieldsSetAllExt;
}
/** @see openlsd.database.business.LSDBusiness#getFieldsSetExt() */
public String getFieldsSetExt() {
return getFieldsSetExt;
}
/** @see openlsd.database.business.LSDBusiness#getFieldsSetExtNULL() */
public String getFieldsSetExtNULL() {
return getFieldsSetExtNULL;
}
/** @see openlsd.database.business.LSDBusiness#getWhereClause() */
public String getWhereClause() {
return getWhereClause;
}
/** @see openlsd.database.business.LSDBusiness#doc_hintBusiness() */
public String doc_hintBusiness() {
switch (LSDConstants.typeDriver) {
case LSDConstants.typeMySQL:
return " ";
case LSDConstants.typeOracle:
return " /*+ index(lsddocument IDX_DOC_LIDMETIERDATE)*/ ";
case LSDConstants.typePostgresql:
return " ";
default:
LSDConstants.logger.error("NO DRIVER CORRECTLY SPECIFIED:"+
LSDConstants.typeDriver);
return " ";
}
}
/** Default empty constructor */
public LSDBusinessImpl() {
this.idb = null;
this.idbunit = LSDConstants.invalide_idx;
this.idowner = null;
this.limitdate = null;
}
/** Constructor from data
* @param lsdb */
public LSDBusinessImpl(LSDBusiness lsdb) {
if (LSDBusiness.class.getClass() == LSDBusinessImpl.class.getClass())
this.setFromLSDBusiness((LSDBusinessImpl) lsdb);
}
/** Constructor from 1 int[] for rank and 1 String[] for value
* @param ranks
* @param args */
public LSDBusinessImpl(int []ranks, String []args) {
this.setFromStringArray(ranks, args);
}
/** Constructor from data
* @param lsdb */
public LSDBusinessImpl(LSDBusinessImpl lsdb) {
this.idb = lsdb.idb;
this.idbunit = lsdb.idbunit;
this.idowner = lsdb.idowner;
this.limitdate = lsdb.limitdate;
}
/** Set from 1 int[] for rank and 1 String[] for value
* @param ranks
* @param args
* @return True if OK, else False */
public boolean setFromStringArray(int []ranks, String []args) {
boolean retour = false;
if (ranks.length > args.length) {
LSDConstants.logger.warn("During initialization of LSDBusinessImpl: not correct ranks and args:"+ranks.length+">"+args.length);
return false;
}
int i, rank;
String arg;
for (i = 0; i < ranks.length; i++) {
arg = args[i];
rank = ranks[i];
switch (rank) {
case ridb:
this.idb = arg;
retour = true;
break;
case ridbunit:
try {
this.idbunit = Long.parseLong(arg);
} catch (NumberFormatException e) {
LSDConstants.logger.fatal("Bad Long:"+arg+", revert to -1");
this.idbunit = LSDConstants.invalide_idx;
}
retour = true;
break;
case ridowner:
this.idowner = arg;
retour = true;
break;
case rlimitdate:
// Replace ; as separator of date and time by blank character
arg = arg.replace(';', ' ');
try {
this.limitdate = Timestamp.valueOf(arg);
} catch (IllegalArgumentException e) {
LSDConstants.logger.fatal("Bad Timestamp:"+arg+", revert to NULL");
this.limitdate = null;
}
retour = true;
break;
default:
LSDConstants.logger.warn("During initialization of LSDBusinessImpl: Unknown index "
+rank+" for value "+arg);
break;
}
}
return retour;
}
/** @see openlsd.database.business.LSDBusiness#equals(openlsd.database.business.LSDBusiness)
*/
public boolean equals(LSDBusiness other) {
if (LSDBusiness.class.getClass() == LSDBusinessImpl.class.getClass())
return this.equals((LSDBusinessImpl) other);
return false;
}
/** @see openlsd.database.business.LSDBusiness#setFromLSDBusiness(openlsd.database.business.LSDBusiness) */
public boolean setFromLSDBusiness(LSDBusiness lsdb) {
if (LSDBusiness.class.getClass() == LSDBusinessImpl.class.getClass())
return setFromLSDBusiness((LSDBusinessImpl) lsdb);
return false;
}
/** Set internal value from ResultSet
* @param resultSet
* @return True if OK, else False */
public boolean getFromResultSet(ResultSet resultSet) {
try {
this.idb = resultSet.getString(fieldsext[ridb]);
this.idbunit = resultSet.getLong(fieldsext[ridbunit]);
this.idowner = resultSet.getString(fieldsext[ridowner]);
this.limitdate = resultSet.getTimestamp(fieldsext[rlimitdate]);
return true;
} catch (SQLException e) {
LSDConstants.logger.error("SQL Exception LSDExtDbDocument");
if (LSDConstants.LOGGING) {
LSDDbSession.error(e);
}
return false;
}
}
/** Set Values for Insert command
* @return the String for Insert command Value part
*/
public String getFieldsValues() {
String retour;
if (idb == null) {
retour = ",NULL,"+idbunit+",";
} else {
retour = ",'"+idb+"',"+idbunit+",";
}
if (idowner == null) {
retour = retour+"NULL,";
} else {
retour = retour+"'"+idowner+"',";
}
if (limitdate == null) {
return retour+"NULL) ";
} else {
return retour+"timestamp '"+limitdate+"') ";
}
}
/** Set the value into the prepareStatement from Object for the Where Condition in getWhereClause
* @param startrank The value to start from in the preparedStatement.setXXX call
* @param preparedStatement
* @return the next startrank or 0 if KO */
public int setToPrepStmtGetWhereClause(int startrank, LSDDbPreparedStatement preparedStatement) {
try {
preparedStatement.setString(startrank, idb);
} catch (SQLException e) {
LSDConstants.logger.error("Bad Prep Statement");
preparedStatement.realClose();
return 0;
}
return (startrank+1);
}
/** Set the value into the prepareStatement from Object for the set in GetFieldsSetExt
* @param startrank The value to start from in the preparedStatement.setXXX call
* @param preparedStatement
* @return the next startrank or 0 if KO */
public int setToPrepStmtGetFieldsSetExt(int startrank, LSDDbPreparedStatement preparedStatement) {
try {
preparedStatement.setLong(startrank, idbunit);
preparedStatement.setString(startrank+1, idowner);
preparedStatement.setTimestamp(startrank+2, limitdate);
} catch (SQLException e) {
LSDConstants.logger.error("Bad Prep Statement");
preparedStatement.realClose();
return 0;
}
return (startrank+3);
}
/** Set the value into the prepareStatement from Object for the set in GetFieldsSetAllExt
* @param startrank The value to start from in the preparedStatement.setXXX call
* @param preparedStatement
* @return the next startrank or 0 if KO */
public int setToPrepStmtGetFieldsSetAllExt(int startrank, LSDDbPreparedStatement preparedStatement) {
try {
preparedStatement.setString(startrank, idb);
preparedStatement.setLong(startrank+1, idbunit);
preparedStatement.setString(startrank+2, idowner);
preparedStatement.setTimestamp(startrank+3, limitdate);
} catch (SQLException e) {
LSDConstants.logger.error("Bad Prep Statement");
preparedStatement.realClose();
return 0;
}
return (startrank+4);
}
/** Clear all data in the object */
public void clear() {
this.idb = null;
this.idbunit = LSDConstants.invalide_idx;
this.idowner = null;
this.limitdate = null;
}
/** Clone the current object but only copy values
* @return The new object as a clone */
public LSDBusiness clone() {
LSDBusinessImpl newbusiness = new LSDBusinessImpl(this);
return newbusiness;
}
/**
* @param lsdb
* @return True if OK, else False
* @see openlsd.database.business.LSDBusiness#setFromLSDBusiness(openlsd.database.business.LSDBusiness) */
public boolean setFromLSDBusiness(LSDBusinessImpl lsdb) {
this.idb = lsdb.idb;
this.idbunit = lsdb.idbunit;
this.idowner = lsdb.idowner;
this.limitdate = lsdb.limitdate;
return true;
}
/** Comparison of two LSDBusinessImpl object on primary key (Business Index)
* @param other
* @return True if Business index are the same, else False */
public boolean equals(LSDBusinessImpl other) {
return this.idb.equals(other.idb);
}
/** Object to String
* @return the string that displays this object
* @see java.lang.Object#toString() */
public String toString() {
return " IDM:"+idb+";BUnit:"+idbunit+";Owner:"+idowner+";Lim:"+limitdate.toString();
}
/** (non-Javadoc)
* @see openlsd.database.business.LSDBusiness#setFromStringForDelete(java.lang.String)
*/
public void setFromString(String line) {
int []ranks = {LSDBusinessImpl.ridb };
String []values = {line};
this.setFromStringArray(ranks,values);
}
/** (non-Javadoc)
* @see openlsd.database.business.LSDBusiness#setFromStringForImport(int, java.lang.String[])
*/
public int setFromStrings(int curargs, String[] args) {
int []ranks = {LSDBusinessImpl.ridb,LSDBusinessImpl.ridbunit,LSDBusinessImpl.ridowner,
LSDBusinessImpl.rlimitdate};
String []newargs = {args[curargs],args[curargs+1],args[curargs+2],args[curargs+3]};
this.setFromStringArray(ranks, newargs);
return (curargs+4);
}
/** (non-Javadoc)
* @see openlsd.database.business.LSDBusiness#toCSV()
*/
@Override
public String toCSV() {
return idb+";"+idbunit+";"+idowner+";"+limitdate.getTime();
}