649 lines
30 KiB
Plaintext
649 lines
30 KiB
Plaintext
<%@ jet
|
|
imports="
|
|
org.talend.designer.codegen.config.CodeGeneratorArgument
|
|
org.talend.core.model.process.INode
|
|
org.talend.core.model.process.ElementParameterParser
|
|
org.talend.core.model.process.IConnection
|
|
org.talend.core.model.metadata.IMetadataTable
|
|
org.talend.core.model.metadata.types.JavaTypesManager
|
|
org.talend.core.model.metadata.MappingTypeRetriever
|
|
org.talend.core.model.metadata.MetadataTalendType
|
|
org.talend.core.model.process.IConnectionCategory
|
|
java.util.List
|
|
java.util.ArrayList
|
|
java.util.Map
|
|
java.util.HashMap
|
|
"
|
|
skeleton="../templates/db_output_bulk.skeleton"
|
|
%>
|
|
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/Log4j/DBLogUtil.javajet"%>
|
|
<%
|
|
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
|
INode node = (INode)codeGenArgument.getArgument();
|
|
String cid = node.getUniqueName();
|
|
dbLog = new DBLogUtil(node);
|
|
String dataAction = ElementParameterParser.getValue(node,"__DATA_ACTION__");
|
|
String dieOnError = ElementParameterParser.getValue(node, "__DIE_ON_ERROR__");
|
|
String tableName = ElementParameterParser.getValue(node,"__TABLE__");
|
|
String dbmsId = ElementParameterParser.getValue(node,"__MAPPING__");
|
|
List<Map<String, String>> addCols =
|
|
(List<Map<String,String>>)ElementParameterParser.getObjectValue(node,"__ADD_COLS__");
|
|
|
|
boolean useFieldOptions = ("true").equals(ElementParameterParser.getValue(node, "__USE_FIELD_OPTIONS__"));
|
|
|
|
List<Map<String, String>> fieldOptions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__FIELD_OPTIONS__");
|
|
|
|
String commitEvery = ElementParameterParser.getValue(node, "__COMMIT_EVERY__");
|
|
boolean isEnableDebug = ("true").equals(ElementParameterParser.getValue(node,"__ENABLE_DEBUG_MODE__"));
|
|
boolean useExistingConnection = "true".equalsIgnoreCase(ElementParameterParser.getValue(node,"__USE_EXISTING_CONNECTION__"));
|
|
String incomingConnName = null;
|
|
List<IMetadataColumn> columnList = getColumnList(node);
|
|
|
|
List< ? extends IConnection> conns = node.getIncomingConnections();
|
|
if(conns!=null && conns.size()>0){
|
|
IConnection conn = conns.get(0);
|
|
incomingConnName = conn.getName();
|
|
}
|
|
|
|
String rejectConnName = null;
|
|
List<? extends IConnection> rejectConns = node.getOutgoingConnections("REJECT");
|
|
if(rejectConns != null && rejectConns.size() > 0) {
|
|
IConnection rejectConn = rejectConns.get(0);
|
|
rejectConnName = rejectConn.getName();
|
|
}
|
|
List<IMetadataColumn> rejectColumnList = null;
|
|
IMetadataTable metadataTable = node.getMetadataFromConnector("REJECT");
|
|
if(metadataTable != null) {
|
|
rejectColumnList = metadataTable.getListColumns();
|
|
}
|
|
|
|
List<? extends IConnection> outgoingConns = node.getOutgoingSortedConnections();
|
|
for(IConnection conn : outgoingConns) {
|
|
if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
|
|
%>
|
|
<%=conn.getName() %> = null;
|
|
<%
|
|
}
|
|
}
|
|
|
|
List<Column> stmtStructure = getManager(dbmsId, cid).createColumnList(columnList, useFieldOptions, fieldOptions, addCols);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
List<Column> colStruct = new ArrayList();
|
|
for(Column colStmt : stmtStructure) {
|
|
if(!colStmt.isReplaced() && !colStmt.isAddCol()) {
|
|
colStruct.add(colStmt);
|
|
}
|
|
}
|
|
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = new StringBuffer("");
|
|
<%
|
|
}
|
|
|
|
boolean isParallelize ="true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__PARALLELIZE__"));
|
|
|
|
if (isParallelize) { // bug0014422
|
|
String tAsyncIn_cid = "";
|
|
if(conns!=null && conns.size() > 0) {
|
|
tAsyncIn_cid = conns.get(0).getSource().getUniqueName();
|
|
}
|
|
if(!useExistingConnection) {
|
|
if(!("").equals(commitEvery)&&!("0").equals(commitEvery)) {
|
|
%>
|
|
commitEvery_<%=cid%> = buffersSize_<%=tAsyncIn_cid%>;
|
|
<%
|
|
}
|
|
}
|
|
} // end bug0014422
|
|
|
|
if(incomingConnName != null && columnList != null) {
|
|
%>
|
|
whetherReject_<%=cid%> = false;
|
|
<%
|
|
if(("INSERT").equals(dataAction)){
|
|
int counter = 1;
|
|
for(Column column : colStruct) {
|
|
if(column.isInsertable()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getColumn().getTalendType(), column.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, column, counter, incomingConnName, cid, NORMAL_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, column, incomingConnName, cid, "query_" , counter, "insertSQLSplits_")%>;
|
|
<%
|
|
}
|
|
counter++;
|
|
}
|
|
}
|
|
if(isEnableDebug) {
|
|
%>
|
|
globalMap.put("<%=cid %>_QUERY", query_<%=cid%>.toString().trim());
|
|
<%
|
|
}
|
|
%>
|
|
try {
|
|
<%if(isEnableDebug){dbLog.data().sqlDebugPrint("globalMap.get(\""+cid+"_QUERY\")");}%>
|
|
insertedCount_<%=cid%> = insertedCount_<%=cid%> + pstmt_<%=cid %>.executeUpdate();
|
|
nb_line_<%=cid%>++;
|
|
<%dbLog.data().inserting(dbLog.var("nb_line"));%>
|
|
} catch(java.lang.Exception e) {
|
|
whetherReject_<%=cid%> = true;
|
|
<%
|
|
if (("true").equals(dieOnError)) {
|
|
%>
|
|
throw(e);
|
|
<%
|
|
} else {
|
|
if(rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) {
|
|
%>
|
|
<%=rejectConnName %> = new <%=rejectConnName %>Struct();
|
|
<%
|
|
for(IMetadataColumn column : columnList) {
|
|
%>
|
|
<%=rejectConnName%>.<%=column.getLabel()%> = <%=incomingConnName%>.<%=column.getLabel()%>;
|
|
<%
|
|
}
|
|
%>
|
|
nb_line_rejected_<%=cid%>++;
|
|
<%=rejectConnName%>.errorCode = ((java.sql.SQLException)e).getSQLState();
|
|
<%=rejectConnName%>.errorMessage = e.getMessage() + " - Line: " + tos_count_<%=node.getUniqueName() %>;
|
|
<%
|
|
} else {
|
|
dbLog.logPrintedException("e.getMessage()");
|
|
%>
|
|
System.err.print(e.getMessage());
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
}
|
|
<%
|
|
} else if(("UPDATE").equals(dataAction)) {
|
|
int counterCol = 1;
|
|
for(Column column : colStruct) {
|
|
if(column.isUpdatable()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getColumn().getTalendType(), column.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, column, counterCol, incomingConnName, cid, NORMAL_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, column, incomingConnName, cid, "query_" , counterCol, "updateSQLSplits_")%>;
|
|
<%
|
|
}
|
|
counterCol++;
|
|
}
|
|
}
|
|
|
|
for(Column column : colStruct) {
|
|
if(column.isUpdateKey()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getColumn().getTalendType(), column.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, column, counterCol, incomingConnName, cid, NORMAL_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, column, incomingConnName, cid, "query_" , counterCol, "updateSQLSplits_")%>;
|
|
<%
|
|
}
|
|
counterCol++;
|
|
}
|
|
}
|
|
if(isEnableDebug) {
|
|
%>
|
|
globalMap.put("<%=cid %>_QUERY", query_<%=cid%>.toString().trim());
|
|
<%
|
|
}
|
|
%>
|
|
try {
|
|
<%if(isEnableDebug){dbLog.data().sqlDebugPrint("globalMap.get(\""+cid+"_QUERY\")");}%>
|
|
updatedCount_<%=cid%> = updatedCount_<%=cid%> + pstmt_<%=cid %>.executeUpdate();
|
|
nb_line_<%=cid%>++;
|
|
<%dbLog.data().updating(dbLog.var("nb_line"));%>
|
|
} catch(java.lang.Exception e) {
|
|
whetherReject_<%=cid%> = true;
|
|
<%
|
|
if (("true").equals(dieOnError)) {
|
|
%>
|
|
throw(e);
|
|
<%
|
|
} else {
|
|
if(rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) {
|
|
%>
|
|
<%=rejectConnName %> = new <%=rejectConnName %>Struct();
|
|
<%
|
|
for(IMetadataColumn column : columnList) {
|
|
%>
|
|
<%=rejectConnName%>.<%=column.getLabel()%> = <%=incomingConnName%>.<%=column.getLabel()%>;
|
|
<%
|
|
}
|
|
%>
|
|
nb_line_rejected_<%=cid%>++;
|
|
<%=rejectConnName%>.errorCode = ((java.sql.SQLException)e).getSQLState();
|
|
<%=rejectConnName%>.errorMessage = e.getMessage() + " - Line: " + tos_count_<%=node.getUniqueName() %>;
|
|
<%
|
|
} else {
|
|
dbLog.logPrintedException("e.getMessage()");
|
|
%>
|
|
System.err.print(e.getMessage());
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
}
|
|
<%
|
|
} else if (("INSERT_OR_UPDATE").equals(dataAction)) {
|
|
int columnIndex = 1;
|
|
for(Column column : colStruct) {
|
|
if(column.isUpdateKey()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getColumn().getTalendType(), column.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, column, columnIndex, incomingConnName, cid, NORMAL_TYPE)%>
|
|
<%
|
|
columnIndex++;
|
|
}
|
|
}
|
|
%>
|
|
int checkCount_<%=cid%> = -1;
|
|
try (java.sql.ResultSet rs_<%=cid%> = pstmt_<%=cid %>.executeQuery()) {
|
|
while(rs_<%=cid%>.next()) {
|
|
checkCount_<%=cid%> = rs_<%=cid%>.getInt(1);
|
|
}
|
|
}
|
|
if(checkCount_<%=cid%> > 0) {
|
|
<%
|
|
int counterCol = 1;
|
|
for(Column column : colStruct) {
|
|
if(column.isUpdatable()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getColumn().getTalendType(), column.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, column, counterCol, incomingConnName, cid, UPDATE_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, column, incomingConnName, cid, "query_" , counterCol, "updateSQLSplits_")%>;
|
|
<%
|
|
}
|
|
counterCol++;
|
|
}
|
|
}
|
|
for(Column column : colStruct) {
|
|
if(column.isUpdateKey()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getColumn().getTalendType(), column.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, column, counterCol, incomingConnName, cid, UPDATE_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, column, incomingConnName, cid, "query_" , counterCol, "updateSQLSplits_")%>;
|
|
<%
|
|
}
|
|
counterCol++;
|
|
}
|
|
}
|
|
if(isEnableDebug) {
|
|
%>
|
|
globalMap.put("<%=cid %>_QUERY", query_<%=cid%>.toString().trim());
|
|
<%
|
|
}
|
|
%>
|
|
try {
|
|
<%if(isEnableDebug){dbLog.data().sqlDebugPrint("globalMap.get(\""+cid+"_QUERY\")");}%>
|
|
updatedCount_<%=cid%> = updatedCount_<%=cid%> + pstmtUpdate_<%=cid %>.executeUpdate();
|
|
nb_line_<%=cid%>++;
|
|
<%dbLog.data().updating(dbLog.var("nb_line"));%>
|
|
} catch(java.lang.Exception e) {
|
|
whetherReject_<%=cid%> = true;
|
|
<%
|
|
if (("true").equals(dieOnError)) {
|
|
%>
|
|
throw(e);
|
|
<%
|
|
} else {
|
|
%>
|
|
nb_line_<%=cid%>++;
|
|
<%
|
|
if(rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) {
|
|
%>
|
|
<%=rejectConnName %> = new <%=rejectConnName %>Struct();
|
|
<%
|
|
for(IMetadataColumn column : columnList) {
|
|
%>
|
|
<%=rejectConnName%>.<%=column.getLabel()%> = <%=incomingConnName%>.<%=column.getLabel()%>;
|
|
<%
|
|
}
|
|
%>
|
|
nb_line_rejected_<%=cid%>++;
|
|
<%=rejectConnName%>.errorCode = ((java.sql.SQLException)e).getSQLState();
|
|
<%=rejectConnName%>.errorMessage = e.getMessage() + " - Line: " + tos_count_<%=node.getUniqueName() %>;
|
|
<%
|
|
} else {
|
|
dbLog.logPrintedException("e.getMessage()");
|
|
%>
|
|
System.err.print(e.getMessage());
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
}
|
|
} else {
|
|
<%
|
|
int counterInsert = 1;
|
|
for(Column columnInsert : colStruct) {
|
|
if(columnInsert.isInsertable()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(columnInsert.getColumn().getTalendType(), columnInsert.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, columnInsert, counterInsert, incomingConnName, cid, INSERT_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, columnInsert, incomingConnName, cid, "query_" , counterInsert, "insertSQLSplits_")%>;
|
|
<%
|
|
}
|
|
counterInsert++;
|
|
}
|
|
}
|
|
if(isEnableDebug) {
|
|
%>
|
|
globalMap.put("<%=cid %>_QUERY", query_<%=cid%>.toString().trim());
|
|
<%
|
|
}
|
|
%>
|
|
try {
|
|
<%if(isEnableDebug){dbLog.data().sqlDebugPrint("globalMap.get(\""+cid+"_QUERY\")");}%>
|
|
insertedCount_<%=cid%> = insertedCount_<%=cid%> + pstmtInsert_<%=cid %>.executeUpdate();
|
|
nb_line_<%=cid%>++;
|
|
<%dbLog.data().inserting(dbLog.var("nb_line"));%>
|
|
} catch(java.lang.Exception e) {
|
|
whetherReject_<%=cid%> = true;
|
|
<%
|
|
if (("true").equals(dieOnError)) {
|
|
%>
|
|
throw(e);
|
|
<%
|
|
} else {
|
|
%>
|
|
nb_line_<%=cid%>++;
|
|
<%
|
|
if(rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) {
|
|
%>
|
|
<%=rejectConnName %> = new <%=rejectConnName %>Struct();
|
|
<%
|
|
for(IMetadataColumn column : columnList) {
|
|
%>
|
|
<%=rejectConnName%>.<%=column.getLabel()%> = <%=incomingConnName%>.<%=column.getLabel()%>;
|
|
<%
|
|
}
|
|
%>
|
|
nb_line_rejected_<%=cid%>++;
|
|
<%=rejectConnName%>.errorCode = ((java.sql.SQLException)e).getSQLState();
|
|
<%=rejectConnName%>.errorMessage = e.getMessage() + " - Line: " + tos_count_<%=node.getUniqueName() %>;
|
|
<%
|
|
} else {
|
|
dbLog.logPrintedException("e.getMessage()");
|
|
%>
|
|
System.err.print(e.getMessage());
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
}
|
|
}
|
|
<%
|
|
} else if (("UPDATE_OR_INSERT").equals(dataAction)) {
|
|
%>
|
|
int updateFlag_<%=cid%>=0;
|
|
<%
|
|
int counterColUpdate = 1;
|
|
for(Column columnUpdate : colStruct) {
|
|
if(columnUpdate.isUpdatable()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(columnUpdate.getColumn().getTalendType(), columnUpdate.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, columnUpdate, counterColUpdate, incomingConnName, cid, UPDATE_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, columnUpdate, incomingConnName, cid, "query_" , counterColUpdate, "updateSQLSplits_")%>;
|
|
<%
|
|
}
|
|
counterColUpdate++;
|
|
}
|
|
}
|
|
|
|
for(Column columnUpdate : colStruct) {
|
|
if(columnUpdate.isUpdateKey()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(columnUpdate.getColumn().getTalendType(), columnUpdate.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, columnUpdate, counterColUpdate, incomingConnName, cid, UPDATE_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, columnUpdate, incomingConnName, cid, "query_" , counterColUpdate, "updateSQLSplits_")%>;
|
|
<%
|
|
}
|
|
counterColUpdate++;
|
|
}
|
|
}
|
|
if(isEnableDebug) {
|
|
%>
|
|
globalMap.put("<%=cid %>_QUERY", query_<%=cid%>.toString().trim());
|
|
<%
|
|
}
|
|
%>
|
|
|
|
try {
|
|
updateFlag_<%=cid%>=pstmtUpdate_<%=cid %>.executeUpdate();
|
|
if(updateFlag_<%=cid%> != 0){
|
|
nb_line_<%=cid%>++;
|
|
<%if(isEnableDebug){dbLog.data().sqlDebugPrint("globalMap.get(\""+cid+"_QUERY\")");}%>
|
|
<%dbLog.data().updating(dbLog.var("nb_line"));%>
|
|
}
|
|
updatedCount_<%=cid%> = updatedCount_<%=cid%>+updateFlag_<%=cid%>;
|
|
} catch(java.lang.Exception e) {
|
|
whetherReject_<%=cid%> = true;
|
|
<%
|
|
if (("true").equals(dieOnError)) {
|
|
%>
|
|
throw(e);
|
|
<%
|
|
} else {
|
|
if(rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) {
|
|
%>
|
|
<%=rejectConnName %> = new <%=rejectConnName %>Struct();
|
|
<%
|
|
for(IMetadataColumn column : columnList) {
|
|
%>
|
|
<%=rejectConnName%>.<%=column.getLabel()%> = <%=incomingConnName%>.<%=column.getLabel()%>;
|
|
<%
|
|
}
|
|
%>
|
|
nb_line_rejected_<%=cid%>++;
|
|
<%=rejectConnName%>.errorCode = ((java.sql.SQLException)e).getSQLState();
|
|
<%=rejectConnName%>.errorMessage = e.getMessage() + " - Line: " + tos_count_<%=node.getUniqueName() %>;
|
|
<%
|
|
} else {
|
|
dbLog.logPrintedException("e.getMessage()");
|
|
%>
|
|
System.err.print(e.getMessage());
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
}
|
|
if(updateFlag_<%=cid%> == 0) {
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = new StringBuffer("");
|
|
<%
|
|
}
|
|
int counter = 1;
|
|
for(Column column : colStruct) {
|
|
if(column.isInsertable()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getColumn().getTalendType(), column.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, column, counter, incomingConnName, cid, INSERT_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, column, incomingConnName, cid, "query_" , counter, "insertSQLSplits_")%>;
|
|
<%
|
|
}
|
|
counter++;
|
|
}
|
|
}
|
|
if(isEnableDebug) {
|
|
%>
|
|
globalMap.put("<%=cid %>_QUERY", query_<%=cid%>.toString().trim());
|
|
<%
|
|
}
|
|
%>
|
|
try {
|
|
<%if(isEnableDebug){dbLog.data().sqlDebugPrint("globalMap.get(\""+cid+"_QUERY\")");}%>
|
|
insertedCount_<%=cid%> = insertedCount_<%=cid%> + pstmtInsert_<%=cid %>.executeUpdate();
|
|
nb_line_<%=cid%>++;
|
|
<%dbLog.data().inserting(dbLog.var("nb_line"));%>
|
|
} catch(java.lang.Exception e) {
|
|
whetherReject_<%=cid%> = true;
|
|
<%
|
|
if (("true").equals(dieOnError)) {
|
|
%>
|
|
throw(e);
|
|
<%
|
|
} else {
|
|
%>
|
|
nb_line_<%=cid%>++;
|
|
<%
|
|
if(rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) {
|
|
%>
|
|
<%=rejectConnName %> = new <%=rejectConnName %>Struct();
|
|
<%
|
|
for(IMetadataColumn column : columnList) {
|
|
%>
|
|
<%=rejectConnName%>.<%=column.getLabel()%> = <%=incomingConnName%>.<%=column.getLabel()%>;
|
|
<%
|
|
}
|
|
%>
|
|
nb_line_rejected_<%=cid%>++;
|
|
<%=rejectConnName%>.errorCode = ((java.sql.SQLException)e).getSQLState();
|
|
<%=rejectConnName%>.errorMessage = e.getMessage() + " - Line: " + tos_count_<%=node.getUniqueName() %>;
|
|
<%
|
|
} else {
|
|
dbLog.logPrintedException("e.getMessage()");
|
|
%>
|
|
System.err.print(e.getMessage());
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
}
|
|
}
|
|
<%
|
|
} else if (("DELETE").equals(dataAction)) {
|
|
int keyCounter = 1;
|
|
for(Column column : colStruct) {
|
|
if(column.isDeleteKey()) {
|
|
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getColumn().getTalendType(), column.getColumn().isNullable());
|
|
%>
|
|
<%=getManager(dbmsId, cid).generateSetStmt(typeToGenerate, column, keyCounter, incomingConnName, cid, NORMAL_TYPE)%>
|
|
<%
|
|
if(isEnableDebug) {
|
|
%>
|
|
query_<%=cid%> = <%=getManager(dbmsId, cid).retrieveSQL(typeToGenerate, column, incomingConnName, cid, "query_" , keyCounter, "deleteSQLSplits_")%>;
|
|
<%
|
|
}
|
|
keyCounter++;
|
|
}
|
|
}
|
|
if(isEnableDebug) {
|
|
%>
|
|
globalMap.put("<%=cid %>_QUERY", query_<%=cid%>.toString().trim());
|
|
<%
|
|
}
|
|
%>
|
|
try {
|
|
<%if(isEnableDebug){dbLog.data().sqlDebugPrint("globalMap.get(\""+cid+"_QUERY\")");}%>
|
|
deletedCount_<%=cid%> = deletedCount_<%=cid%> + pstmt_<%=cid %>.executeUpdate();
|
|
nb_line_<%=cid%>++;
|
|
<%dbLog.data().deleting(dbLog.var("nb_line"));%>
|
|
} catch(java.lang.Exception e) {
|
|
whetherReject_<%=cid%> = true;
|
|
<%
|
|
if (("true").equals(dieOnError)) {
|
|
%>
|
|
throw(e);
|
|
<%
|
|
} else {
|
|
%>
|
|
nb_line_<%=cid%>++;
|
|
<%
|
|
if(rejectConnName != null && rejectColumnList != null && rejectColumnList.size() > 0) {
|
|
%>
|
|
<%=rejectConnName %> = new <%=rejectConnName %>Struct();
|
|
<%
|
|
for(IMetadataColumn column : columnList) {
|
|
%>
|
|
<%=rejectConnName%>.<%=column.getLabel()%> = <%=incomingConnName%>.<%=column.getLabel()%>;
|
|
<%
|
|
}
|
|
%>
|
|
nb_line_rejected_<%=cid%>++;
|
|
<%=rejectConnName%>.errorCode = ((java.sql.SQLException)e).getSQLState();
|
|
<%=rejectConnName%>.errorMessage = e.getMessage() + " - Line: " + tos_count_<%=node.getUniqueName() %>;
|
|
<%
|
|
} else {
|
|
dbLog.logPrintedException("e.getMessage()");
|
|
%>
|
|
System.err.print(e.getMessage());
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
}
|
|
<%
|
|
}
|
|
|
|
if(outgoingConns != null && outgoingConns.size() > 0) {
|
|
%>
|
|
if(!whetherReject_<%=cid%>) {
|
|
<%
|
|
for(IConnection outgoingConn : outgoingConns) {
|
|
if(rejectConnName == null || (rejectConnName != null && !outgoingConn.getName().equals(rejectConnName))) {
|
|
if(outgoingConn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
|
|
%>
|
|
<%=outgoingConn.getName()%> = new <%=outgoingConn.getName()%>Struct();
|
|
<%
|
|
for(IMetadataColumn column : columnList) {
|
|
%>
|
|
<%=outgoingConn.getName()%>.<%=column.getLabel()%> = <%=incomingConnName%>.<%=column.getLabel()%>;
|
|
<%
|
|
}
|
|
}
|
|
}
|
|
}
|
|
%>
|
|
}
|
|
<%
|
|
}
|
|
|
|
////////////commit every////////////
|
|
if(!("").equals(commitEvery) && !("0").equals(commitEvery)) {
|
|
%>
|
|
commitCounter_<%=cid%>++;
|
|
|
|
if(commitEvery_<%=cid%> <= commitCounter_<%=cid%>) {
|
|
<%dbLog.commit().commitTry(null, dbLog.var("commitCounter"));%>
|
|
conn_<%=cid%>.commit();
|
|
<%dbLog.commit().commitDone(null);%>
|
|
commitCounter_<%=cid%>=0;
|
|
|
|
}
|
|
|
|
<%
|
|
}
|
|
}
|
|
%>
|