This repository has been archived on 2025-12-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tdi-studio-se/main/plugins/org.talend.designer.components.localprovider/components/tJavaDBOutput/tJavaDBOutput_end.javajet
2020-08-12 11:20:05 +03:00

122 lines
3.6 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
java.util.List
"
%>
<%@ 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 commitEvery = ElementParameterParser.getValue(node, "__COMMIT_EVERY__");
String frameworkType = ElementParameterParser.getValue(node,"__FRAMEWORK_TYPE__");
boolean setAutoCommit = false;
boolean useExistingConnection = false;
String connectionFlag = ElementParameterParser.getValue(node, "__CONNECTION_FLAG__");
if(!("").equals(commitEvery)&&!("0").equals(commitEvery)){
%>
if (commitCounter_<%=cid%> > 0) {
<%dbLog.commit().commitTry(null, dbLog.var("commitCounter"));%>
conn_<%=cid%>.commit();
<%dbLog.commit().commitDone(null);%>
}
<%
}
if(("INSERT_OR_UPDATE").equals(dataAction)) {
%>
if(pstmtUpdate_<%=cid%> != null){
pstmtUpdate_<%=cid %>.close();
resourceMap.remove("pstmtUpdate_<%=cid %>");
}
if(pstmtInsert_<%=cid %> != null){
pstmtInsert_<%=cid %>.close();
resourceMap.remove("pstmtInsert_<%=cid %>");
}
if(pstmt_<%=cid %> != null) {
pstmt_<%=cid %>.close();
resourceMap.remove("pstmt_<%=cid %>");
}
<%
} else if(("UPDATE_OR_INSERT").equals(dataAction)) {
%>
if(pstmtUpdate_<%=cid%> != null){
pstmtUpdate_<%=cid %>.close();
resourceMap.remove("pstmtUpdate_<%=cid %>");
}
if(pstmtInsert_<%=cid %> != null){
pstmtInsert_<%=cid %>.close();
resourceMap.remove("pstmtInsert_<%=cid %>");
}
<%
} else {
%>
if(pstmt_<%=cid %> != null) {
pstmt_<%=cid %>.close();
resourceMap.remove("pstmt_<%=cid %>");
}
<%
}
%>
resourceMap.put("statementClosed_<%=cid%>", true);
<%dbLog.conn().closeTry(null);%>
conn_<%=cid%> .close();
<%dbLog.conn().closeDone(null);%>
<%
if(("EMBEDED").equals(frameworkType))
{%>
try
{
java.sql.DriverManager.getConnection("jdbc:derby:;shutdown=true");
}
catch(java.sql.SQLException se)
{
/*
In embedded mode, an application should shut down Derby.
If the application fails to shut down Derby explicitly,
the Derby does not perform a checkpoint when the JVM shuts down, which means
that the next connection will be slower.
Explicitly shutting down Derby with the URL is preferred.
This style of shutdown will always throw an "exception".
*/
}
<%
}
else
{
if(("false").equals(connectionFlag))
{
%>
serverControl_<%=cid%>.shutdown();
<%
}
}
%>
resourceMap.put("finish_<%=cid%>", true);
int rejectedCount_<%=cid%> = 0;
<%
String rejectConnName = null;
List<? extends IConnection> rejectConns = node.getOutgoingConnections("REJECT");
if(rejectConns != null && rejectConns.size() > 0) {
IConnection rejectConn = rejectConns.get(0);
rejectConnName = rejectConn.getName();
}
%>
<%@ include file="../templates/DB/Output/DBOutputEndGlobalVars.javajet"%>