Connection con = null;
StringBuffer strFields = new StringBuffer("");
StringBuffer strValues = new StringBuffer("");
FileImportData[] data = null;
int constant = 0;
OBError myMessage = null;
int i = 0;
try {
con = getTransactionConnection();
data = FileImportData.select(this, strAdImpformatId);
String strTable = FileImportData.table(this, strAdImpformatId);
for (i = 0; i < data2.length; i++) {
// create a basic row with uuid to be updated in the next step
String sequence = SequenceIdData.getUUID();
try {
FileImportData.insert(con, this, strTable, (strTable + "_ID"), sequence,
vars.getClient(), vars.getOrg(), vars.getUser());
} catch (ServletException ex) {
myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
releaseRollbackConnection(con);
return myMessage;
}
// generate the updated row information and update the basic row already created.
int jj = 0;
for (int j = 0; j < data.length; j++) {
if ((data2[i].getField(String.valueOf(j - constant)) == null || data2[i].getField(
String.valueOf(j - constant)).equals(""))
&& data[j].constantvalue.equals(""))
continue;
if (jj > 0)
strFields.append(",");
jj++;
strFields.append(data[j].columnname).append(" = ");
strValues.append("'");
if ((data[j].datatype.equals("C")) && (!data[j].constantvalue.equals(""))) {
strValues.append(data[j].constantvalue);
constant = constant + 1;
} else
strValues.append(parseField(data2[i].getField(String.valueOf(j - constant)),
data[j].fieldlength, data[j].datatype, data[j].dataformat, data[j].decimalpoint));
strValues.append("'");
strFields.append(strValues);
strValues.delete(0, strValues.length());
}
constant = 0;
if (log4j.isDebugEnabled())
log4j.debug("##########iteration - " + (i + 1) + " - strFields = " + strFields);
try {
FileImportData.update(con, this, strTable, strFields.toString(), (strTable + "_id = '"
+ sequence + "'"));
} catch (ServletException ex) {
myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
if (i == 0 && !firstRowHeaders) {
myMessage.setTitle(Utility.messageBD(this,
"Error while inserting data. Please check if the CSV file contains a header", vars
.getLanguage()));
} else {
myMessage.setTitle(Utility.messageBD(this, "Error while inserting data", vars
.getLanguage()));
}
String strMessage = myMessage.getMessage();
myMessage.setMessage("<strong>" + Utility.messageBD(this, "Line", vars.getLanguage())
+ " </strong>" + (i + 1) + "<br><strong>"
+ Utility.messageBD(this, "Inserting data", vars.getLanguage())
+ ": </strong>" + strFields + "<br><strong>"
+ Utility.messageBD(this, "Error", vars.getLanguage()) + " </strong>"
+ strMessage);
releaseRollbackConnection(con);
return myMessage;
}
strFields.delete(0, strFields.length());
}
releaseCommitConnection(con);
myMessage = new OBError();
myMessage.setType("Success");
myMessage.setTitle(Utility.messageBD(this, "Success", vars.getLanguage()));
myMessage.setMessage(Utility.messageBD(this, "Records inserted in the temporary table", vars
.getLanguage())
+ ": " + i);
} catch (Exception e) {
try {
releaseRollbackConnection(con);