Compare commits
1 Commits
master
...
vyu/TDI-43
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57082262b6 |
@@ -55,10 +55,36 @@
|
||||
>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8" SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')"
|
||||
>
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="10"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="12"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER
|
||||
NAME="ELT_TABLE_NAME"
|
||||
|
||||
@@ -86,6 +86,8 @@ imports="
|
||||
}
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
|
||||
boolean useWhereTable = ("true").equals(ElementParameterParser.getValue(node, "__USE_WHERE_CONDITIONS_TABLE__"));
|
||||
List<Map<String, String>> whereConditions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__WHERE_CONDITIONS_TABLE__");
|
||||
%>
|
||||
|
||||
|
||||
@@ -284,35 +286,58 @@ for(Column colStmt:stmtStructure){
|
||||
<%
|
||||
}else if (("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> " +select_query_<%=cid %>.substring(select_query_<%=cid %>.indexOf("FROM"));
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> " +select_query_<%=cid %>.substring(select_query_<%=cid %>.indexOf("FROM")));
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause) || (useWhereTable && whereConditions.size() > 0)) {
|
||||
%>
|
||||
if(select_query_<%=cid %>.indexOf("WHERE")==-1){
|
||||
updateQuery_<%=cid %> +=" WHERE ";
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
}else{
|
||||
updateQuery_<%=cid %> +=" AND ";
|
||||
}
|
||||
updateQuery_<%=cid %>+= <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
<%
|
||||
updateQuery_<%=cid %>.append(" AND ");
|
||||
}
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
updateQuery_<%=cid %>.append(<%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") "
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") ");
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
|
||||
<%
|
||||
}
|
||||
@@ -339,7 +364,7 @@ System.out.println("--> " + nb_line_inserted_<%=cid%> + " rows inserted. \n");
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
@@ -347,7 +372,7 @@ nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
|
||||
@@ -15,3 +15,19 @@ NB_LINE_DELETED.NAME=Number Of Deleted Lines
|
||||
USE_DIFFERENT_TABLE.NAME=Use different table name
|
||||
DIFFERENT_TABLE_NAME.NAME=Table name
|
||||
IS_TABLE_NAME_VARIABLE.NAME=Table name from connection name is variable
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
@@ -54,10 +54,36 @@
|
||||
>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8" SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')"
|
||||
>
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="10"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="12"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER
|
||||
NAME="ELT_TABLE_NAME"
|
||||
|
||||
@@ -1,146 +1,147 @@
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.core.model.metadata.IMetadataTable
|
||||
org.talend.core.model.metadata.IMetadataColumn
|
||||
org.talend.core.model.process.IConnection
|
||||
org.talend.commons.utils.generation.CodeGenerationUtils
|
||||
java.util.List
|
||||
java.util.ArrayList
|
||||
java.util.LinkedList
|
||||
java.util.Map
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jDBConnUtil.javajet"%>
|
||||
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
|
||||
String dbtable = null;
|
||||
String dbschema = ElementParameterParser.getValue(node,"__ELT_SCHEMA_NAME__");
|
||||
String uniqueNameConnection = null;
|
||||
INode previousNode = null;
|
||||
|
||||
String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__");
|
||||
boolean useDifferentTable = "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__"));
|
||||
boolean isTableNameVariable="true".equals(ElementParameterParser.getValue(node, "__IS_TABLE_NAME_VARIABLE__"));
|
||||
boolean useUpdateStatement="true".equals(ElementParameterParser.getValue(node, "__USE_UPDATE_STATEMENT__"));
|
||||
%>
|
||||
String select_query_<%=cid %> = null;
|
||||
String tableName_<%=cid%> = null;
|
||||
String selectQueryColumnsName_<%=cid %> = null;
|
||||
<%
|
||||
List<IConnection> connections = (List<IConnection>) node.getIncomingConnections();
|
||||
if(connections != null && connections.size() > 0 && connections.get(0) != null) {
|
||||
IConnection connection = connections.get(0);
|
||||
previousNode = connection.getSource();
|
||||
String previousComponentName = previousNode.getUniqueName();
|
||||
dbtable = connection.getName();
|
||||
uniqueNameConnection = connection.getUniqueName();
|
||||
|
||||
%>
|
||||
select_query_<%=cid %> = (String) globalMap.get("<%=previousComponentName%>"+"QUERY"+"<%=uniqueNameConnection%>");
|
||||
selectQueryColumnsName_<%=cid %> = (String) globalMap.get("<%=previousComponentName%>"+"QUERY_COLUMNS_NAME"+"<%=uniqueNameConnection%>");
|
||||
|
||||
<%
|
||||
}
|
||||
String tableName=null;
|
||||
if(useDifferentTable){
|
||||
tableName=differenttable;
|
||||
}else{
|
||||
if(isTableNameVariable){
|
||||
tableName=dbtable;
|
||||
}else{
|
||||
tableName="\""+dbtable +"\"";
|
||||
}
|
||||
}
|
||||
%>
|
||||
String dbschema_<%=cid%> = <%=dbschema%>;
|
||||
if(dbschema_<%=cid%> != null && dbschema_<%=cid%>.trim().length() > 0) {
|
||||
tableName_<%=cid%> = <%=dbschema%> + "." + <%=tableName%>;
|
||||
}else {
|
||||
tableName_<%=cid%> = <%=tableName%>;
|
||||
}
|
||||
<%
|
||||
String dataAction = ElementParameterParser.getValue(node,"__DATA_ACTION__");
|
||||
|
||||
String dbhost = null;
|
||||
String dbport = null;
|
||||
String dbname = null;
|
||||
String dbuser = null;
|
||||
boolean useExistingConn = false;
|
||||
String dbproperties = null;
|
||||
String driver = "JTDS";
|
||||
boolean useActiveDirectoryAuth = false;
|
||||
if(previousNode != null) {
|
||||
dbhost = ElementParameterParser.getValue(previousNode, "__HOST__");
|
||||
dbport = ElementParameterParser.getValue(previousNode, "__PORT__");
|
||||
dbname = ElementParameterParser.getValue(previousNode, "__DBNAME__");
|
||||
dbuser = ElementParameterParser.getValue(previousNode, "__USER__");
|
||||
useExistingConn = ("true").equals(ElementParameterParser.getValue(previousNode, "__USE_EXISTING_CONNECTION__"));
|
||||
dbproperties = ElementParameterParser.getValue(previousNode, "__PROPERTIES__");
|
||||
driver = ElementParameterParser.getValue(previousNode, "__DRIVER__");
|
||||
useActiveDirectoryAuth = "true".equals(ElementParameterParser.getValue(previousNode, "__ACTIVE_DIR_AUTH__"));
|
||||
}
|
||||
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
|
||||
%>
|
||||
|
||||
|
||||
<%
|
||||
if(useExistingConn) {
|
||||
String connection = ElementParameterParser.getValue(previousNode, "__CONNECTION__");
|
||||
String conn = "conn_" + connection;
|
||||
%>
|
||||
java.sql.Connection conn_<%=cid%> = (java.sql.Connection)globalMap.get("<%=conn%>");
|
||||
<%
|
||||
log4jCodeGenerateUtil.useExistConnection(node);
|
||||
} else {
|
||||
if("JTDS".equals(driver)) {
|
||||
%>
|
||||
String driverClass_<%=cid%> = "net.sourceforge.jtds.jdbc.Driver";
|
||||
<%} else {%>
|
||||
String driverClass_<%=cid%> = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
<%}%>
|
||||
java.lang.Class.forName(driverClass_<%=cid%>);
|
||||
String port_<%=cid%> = <%=dbport%>;
|
||||
String dbname_<%=cid%> = <%=dbname%> ;
|
||||
<%
|
||||
if("JTDS".equals(driver)) {
|
||||
%>
|
||||
String url_<%=cid %> = "jdbc:jtds:sqlserver://" + <%=dbhost%> ;
|
||||
<%} else {%>
|
||||
String url_<%=cid %> = "jdbc:sqlserver://" + <%=dbhost%> ;
|
||||
<%}%>
|
||||
if (!"".equals(port_<%=cid%>)) {
|
||||
url_<%=cid %> += ":" + <%=dbport%>;
|
||||
}
|
||||
if (!"".equals(dbname_<%=cid%>)) {
|
||||
<%
|
||||
if("JTDS".equals(driver)) {
|
||||
%>
|
||||
url_<%=cid%> += "//" + <%=dbname%>;
|
||||
<%} else {%>
|
||||
url_<%=cid%> += ";databaseName=" + <%=dbname%>;
|
||||
<%}%>
|
||||
}
|
||||
<%
|
||||
if (driver.equals("MSSQL_PROP") && useActiveDirectoryAuth) {
|
||||
%>
|
||||
url_<%=cid%> += ";encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;Authentication=ActiveDirectoryPassword";
|
||||
url_<%=cid%> += ";database=" + <%=dbname%>;
|
||||
<%
|
||||
}
|
||||
%>
|
||||
url_<%=cid%> += ";appName=" + projectName + ";" + <%=dbproperties%>;
|
||||
String dbUser_<%=cid %> = <%=dbuser%>;
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.core.model.metadata.IMetadataTable
|
||||
org.talend.core.model.metadata.IMetadataColumn
|
||||
org.talend.core.model.process.IConnection
|
||||
org.talend.commons.utils.generation.CodeGenerationUtils
|
||||
java.util.List
|
||||
java.util.ArrayList
|
||||
java.util.LinkedList
|
||||
java.util.Map
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jDBConnUtil.javajet"%>
|
||||
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
|
||||
String dbtable = null;
|
||||
String dbschema = ElementParameterParser.getValue(node,"__ELT_SCHEMA_NAME__");
|
||||
String uniqueNameConnection = null;
|
||||
INode previousNode = null;
|
||||
|
||||
String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__");
|
||||
boolean useDifferentTable = "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__"));
|
||||
boolean isTableNameVariable="true".equals(ElementParameterParser.getValue(node, "__IS_TABLE_NAME_VARIABLE__"));
|
||||
boolean useUpdateStatement="true".equals(ElementParameterParser.getValue(node, "__USE_UPDATE_STATEMENT__"));
|
||||
%>
|
||||
String select_query_<%=cid %> = null;
|
||||
String tableName_<%=cid%> = null;
|
||||
String selectQueryColumnsName_<%=cid %> = null;
|
||||
<%
|
||||
List<IConnection> connections = (List<IConnection>) node.getIncomingConnections();
|
||||
if(connections != null && connections.size() > 0 && connections.get(0) != null) {
|
||||
IConnection connection = connections.get(0);
|
||||
previousNode = connection.getSource();
|
||||
String previousComponentName = previousNode.getUniqueName();
|
||||
dbtable = connection.getName();
|
||||
uniqueNameConnection = connection.getUniqueName();
|
||||
|
||||
%>
|
||||
select_query_<%=cid %> = (String) globalMap.get("<%=previousComponentName%>"+"QUERY"+"<%=uniqueNameConnection%>");
|
||||
selectQueryColumnsName_<%=cid %> = (String) globalMap.get("<%=previousComponentName%>"+"QUERY_COLUMNS_NAME"+"<%=uniqueNameConnection%>");
|
||||
|
||||
<%
|
||||
}
|
||||
String tableName=null;
|
||||
if(useDifferentTable){
|
||||
tableName=differenttable;
|
||||
}else{
|
||||
if(isTableNameVariable){
|
||||
tableName=dbtable;
|
||||
}else{
|
||||
tableName="\""+dbtable +"\"";
|
||||
}
|
||||
}
|
||||
%>
|
||||
String dbschema_<%=cid%> = <%=dbschema%>;
|
||||
if(dbschema_<%=cid%> != null && dbschema_<%=cid%>.trim().length() > 0) {
|
||||
tableName_<%=cid%> = <%=dbschema%> + "." + <%=tableName%>;
|
||||
}else {
|
||||
tableName_<%=cid%> = <%=tableName%>;
|
||||
}
|
||||
<%
|
||||
String dataAction = ElementParameterParser.getValue(node,"__DATA_ACTION__");
|
||||
|
||||
String dbhost = null;
|
||||
String dbport = null;
|
||||
String dbname = null;
|
||||
String dbuser = null;
|
||||
boolean useExistingConn = false;
|
||||
String dbproperties = null;
|
||||
String driver = "JTDS";
|
||||
boolean useActiveDirectoryAuth = false;
|
||||
if(previousNode != null) {
|
||||
dbhost = ElementParameterParser.getValue(previousNode, "__HOST__");
|
||||
dbport = ElementParameterParser.getValue(previousNode, "__PORT__");
|
||||
dbname = ElementParameterParser.getValue(previousNode, "__DBNAME__");
|
||||
dbuser = ElementParameterParser.getValue(previousNode, "__USER__");
|
||||
useExistingConn = ("true").equals(ElementParameterParser.getValue(previousNode, "__USE_EXISTING_CONNECTION__"));
|
||||
dbproperties = ElementParameterParser.getValue(previousNode, "__PROPERTIES__");
|
||||
driver = ElementParameterParser.getValue(previousNode, "__DRIVER__");
|
||||
useActiveDirectoryAuth = "true".equals(ElementParameterParser.getValue(previousNode, "__ACTIVE_DIR_AUTH__"));
|
||||
}
|
||||
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
boolean useWhereTable = ("true").equals(ElementParameterParser.getValue(node, "__USE_WHERE_CONDITIONS_TABLE__"));
|
||||
List<Map<String, String>> whereConditions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__WHERE_CONDITIONS_TABLE__");
|
||||
%>
|
||||
|
||||
|
||||
<%
|
||||
if(useExistingConn) {
|
||||
String connection = ElementParameterParser.getValue(previousNode, "__CONNECTION__");
|
||||
String conn = "conn_" + connection;
|
||||
%>
|
||||
java.sql.Connection conn_<%=cid%> = (java.sql.Connection)globalMap.get("<%=conn%>");
|
||||
<%
|
||||
log4jCodeGenerateUtil.useExistConnection(node);
|
||||
} else {
|
||||
if("JTDS".equals(driver)) {
|
||||
%>
|
||||
String driverClass_<%=cid%> = "net.sourceforge.jtds.jdbc.Driver";
|
||||
<%} else {%>
|
||||
String driverClass_<%=cid%> = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
<%}%>
|
||||
java.lang.Class.forName(driverClass_<%=cid%>);
|
||||
String port_<%=cid%> = <%=dbport%>;
|
||||
String dbname_<%=cid%> = <%=dbname%> ;
|
||||
<%
|
||||
if("JTDS".equals(driver)) {
|
||||
%>
|
||||
String url_<%=cid %> = "jdbc:jtds:sqlserver://" + <%=dbhost%> ;
|
||||
<%} else {%>
|
||||
String url_<%=cid %> = "jdbc:sqlserver://" + <%=dbhost%> ;
|
||||
<%}%>
|
||||
if (!"".equals(port_<%=cid%>)) {
|
||||
url_<%=cid %> += ":" + <%=dbport%>;
|
||||
}
|
||||
if (!"".equals(dbname_<%=cid%>)) {
|
||||
<%
|
||||
if("JTDS".equals(driver)) {
|
||||
%>
|
||||
url_<%=cid%> += "//" + <%=dbname%>;
|
||||
<%} else {%>
|
||||
url_<%=cid%> += ";databaseName=" + <%=dbname%>;
|
||||
<%}%>
|
||||
}
|
||||
<%
|
||||
if (driver.equals("MSSQL_PROP") && useActiveDirectoryAuth) {
|
||||
%>
|
||||
url_<%=cid%> += ";encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;Authentication=ActiveDirectoryPassword";
|
||||
url_<%=cid%> += ";database=" + <%=dbname%>;
|
||||
<%
|
||||
}
|
||||
%>
|
||||
url_<%=cid%> += ";appName=" + projectName + ";" + <%=dbproperties%>;
|
||||
String dbUser_<%=cid %> = <%=dbuser%>;
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASS__";
|
||||
@@ -149,288 +150,311 @@ if(useExistingConn) {
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/eltpassword.javajet"%>
|
||||
|
||||
String dbPwd_<%=cid %> = decryptedPassword_<%=cid%>;
|
||||
|
||||
java.sql.Connection conn_<%=cid%> = null;
|
||||
<%
|
||||
log4jCodeGenerateUtil.debugConnectionParams(node);
|
||||
log4jCodeGenerateUtil.connect(node);
|
||||
}
|
||||
%>
|
||||
|
||||
<%
|
||||
List<IMetadataColumn> columnList = null;
|
||||
|
||||
List<IMetadataTable> metadatas = node.getMetadataList();
|
||||
if(metadatas !=null && metadatas.size()>0){
|
||||
IMetadataTable metadata = metadatas.get(0);
|
||||
if(metadata != null){
|
||||
columnList = metadata.getListColumns();
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
|
||||
java.sql.PreparedStatement pstmt_<%=cid %> =null;
|
||||
|
||||
<%
|
||||
|
||||
if(columnList != null && columnList.size()>0){
|
||||
|
||||
class Column{
|
||||
|
||||
IMetadataColumn column;
|
||||
|
||||
String name;
|
||||
|
||||
String sqlStmt;
|
||||
|
||||
String value;
|
||||
|
||||
boolean addCol;
|
||||
|
||||
List<Column> replacement = new ArrayList<Column>();
|
||||
|
||||
public Column(IMetadataColumn column){
|
||||
this.column = column;
|
||||
String columname = column.getOriginalDbColumnName();
|
||||
if(columname!=null && columname.trim().length()>0){
|
||||
this.name = columname;
|
||||
}else{
|
||||
this.name = column.getLabel();
|
||||
}
|
||||
this.sqlStmt = "=?";
|
||||
this.value = "?";
|
||||
this.addCol =false;
|
||||
}
|
||||
|
||||
public boolean isReplaced(){
|
||||
return replacement.size()>0;
|
||||
}
|
||||
|
||||
public List<Column> getReplacement(){
|
||||
return this.replacement;
|
||||
}
|
||||
|
||||
public IMetadataColumn getColumn(){
|
||||
return this.column;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isAddCol(){
|
||||
return this.addCol;
|
||||
}
|
||||
|
||||
public String getSqlStmt(){
|
||||
return this.sqlStmt;
|
||||
}
|
||||
|
||||
public String getValue(){
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder insertColName = new StringBuilder();
|
||||
|
||||
StringBuilder insertValueStmt = new StringBuilder();
|
||||
|
||||
StringBuilder updateSetStmt = new StringBuilder();
|
||||
|
||||
StringBuilder updateWhereStmt = new StringBuilder();
|
||||
|
||||
StringBuilder mergeCondition = new StringBuilder ();
|
||||
|
||||
List<Column> stmtStructure = new LinkedList<Column>();
|
||||
|
||||
for(IMetadataColumn column:columnList){
|
||||
|
||||
stmtStructure.add(new Column(column));
|
||||
|
||||
}
|
||||
|
||||
|
||||
int counterOuter =0;
|
||||
boolean firstKey = true;
|
||||
boolean firstNoneKey = true;
|
||||
boolean isfirstKey = true;
|
||||
for(Column colStmt:stmtStructure){
|
||||
String suffix = ",";
|
||||
|
||||
if (colStmt.getColumn().isKey()){
|
||||
if (isfirstKey) {
|
||||
isfirstKey = false;
|
||||
}else {
|
||||
mergeCondition.append(" AND ");
|
||||
}
|
||||
mergeCondition.append("target." + colStmt.getColumn().getLabel() + "=source." + colStmt.getColumn().getLabel());
|
||||
}
|
||||
if(colStmt.isReplaced()){
|
||||
List<Column> replacedColumns = colStmt.getReplacement();
|
||||
int counterReplace = 0;
|
||||
if(counterOuter==(stmtStructure.size()-1) && counterReplace==(replacedColumns.size()-1) ){
|
||||
suffix = "";
|
||||
}
|
||||
for(Column replacement:replacedColumns){
|
||||
insertColName.append(replacement.getName()+suffix);
|
||||
insertValueStmt.append(replacement.getSqlStmt()+suffix);
|
||||
if(!colStmt.getColumn().isKey()){
|
||||
if(!firstNoneKey){
|
||||
updateSetStmt.append(",");
|
||||
}else{
|
||||
firstNoneKey = false;
|
||||
}
|
||||
updateSetStmt.append(replacement.getName());
|
||||
updateSetStmt.append(replacement.getSqlStmt());
|
||||
}else{
|
||||
if(!firstKey){
|
||||
updateWhereStmt.append(" AND ");
|
||||
}else{
|
||||
firstKey = false;
|
||||
}
|
||||
updateWhereStmt.append(replacement.getName());
|
||||
updateWhereStmt.append(replacement.getSqlStmt());
|
||||
}
|
||||
counterReplace++;
|
||||
}
|
||||
}else{
|
||||
if(counterOuter==(stmtStructure.size()-1)){
|
||||
suffix = "";
|
||||
}
|
||||
if(colStmt.isAddCol()){
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getSqlStmt()+suffix);
|
||||
updateSetStmt.append(colStmt.getName());
|
||||
updateSetStmt.append(colStmt.getSqlStmt()+suffix);
|
||||
}else{
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getValue()+suffix);
|
||||
updateSetStmt.append(colStmt.getName()+"=(\"+select_query_"+ cid +".replaceFirst(java.util.regex.Pattern.quote(selectQueryColumnsName_"+ cid +"),routines.system.StringUtils.splitSQLColumns(selectQueryColumnsName_"+ cid +")[ "+ counterOuter + "])+\")" +suffix);
|
||||
}
|
||||
}
|
||||
counterOuter ++;
|
||||
}
|
||||
|
||||
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
String insertQuery_<%=cid %> = "INSERT INTO "+tableName_<%=cid%>+"(<%=insertColName.toString()%>) ("+select_query_<%=cid %>+")";
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(insertQuery_<%=cid %>);
|
||||
|
||||
<%
|
||||
}else if (("UPDATE").equals(dataAction)){
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
String updateQuery_<%=cid %> = select_query_<%=cid %>;
|
||||
<%
|
||||
}else{
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> ";
|
||||
<%
|
||||
}
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
if(select_query_<%=cid %>.indexOf("WHERE")==-1){
|
||||
updateQuery_<%=cid %> +=" WHERE ";
|
||||
}else{
|
||||
updateQuery_<%=cid %> +=" AND ";
|
||||
}
|
||||
updateQuery_<%=cid %>+= <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
<%
|
||||
}else{
|
||||
%>
|
||||
updateQuery_<%=cid %> += " WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") "
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
int nb_line_<%=cid%> = 0;
|
||||
int nb_line_updated_<%=cid%> = 0;
|
||||
int nb_line_inserted_<%=cid%> = 0;
|
||||
int nb_line_deleted_<%=cid%> = 0;
|
||||
<%
|
||||
|
||||
}
|
||||
|
||||
if(dbtable != null && columnList != null){
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
|
||||
System.out.println("Inserting with : \n" + insertQuery_<%=cid %> + "\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+insertQuery_"+ cid +"+\"");%>
|
||||
nb_line_inserted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_inserted_<%=cid%> + " rows inserted. \n");
|
||||
|
||||
<%
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_updated_<%=cid%> + " rows updated. \n");
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_deleted_<%=cid%> + " rows deleted. \n");
|
||||
<%
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
%>
|
||||
|
||||
pstmt_<%=cid %>.close();
|
||||
|
||||
<%
|
||||
if(!useExistingConn) {
|
||||
%>
|
||||
if(conn_<%=cid%> != null && !conn_<%=cid%>.isClosed()) {
|
||||
<%log4jCodeGenerateUtil.close(node);%>
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
nb_line_<%=cid%> = nb_line_updated_<%=cid%> + nb_line_inserted_<%=cid%> + nb_line_deleted_<%=cid%>;
|
||||
|
||||
globalMap.put("<%=cid %>_NB_LINE",nb_line_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_UPDATED",nb_line_updated_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_INSERTED",nb_line_inserted_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_DELETED",nb_line_deleted_<%=cid%>);
|
||||
|
||||
<%
|
||||
if(isLog4jEnabled){
|
||||
Map<String,String> actionMap=new java.util.HashMap<String,String>();
|
||||
actionMap.put("INSERT","inserted");
|
||||
actionMap.put("UPDATE","updated");
|
||||
actionMap.put("DELETE","deleted");
|
||||
%>
|
||||
log.info("<%=cid%> - Has <%=actionMap.get(dataAction)%> records count: " + nb_line_<%=actionMap.get(dataAction)%>_<%=cid%> + ".");
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
java.sql.Connection conn_<%=cid%> = null;
|
||||
<%
|
||||
log4jCodeGenerateUtil.debugConnectionParams(node);
|
||||
log4jCodeGenerateUtil.connect(node);
|
||||
}
|
||||
%>
|
||||
|
||||
<%
|
||||
List<IMetadataColumn> columnList = null;
|
||||
|
||||
List<IMetadataTable> metadatas = node.getMetadataList();
|
||||
if(metadatas !=null && metadatas.size()>0){
|
||||
IMetadataTable metadata = metadatas.get(0);
|
||||
if(metadata != null){
|
||||
columnList = metadata.getListColumns();
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
|
||||
java.sql.PreparedStatement pstmt_<%=cid %> =null;
|
||||
|
||||
<%
|
||||
|
||||
if(columnList != null && columnList.size()>0){
|
||||
|
||||
class Column{
|
||||
|
||||
IMetadataColumn column;
|
||||
|
||||
String name;
|
||||
|
||||
String sqlStmt;
|
||||
|
||||
String value;
|
||||
|
||||
boolean addCol;
|
||||
|
||||
List<Column> replacement = new ArrayList<Column>();
|
||||
|
||||
public Column(IMetadataColumn column){
|
||||
this.column = column;
|
||||
String columname = column.getOriginalDbColumnName();
|
||||
if(columname!=null && columname.trim().length()>0){
|
||||
this.name = columname;
|
||||
}else{
|
||||
this.name = column.getLabel();
|
||||
}
|
||||
this.sqlStmt = "=?";
|
||||
this.value = "?";
|
||||
this.addCol =false;
|
||||
}
|
||||
|
||||
public boolean isReplaced(){
|
||||
return replacement.size()>0;
|
||||
}
|
||||
|
||||
public List<Column> getReplacement(){
|
||||
return this.replacement;
|
||||
}
|
||||
|
||||
public IMetadataColumn getColumn(){
|
||||
return this.column;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isAddCol(){
|
||||
return this.addCol;
|
||||
}
|
||||
|
||||
public String getSqlStmt(){
|
||||
return this.sqlStmt;
|
||||
}
|
||||
|
||||
public String getValue(){
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder insertColName = new StringBuilder();
|
||||
|
||||
StringBuilder insertValueStmt = new StringBuilder();
|
||||
|
||||
StringBuilder updateSetStmt = new StringBuilder();
|
||||
|
||||
StringBuilder updateWhereStmt = new StringBuilder();
|
||||
|
||||
StringBuilder mergeCondition = new StringBuilder ();
|
||||
|
||||
List<Column> stmtStructure = new LinkedList<Column>();
|
||||
|
||||
for(IMetadataColumn column:columnList){
|
||||
|
||||
stmtStructure.add(new Column(column));
|
||||
|
||||
}
|
||||
|
||||
|
||||
int counterOuter =0;
|
||||
boolean firstKey = true;
|
||||
boolean firstNoneKey = true;
|
||||
boolean isfirstKey = true;
|
||||
for(Column colStmt:stmtStructure){
|
||||
String suffix = ",";
|
||||
|
||||
if (colStmt.getColumn().isKey()){
|
||||
if (isfirstKey) {
|
||||
isfirstKey = false;
|
||||
}else {
|
||||
mergeCondition.append(" AND ");
|
||||
}
|
||||
mergeCondition.append("target." + colStmt.getColumn().getLabel() + "=source." + colStmt.getColumn().getLabel());
|
||||
}
|
||||
if(colStmt.isReplaced()){
|
||||
List<Column> replacedColumns = colStmt.getReplacement();
|
||||
int counterReplace = 0;
|
||||
if(counterOuter==(stmtStructure.size()-1) && counterReplace==(replacedColumns.size()-1) ){
|
||||
suffix = "";
|
||||
}
|
||||
for(Column replacement:replacedColumns){
|
||||
insertColName.append(replacement.getName()+suffix);
|
||||
insertValueStmt.append(replacement.getSqlStmt()+suffix);
|
||||
if(!colStmt.getColumn().isKey()){
|
||||
if(!firstNoneKey){
|
||||
updateSetStmt.append(",");
|
||||
}else{
|
||||
firstNoneKey = false;
|
||||
}
|
||||
updateSetStmt.append(replacement.getName());
|
||||
updateSetStmt.append(replacement.getSqlStmt());
|
||||
}else{
|
||||
if(!firstKey){
|
||||
updateWhereStmt.append(" AND ");
|
||||
}else{
|
||||
firstKey = false;
|
||||
}
|
||||
updateWhereStmt.append(replacement.getName());
|
||||
updateWhereStmt.append(replacement.getSqlStmt());
|
||||
}
|
||||
counterReplace++;
|
||||
}
|
||||
}else{
|
||||
if(counterOuter==(stmtStructure.size()-1)){
|
||||
suffix = "";
|
||||
}
|
||||
if(colStmt.isAddCol()){
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getSqlStmt()+suffix);
|
||||
updateSetStmt.append(colStmt.getName());
|
||||
updateSetStmt.append(colStmt.getSqlStmt()+suffix);
|
||||
}else{
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getValue()+suffix);
|
||||
updateSetStmt.append(colStmt.getName()+"=(\"+select_query_"+ cid +".replaceFirst(java.util.regex.Pattern.quote(selectQueryColumnsName_"+ cid +"),routines.system.StringUtils.splitSQLColumns(selectQueryColumnsName_"+ cid +")[ "+ counterOuter + "])+\")" +suffix);
|
||||
}
|
||||
}
|
||||
counterOuter ++;
|
||||
}
|
||||
|
||||
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
String insertQuery_<%=cid %> = "INSERT INTO "+tableName_<%=cid%>+"(<%=insertColName.toString()%>) ("+select_query_<%=cid %>+")";
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(insertQuery_<%=cid %>);
|
||||
|
||||
<%
|
||||
}else if (("UPDATE").equals(dataAction)){
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer(select_query_<%=cid %>);
|
||||
<%
|
||||
}else{
|
||||
%>
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> ");
|
||||
<%
|
||||
}
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause) || (useWhereTable && whereConditions.size() > 0)) {
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
if(select_query_<%=cid %>.indexOf("WHERE")==-1){
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
}else{
|
||||
updateQuery_<%=cid %>.append(" AND ");
|
||||
}
|
||||
<%
|
||||
}else{
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
<%
|
||||
}
|
||||
if(!useWhereTable) {
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") ");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
<%
|
||||
}
|
||||
%>
|
||||
int nb_line_<%=cid%> = 0;
|
||||
int nb_line_updated_<%=cid%> = 0;
|
||||
int nb_line_inserted_<%=cid%> = 0;
|
||||
int nb_line_deleted_<%=cid%> = 0;
|
||||
<%
|
||||
|
||||
}
|
||||
|
||||
if(dbtable != null && columnList != null){
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
|
||||
System.out.println("Inserting with : \n" + insertQuery_<%=cid %> + "\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+insertQuery_"+ cid +"+\"");%>
|
||||
nb_line_inserted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_inserted_<%=cid%> + " rows inserted. \n");
|
||||
|
||||
<%
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_updated_<%=cid%> + " rows updated. \n");
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_deleted_<%=cid%> + " rows deleted. \n");
|
||||
<%
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
%>
|
||||
|
||||
pstmt_<%=cid %>.close();
|
||||
|
||||
<%
|
||||
if(!useExistingConn) {
|
||||
%>
|
||||
if(conn_<%=cid%> != null && !conn_<%=cid%>.isClosed()) {
|
||||
<%log4jCodeGenerateUtil.close(node);%>
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
nb_line_<%=cid%> = nb_line_updated_<%=cid%> + nb_line_inserted_<%=cid%> + nb_line_deleted_<%=cid%>;
|
||||
|
||||
globalMap.put("<%=cid %>_NB_LINE",nb_line_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_UPDATED",nb_line_updated_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_INSERTED",nb_line_inserted_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_DELETED",nb_line_deleted_<%=cid%>);
|
||||
|
||||
<%
|
||||
if(isLog4jEnabled){
|
||||
Map<String,String> actionMap=new java.util.HashMap<String,String>();
|
||||
actionMap.put("INSERT","inserted");
|
||||
actionMap.put("UPDATE","updated");
|
||||
actionMap.put("DELETE","deleted");
|
||||
%>
|
||||
log.info("<%=cid%> - Has <%=actionMap.get(dataAction)%> records count: " + nb_line_<%=actionMap.get(dataAction)%>_<%=cid%> + ".");
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
@@ -23,6 +23,22 @@ USER.NAME=Username
|
||||
COMMIT_EVERY.NAME=Commit every
|
||||
WHERE_CLAUSE.NAME=Where clauses \n(for UPDATE and DELETE only)
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
|
||||
ELT_TABLE_NAME.NAME=Default Table Name
|
||||
ELT_SCHEMA_NAME.NAME=Default Schema Name
|
||||
NB_LINE_UPDATED.NAME=Number Of Updated Lines
|
||||
|
||||
@@ -58,17 +58,41 @@
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="10"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="12"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER
|
||||
NAME="ELT_TABLE_NAME"
|
||||
FIELD="TEXT"
|
||||
NUM_ROW="10"
|
||||
NUM_ROW="13"
|
||||
>
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
@@ -65,7 +65,9 @@ imports="
|
||||
|
||||
String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__");
|
||||
boolean useDifferentTable = "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__"));
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
boolean useWhereTable = ("true").equals(ElementParameterParser.getValue(node, "__USE_WHERE_CONDITIONS_TABLE__"));
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
List<Map<String, String>> whereConditions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__WHERE_CONDITIONS_TABLE__");
|
||||
String tableName=null;
|
||||
if(useDifferentTable){
|
||||
tableName=differenttable;
|
||||
@@ -265,32 +267,55 @@ imports="
|
||||
<%
|
||||
} else if (("UPDATE").equals(dataAction)) {
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+<%=tableName%>;
|
||||
updateQuery_<%=cid %> +=" SET <%=updateSetStmt.toString()%> "
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE "+<%=tableName%>);
|
||||
updateQuery_<%=cid %>.append(" SET <%=updateSetStmt.toString()%> ");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
updateQuery_<%=cid %>.append(" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
<%
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+<%=tableName%>;
|
||||
deleteQuery_<%=cid %> += " WHERE EXISTS ("+select_query_<%=cid %>+")"
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE FROM "+<%=tableName%>);
|
||||
deleteQuery_<%=cid %>.append(" WHERE EXISTS ("+select_query_<%=cid %>+")");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
<%
|
||||
}
|
||||
%>
|
||||
@@ -312,7 +337,7 @@ imports="
|
||||
<%
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
@@ -320,7 +345,7 @@ imports="
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
|
||||
@@ -40,6 +40,22 @@ USER.NAME=Username
|
||||
WHERE_CLAUSE.NAME=Where clauses \n(for UPDATE and DELETE only)
|
||||
ELT_TABLE_NAME.NAME=Default Table Name
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
|
||||
USE_DIFFERENT_TABLE.NAME=Use different table name
|
||||
DIFFERENT_TABLE_NAME.NAME=Table name
|
||||
IS_TABLE_NAME_VARIABLE.NAME=Table name from connection name is variable
|
||||
|
||||
@@ -60,10 +60,36 @@
|
||||
</PARAMETER>
|
||||
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="10"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="12"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
|
||||
<PARAMETER
|
||||
|
||||
@@ -59,17 +59,19 @@ imports="
|
||||
}
|
||||
String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__");
|
||||
boolean useDifferentTable = "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__"));
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
String tableName=null;
|
||||
if(useDifferentTable){
|
||||
tableName=differenttable;
|
||||
}else{
|
||||
if(isTableNameVariable){
|
||||
tableName=dbtable;
|
||||
}else{
|
||||
tableName="\""+dbtable +"\"";
|
||||
}
|
||||
}
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
boolean useWhereTable = ("true").equals(ElementParameterParser.getValue(node, "__USE_WHERE_CONDITIONS_TABLE__"));
|
||||
List<Map<String, String>> whereConditions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__WHERE_CONDITIONS_TABLE__");
|
||||
String tableName=null;
|
||||
if(useDifferentTable){
|
||||
tableName=differenttable;
|
||||
}else{
|
||||
if(isTableNameVariable){
|
||||
tableName=dbtable;
|
||||
}else{
|
||||
tableName="\""+dbtable +"\"";
|
||||
}
|
||||
}
|
||||
%>
|
||||
java.sql.Connection conn_<%=cid%> = null;
|
||||
<%
|
||||
@@ -251,36 +253,58 @@ java.sql.Connection conn_<%=cid%> = null;
|
||||
<%
|
||||
} else if (("UPDATE").equals(dataAction)) {
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+<%=tableName%>;
|
||||
updateQuery_<%=cid %> +=" SET <%=updateSetStmt.toString()%> " +select_query_<%=cid %>.substring(select_query_<%=cid %>.indexOf("FROM"));
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE "+<%=tableName%>);
|
||||
updateQuery_<%=cid %>.append(" SET <%=updateSetStmt.toString()%> " +select_query_<%=cid %>.substring(select_query_<%=cid %>.indexOf("FROM")));
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause) || (useWhereTable && whereConditions.size() > 0)) {
|
||||
%>
|
||||
if(select_query_<%=cid %>.indexOf("WHERE")==-1){
|
||||
updateQuery_<%=cid %> +=" WHERE ";
|
||||
}else{
|
||||
updateQuery_<%=cid %> +=" AND ";
|
||||
}
|
||||
updateQuery_<%=cid %>+= <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
if(select_query_<%=cid %>.indexOf("WHERE")==-1){
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
}else{
|
||||
updateQuery_<%=cid %>.append(" AND ");
|
||||
}
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+<%=tableName%>;
|
||||
deleteQuery_<%=cid %> += " WHERE EXISTS ("+select_query_<%=cid %>+")"
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE FROM "+<%=tableName%>);
|
||||
deleteQuery_<%=cid %>.append(" WHERE EXISTS ("+select_query_<%=cid %>+")");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
<%
|
||||
}
|
||||
%>
|
||||
@@ -303,7 +327,7 @@ java.sql.Connection conn_<%=cid%> = null;
|
||||
<%
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
@@ -311,7 +335,7 @@ java.sql.Connection conn_<%=cid%> = null;
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
|
||||
@@ -14,3 +14,19 @@ NB_LINE.NAME=Number of line
|
||||
NB_LINE_UPDATED.NAME=Number Of Updated Lines
|
||||
NB_LINE_INSERTED.NAME=Number Of Inserted Lines
|
||||
NB_LINE_DELETED.NAME=Number Of Deleted Lines
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
@@ -38,7 +38,7 @@
|
||||
<PARAMETER
|
||||
NAME="DATA_ACTION"
|
||||
FIELD="CLOSED_LIST"
|
||||
NUM_ROW="6"
|
||||
NUM_ROW="2"
|
||||
>
|
||||
<ITEMS DEFAULT="INSERT">
|
||||
<ITEM NAME="INSERT" VALUE="INSERT" />
|
||||
@@ -51,16 +51,41 @@
|
||||
<PARAMETER
|
||||
NAME="SCHEMA"
|
||||
FIELD="SCHEMA_TYPE"
|
||||
NUM_ROW="7"
|
||||
NUM_ROW="3"
|
||||
>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8"
|
||||
NOT_SHOW_IF="(DATA_ACTION == 'MERGE') OR (DATA_ACTION == 'INSERT')"
|
||||
>
|
||||
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="5"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="6"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="7"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER
|
||||
NAME="USE_MERGE_UPDATE"
|
||||
FIELD="CHECK"
|
||||
|
||||
@@ -87,8 +87,9 @@ imports="
|
||||
dbproperties = ElementParameterParser.getValue(previousNode, "__PROPERTIES__");
|
||||
}
|
||||
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
|
||||
boolean useWhereTable = ("true").equals(ElementParameterParser.getValue(node, "__USE_WHERE_CONDITIONS_TABLE__"));
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
List<Map<String, String>> whereConditions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__WHERE_CONDITIONS_TABLE__");
|
||||
%>
|
||||
|
||||
|
||||
@@ -412,43 +413,60 @@ if (useHintOptions) {
|
||||
<%
|
||||
}else if (("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET (<%=insertColName.toString()%>) = ("+select_query_<%=cid %>+") "
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE "+tableName_<%=cid%>+" SET (<%=insertColName.toString()%>) = ("+select_query_<%=cid %>+") ");
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
updateQuery_<%=cid %>.append(" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
if (useHintOptions && hintsValues.get("UPDATE") != null){
|
||||
%>
|
||||
updateQuery_<%=cid %>.insert(updateQuery_<%=cid %>.toString().indexOf("UPDATE")+ "UPDATE".length() +1 , <%=hintsValues.get("UPDATE")%> + " ");
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
<% if (useHintOptions && hintsValues.get("UPDATE") != null){
|
||||
%>
|
||||
StringBuffer updateStringBuffer_<%=cid%> = new StringBuffer(updateQuery_<%=cid %>);
|
||||
updateStringBuffer_<%=cid%>.insert(updateQuery_<%=cid %>.indexOf("UPDATE")+ "UPDATE".length() +1 , <%=hintsValues.get("UPDATE")%> + " ");
|
||||
updateQuery_<%=cid %> =updateStringBuffer_<%=cid%>.toString();
|
||||
<%
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") "
|
||||
<%if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%}%>
|
||||
;
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") ");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
if(useHintOptions && hintsValues.get("DELETE") != null) {
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
StringBuffer deleteStringBuffer_<%=cid%> = new StringBuffer(deleteQuery_<%=cid %>);
|
||||
deleteStringBuffer_<%=cid%>.insert(deleteQuery_<%=cid %>.indexOf("DELETE")+ "DELETE".length()+1 , <%=hintsValues.get("DELETE")%> + " " );
|
||||
deleteQuery_<%=cid %> =deleteStringBuffer_<%=cid%>.toString();
|
||||
<%
|
||||
}%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
if(useHintOptions && hintsValues.get("DELETE") != null) {
|
||||
%>
|
||||
deleteQuery_<%=cid %>.insert(deleteQuery_<%=cid %>.toString().indexOf("DELETE")+ "DELETE".length()+1 , <%=hintsValues.get("DELETE")%> + " " );
|
||||
<%
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
|
||||
<%
|
||||
}else if ("MERGE".equals(dataAction)) {
|
||||
@@ -590,7 +608,7 @@ nb_line_inserted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
|
||||
%>
|
||||
<%if(!isLog4jEnabled){%>System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");<%}%>
|
||||
<%if(!isLog4jEnabled){%>System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");<%}%>
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
@@ -598,7 +616,7 @@ nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
<%if(!isLog4jEnabled){%>System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");<%}%>
|
||||
<%if(!isLog4jEnabled){%>System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString() +"\n");<%}%>
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
|
||||
@@ -35,6 +35,22 @@ USER.NAME=Username
|
||||
COMMIT_EVERY.NAME=Commit every
|
||||
WHERE_CLAUSE.NAME=Where clauses \n(for UPDATE and DELETE only)
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
|
||||
ELT_TABLE_NAME.NAME=Default Table Name
|
||||
ELT_SCHEMA_NAME.NAME=Default Schema Name
|
||||
NB_LINE_UPDATED.NAME=Number Of Updated Lines
|
||||
|
||||
@@ -83,10 +83,36 @@
|
||||
>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8" SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')"
|
||||
>
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="10"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="12"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER
|
||||
NAME="ELT_TABLE_NAME"
|
||||
|
||||
@@ -84,7 +84,9 @@ skeleton="../templates/db_output_bulk.skeleton"
|
||||
dbuser = ElementParameterParser.getValue(previousNode, "__USER__");
|
||||
useExistingConn = ("true").equals(ElementParameterParser.getValue(previousNode, "__USE_EXISTING_CONNECTION__"));
|
||||
}
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
boolean useWhereTable = ("true").equals(ElementParameterParser.getValue(node, "__USE_WHERE_CONDITIONS_TABLE__"));
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
List<Map<String, String>> whereConditions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__WHERE_CONDITIONS_TABLE__");
|
||||
%>
|
||||
String dbUser_<%=cid %> = null;
|
||||
<%
|
||||
@@ -163,46 +165,74 @@ skeleton="../templates/db_output_bulk.skeleton"
|
||||
String insertQuery_<%=cid %> = "INSERT INTO "+tableName_<%=cid%>+"(<%=insertColName.toString()%>) ("+select_query_<%=cid %>+")";
|
||||
<%
|
||||
} else if (("UPDATE").equals(dataAction)){
|
||||
boolean useAnd = false;
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
String updateQuery_<%=cid %> = select_query_<%=cid %>;
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer(select_query_<%=cid %>);
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
if (updateQuery_<%=cid %>.toUpperCase().contains(" WHERE ")) {
|
||||
updateQuery_<%=cid %> += " AND (" + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%> + ")";
|
||||
if (updateQuery_<%=cid %>.toString().toUpperCase().contains(" WHERE ")) {
|
||||
<%
|
||||
useAnd = true;
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(" AND (");
|
||||
} else {
|
||||
updateQuery_<%=cid %> += " WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
}
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> "
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> ");
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
<%
|
||||
}
|
||||
if(!useWhereTable) {
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
if(useAnd) {
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(")");
|
||||
<%
|
||||
}
|
||||
} else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") "
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
<%
|
||||
%>
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") ");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
%>
|
||||
|
||||
int nb_line_<%=cid%> = 0;
|
||||
int nb_line_updated_<%=cid%> = 0;
|
||||
@@ -239,9 +269,9 @@ skeleton="../templates/db_output_bulk.skeleton"
|
||||
<%
|
||||
} else if(("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
java.sql.PreparedStatement pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
java.sql.PreparedStatement pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_updated_<%=cid%> + " rows updated. \n");
|
||||
@@ -249,9 +279,9 @@ skeleton="../templates/db_output_bulk.skeleton"
|
||||
<%
|
||||
} else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
java.sql.PreparedStatement pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
java.sql.PreparedStatement pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_deleted_<%=cid%> + " rows deleted. \n");
|
||||
|
||||
@@ -23,6 +23,22 @@ USER.NAME=Username
|
||||
COMMIT_EVERY.NAME=Commit every
|
||||
WHERE_CLAUSE.NAME=Where clauses \n(for UPDATE and DELETE only)
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
|
||||
ELT_TABLE_NAME.NAME=Default Table Name
|
||||
ELT_SCHEMA_NAME.NAME=Default Schema Name
|
||||
NB_LINE_UPDATED.NAME=Number Of Updated Lines
|
||||
|
||||
@@ -54,10 +54,36 @@
|
||||
>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8" SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')"
|
||||
>
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="10"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="12"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER
|
||||
NAME="ELT_TABLE_NAME"
|
||||
|
||||
@@ -287,50 +287,74 @@ for(Column colStmt:stmtStructure){
|
||||
<%
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
String updateQuery_<%=cid %> = select_query_<%=cid %>;
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer(select_query_<%=cid %>);
|
||||
<%
|
||||
}else{
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> ";
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> ");
|
||||
<%
|
||||
}
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
if(select_query_<%=cid %>.indexOf("WHERE")==-1){
|
||||
updateQuery_<%=cid %> +=" WHERE ";
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
}else{
|
||||
updateQuery_<%=cid %> +=" AND ";
|
||||
updateQuery_<%=cid %>.append(" AND ");
|
||||
}
|
||||
updateQuery_<%=cid %>+= <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
<%
|
||||
}else{
|
||||
%>
|
||||
updateQuery_<%=cid %> += " WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
<%
|
||||
}
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") "
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") ");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
|
||||
<%
|
||||
}
|
||||
%>
|
||||
%>
|
||||
int nb_line_<%=cid%> = 0;
|
||||
int nb_line_updated_<%=cid%> = 0;
|
||||
int nb_line_inserted_<%=cid%> = 0;
|
||||
@@ -353,7 +377,7 @@ System.out.println("--> " + nb_line_inserted_<%=cid%> + " rows inserted. \n");
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
@@ -361,7 +385,7 @@ nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
|
||||
@@ -23,6 +23,22 @@ USER.NAME=Username
|
||||
COMMIT_EVERY.NAME=Commit every
|
||||
WHERE_CLAUSE.NAME=Where clauses \n(for UPDATE and DELETE only)
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
|
||||
ELT_TABLE_NAME.NAME=Default Table Name
|
||||
ELT_SCHEMA_NAME.NAME=Default Schema Name
|
||||
NB_LINE_UPDATED.NAME=Number Of Updated Lines
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
<PARAMETER
|
||||
NAME="DATA_ACTION"
|
||||
FIELD="CLOSED_LIST"
|
||||
NUM_ROW="6"
|
||||
NUM_ROW="2"
|
||||
>
|
||||
<ITEMS DEFAULT="INSERT">
|
||||
<ITEM NAME="INSERT" VALUE="INSERT" />
|
||||
@@ -52,15 +52,41 @@
|
||||
<PARAMETER
|
||||
NAME="SCHEMA"
|
||||
FIELD="SCHEMA_TYPE"
|
||||
NUM_ROW="7"
|
||||
NUM_ROW="3"
|
||||
>
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="5"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="6"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="7"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER
|
||||
NAME="ELT_TABLE_NAME"
|
||||
|
||||
@@ -1,138 +1,140 @@
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.core.model.metadata.IMetadataTable
|
||||
org.talend.core.model.metadata.IMetadataColumn
|
||||
org.talend.core.model.process.IConnection
|
||||
org.talend.commons.utils.generation.CodeGenerationUtils
|
||||
java.util.List
|
||||
java.util.ArrayList
|
||||
java.util.LinkedList
|
||||
java.util.Map
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jDBConnUtil.javajet"%>
|
||||
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
|
||||
String dbtable = null;
|
||||
String dbschema = ElementParameterParser.getValue(node,"__ELT_SCHEMA_NAME__");
|
||||
String uniqueNameConnection = null;
|
||||
INode previousNode = null;
|
||||
|
||||
String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__");
|
||||
boolean useDifferentTable = "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__"));
|
||||
String dbVersion = ElementParameterParser.getValue(node, "__DB_VERSION__");
|
||||
boolean isTableNameVariable="true".equals(ElementParameterParser.getValue(node, "__IS_TABLE_NAME_VARIABLE__"));
|
||||
%>
|
||||
String select_query_<%=cid %> = null;
|
||||
String tableName_<%=cid%> = null;
|
||||
String selectQueryColumnsName_<%=cid %> = null;
|
||||
<%
|
||||
List<IConnection> connections = (List<IConnection>) node.getIncomingConnections();
|
||||
if(connections != null && connections.size() > 0 && connections.get(0) != null) {
|
||||
IConnection connection = connections.get(0);
|
||||
previousNode = connection.getSource();
|
||||
String previousComponentName = previousNode.getUniqueName();
|
||||
dbtable = connection.getName();
|
||||
uniqueNameConnection = connection.getUniqueName();
|
||||
%>
|
||||
select_query_<%=cid %> = (String) globalMap.get("<%=previousComponentName%>"+"QUERY"+"<%=uniqueNameConnection%>");
|
||||
selectQueryColumnsName_<%=cid %> = (String) globalMap.get("<%=previousComponentName%>"+"QUERY_COLUMNS_NAME"+"<%=uniqueNameConnection%>");
|
||||
<%
|
||||
}
|
||||
String tableName=null;
|
||||
if(useDifferentTable){
|
||||
tableName=differenttable;
|
||||
}else{
|
||||
if(isTableNameVariable){
|
||||
tableName=dbtable;
|
||||
}else{
|
||||
tableName="\""+dbtable +"\"";
|
||||
}
|
||||
}
|
||||
%>
|
||||
String dbschema_<%=cid%> = <%=dbschema%>;
|
||||
if(dbschema_<%=cid%> != null && dbschema_<%=cid%>.trim().length() > 0) {
|
||||
tableName_<%=cid%> = <%=dbschema%> + "." + <%=tableName%>;
|
||||
} else {
|
||||
tableName_<%=cid%> = <%=tableName%>;
|
||||
}
|
||||
<%
|
||||
String dataAction = ElementParameterParser.getValue(node,"__DATA_ACTION__");
|
||||
|
||||
String dbhost = null;
|
||||
String dbport = null;
|
||||
String dbname = null;
|
||||
String dbuser = null;
|
||||
boolean useExistingConn = false;
|
||||
String dbproperties = null;
|
||||
if(previousNode != null) {
|
||||
dbhost = ElementParameterParser.getValue(previousNode, "__HOST__");
|
||||
dbport = ElementParameterParser.getValue(previousNode, "__PORT__");
|
||||
dbname = ElementParameterParser.getValue(previousNode, "__DBNAME__");
|
||||
dbuser = ElementParameterParser.getValue(previousNode, "__USER__");
|
||||
useExistingConn = ("true").equals(ElementParameterParser.getValue(previousNode, "__USE_EXISTING_CONNECTION__"));
|
||||
dbproperties = ElementParameterParser.getValue(previousNode, "__PROPERTIES__");
|
||||
}
|
||||
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
|
||||
%>
|
||||
|
||||
<%
|
||||
if(useExistingConn) {
|
||||
String connection = ElementParameterParser.getValue(previousNode, "__CONNECTION__");
|
||||
String conn = "conn_" + connection;
|
||||
%>
|
||||
java.sql.Connection conn_<%=cid%> = (java.sql.Connection)globalMap.get("<%=conn%>");
|
||||
<%
|
||||
log4jCodeGenerateUtil.useExistConnection(node);
|
||||
} else {
|
||||
if("SYBSEIQ_16_SA".equals(dbVersion)){
|
||||
%>
|
||||
String driverClass_<%=cid%> = "sap.jdbc4.sqlanywhere.IDriver";
|
||||
<%
|
||||
if(dbproperties == null || ("\"\"").equals(dbproperties) || ("").equals(dbproperties)) {
|
||||
%>
|
||||
String url_<%=cid%> = "jdbc:sqlanywhere:Host=" + <%=dbhost %> + ":" + <%=dbport %> + ";DatabaseName=" + <%=dbname %>;
|
||||
<%
|
||||
}
|
||||
else{
|
||||
%>
|
||||
String url_<%=cid%> = "jdbc:sqlanywhere:Host=" + <%=dbhost %> + ":" + <%=dbport %> + ";DatabaseName=" + <%=dbname %> + ";" + <%=dbproperties%>;
|
||||
<%
|
||||
}
|
||||
}
|
||||
else if("SYBSEIQ_16".equals(dbVersion)){%>
|
||||
String driverClass_<%=cid%> = "com.sybase.jdbc4.jdbc.SybDriver";
|
||||
<%}else{%>
|
||||
String driverClass_<%=cid%> = "com.sybase.jdbc3.jdbc.SybDriver";
|
||||
<%}%>
|
||||
java.lang.Class jdbcclazz_<%=cid%> = java.lang.Class.forName(driverClass_<%=cid%>);
|
||||
<%if("SYBSEIQ_16".equals(dbVersion)){%>
|
||||
jdbcclazz_<%=cid%>.newInstance();
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
if(dbproperties == null || ("\"\"").equals(dbproperties) || ("").equals(dbproperties)) {
|
||||
%>
|
||||
String url_<%=cid %> = "jdbc:sybase:Tds:" + <%=dbhost %> + ":" + <%=dbport %> + "/" + <%=dbname %>;
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
String url_<%=cid %> = "jdbc:sybase:Tds:" + <%=dbhost %> + ":" + <%=dbport %> + "/" + <%=dbname %> + "?" + <%=dbproperties%>;
|
||||
<%
|
||||
}
|
||||
%>
|
||||
String dbUser_<%=cid %> = <%=dbuser%>;
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.core.model.metadata.IMetadataTable
|
||||
org.talend.core.model.metadata.IMetadataColumn
|
||||
org.talend.core.model.process.IConnection
|
||||
org.talend.commons.utils.generation.CodeGenerationUtils
|
||||
java.util.List
|
||||
java.util.ArrayList
|
||||
java.util.LinkedList
|
||||
java.util.Map
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jDBConnUtil.javajet"%>
|
||||
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
|
||||
String dbtable = null;
|
||||
String dbschema = ElementParameterParser.getValue(node,"__ELT_SCHEMA_NAME__");
|
||||
String uniqueNameConnection = null;
|
||||
INode previousNode = null;
|
||||
|
||||
String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__");
|
||||
boolean useDifferentTable = "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__"));
|
||||
String dbVersion = ElementParameterParser.getValue(node, "__DB_VERSION__");
|
||||
boolean isTableNameVariable="true".equals(ElementParameterParser.getValue(node, "__IS_TABLE_NAME_VARIABLE__"));
|
||||
%>
|
||||
String select_query_<%=cid %> = null;
|
||||
String tableName_<%=cid%> = null;
|
||||
String selectQueryColumnsName_<%=cid %> = null;
|
||||
<%
|
||||
List<IConnection> connections = (List<IConnection>) node.getIncomingConnections();
|
||||
if(connections != null && connections.size() > 0 && connections.get(0) != null) {
|
||||
IConnection connection = connections.get(0);
|
||||
previousNode = connection.getSource();
|
||||
String previousComponentName = previousNode.getUniqueName();
|
||||
dbtable = connection.getName();
|
||||
uniqueNameConnection = connection.getUniqueName();
|
||||
%>
|
||||
select_query_<%=cid %> = (String) globalMap.get("<%=previousComponentName%>"+"QUERY"+"<%=uniqueNameConnection%>");
|
||||
selectQueryColumnsName_<%=cid %> = (String) globalMap.get("<%=previousComponentName%>"+"QUERY_COLUMNS_NAME"+"<%=uniqueNameConnection%>");
|
||||
<%
|
||||
}
|
||||
String tableName=null;
|
||||
if(useDifferentTable){
|
||||
tableName=differenttable;
|
||||
}else{
|
||||
if(isTableNameVariable){
|
||||
tableName=dbtable;
|
||||
}else{
|
||||
tableName="\""+dbtable +"\"";
|
||||
}
|
||||
}
|
||||
%>
|
||||
String dbschema_<%=cid%> = <%=dbschema%>;
|
||||
if(dbschema_<%=cid%> != null && dbschema_<%=cid%>.trim().length() > 0) {
|
||||
tableName_<%=cid%> = <%=dbschema%> + "." + <%=tableName%>;
|
||||
} else {
|
||||
tableName_<%=cid%> = <%=tableName%>;
|
||||
}
|
||||
<%
|
||||
String dataAction = ElementParameterParser.getValue(node,"__DATA_ACTION__");
|
||||
|
||||
String dbhost = null;
|
||||
String dbport = null;
|
||||
String dbname = null;
|
||||
String dbuser = null;
|
||||
boolean useExistingConn = false;
|
||||
String dbproperties = null;
|
||||
if(previousNode != null) {
|
||||
dbhost = ElementParameterParser.getValue(previousNode, "__HOST__");
|
||||
dbport = ElementParameterParser.getValue(previousNode, "__PORT__");
|
||||
dbname = ElementParameterParser.getValue(previousNode, "__DBNAME__");
|
||||
dbuser = ElementParameterParser.getValue(previousNode, "__USER__");
|
||||
useExistingConn = ("true").equals(ElementParameterParser.getValue(previousNode, "__USE_EXISTING_CONNECTION__"));
|
||||
dbproperties = ElementParameterParser.getValue(previousNode, "__PROPERTIES__");
|
||||
}
|
||||
|
||||
boolean useWhereTable = ("true").equals(ElementParameterParser.getValue(node, "__USE_WHERE_CONDITIONS_TABLE__"));
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
List<Map<String, String>> whereConditions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__WHERE_CONDITIONS_TABLE__");
|
||||
|
||||
%>
|
||||
|
||||
<%
|
||||
if(useExistingConn) {
|
||||
String connection = ElementParameterParser.getValue(previousNode, "__CONNECTION__");
|
||||
String conn = "conn_" + connection;
|
||||
%>
|
||||
java.sql.Connection conn_<%=cid%> = (java.sql.Connection)globalMap.get("<%=conn%>");
|
||||
<%
|
||||
log4jCodeGenerateUtil.useExistConnection(node);
|
||||
} else {
|
||||
if("SYBSEIQ_16_SA".equals(dbVersion)){
|
||||
%>
|
||||
String driverClass_<%=cid%> = "sap.jdbc4.sqlanywhere.IDriver";
|
||||
<%
|
||||
if(dbproperties == null || ("\"\"").equals(dbproperties) || ("").equals(dbproperties)) {
|
||||
%>
|
||||
String url_<%=cid%> = "jdbc:sqlanywhere:Host=" + <%=dbhost %> + ":" + <%=dbport %> + ";DatabaseName=" + <%=dbname %>;
|
||||
<%
|
||||
}
|
||||
else{
|
||||
%>
|
||||
String url_<%=cid%> = "jdbc:sqlanywhere:Host=" + <%=dbhost %> + ":" + <%=dbport %> + ";DatabaseName=" + <%=dbname %> + ";" + <%=dbproperties%>;
|
||||
<%
|
||||
}
|
||||
}
|
||||
else if("SYBSEIQ_16".equals(dbVersion)){%>
|
||||
String driverClass_<%=cid%> = "com.sybase.jdbc4.jdbc.SybDriver";
|
||||
<%}else{%>
|
||||
String driverClass_<%=cid%> = "com.sybase.jdbc3.jdbc.SybDriver";
|
||||
<%}%>
|
||||
java.lang.Class jdbcclazz_<%=cid%> = java.lang.Class.forName(driverClass_<%=cid%>);
|
||||
<%if("SYBSEIQ_16".equals(dbVersion)){%>
|
||||
jdbcclazz_<%=cid%>.newInstance();
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
if(dbproperties == null || ("\"\"").equals(dbproperties) || ("").equals(dbproperties)) {
|
||||
%>
|
||||
String url_<%=cid %> = "jdbc:sybase:Tds:" + <%=dbhost %> + ":" + <%=dbport %> + "/" + <%=dbname %>;
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
String url_<%=cid %> = "jdbc:sybase:Tds:" + <%=dbhost %> + ":" + <%=dbport %> + "/" + <%=dbname %> + "?" + <%=dbproperties%>;
|
||||
<%
|
||||
}
|
||||
%>
|
||||
String dbUser_<%=cid %> = <%=dbuser%>;
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASS__";
|
||||
@@ -141,249 +143,269 @@ imports="
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/eltpassword.javajet"%>
|
||||
|
||||
String dbPwd_<%=cid %> = decryptedPassword_<%=cid%>;
|
||||
|
||||
java.sql.Connection conn_<%=cid%> = null;
|
||||
<%
|
||||
log4jCodeGenerateUtil.debugConnectionParams(node);
|
||||
log4jCodeGenerateUtil.connect(node);
|
||||
}
|
||||
%>
|
||||
|
||||
<%
|
||||
List<IMetadataColumn> columnList = null;
|
||||
List<IMetadataTable> metadatas = node.getMetadataList();
|
||||
if(metadatas !=null && metadatas.size()>0){
|
||||
IMetadataTable metadata = metadatas.get(0);
|
||||
if(metadata != null){
|
||||
columnList = metadata.getListColumns();
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
java.sql.PreparedStatement pstmt_<%=cid %> =null;
|
||||
|
||||
<%
|
||||
|
||||
if(columnList != null && columnList.size()>0){
|
||||
|
||||
class Column{
|
||||
|
||||
IMetadataColumn column;
|
||||
|
||||
String name;
|
||||
|
||||
String sqlStmt;
|
||||
|
||||
String value;
|
||||
|
||||
boolean addCol;
|
||||
|
||||
List<Column> replacement = new ArrayList<Column>();
|
||||
|
||||
public Column(IMetadataColumn column){
|
||||
this.column = column;
|
||||
String columname = column.getOriginalDbColumnName();
|
||||
if(columname!=null && columname.trim().length()>0){
|
||||
this.name = columname;
|
||||
}else{
|
||||
this.name = column.getLabel();
|
||||
}
|
||||
this.sqlStmt = "=?";
|
||||
this.value = "?";
|
||||
this.addCol =false;
|
||||
}
|
||||
|
||||
public boolean isReplaced(){
|
||||
return replacement.size()>0;
|
||||
}
|
||||
|
||||
public List<Column> getReplacement(){
|
||||
return this.replacement;
|
||||
}
|
||||
|
||||
public IMetadataColumn getColumn(){
|
||||
return this.column;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isAddCol(){
|
||||
return this.addCol;
|
||||
}
|
||||
|
||||
public String getSqlStmt(){
|
||||
return this.sqlStmt;
|
||||
}
|
||||
|
||||
public String getValue(){
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder insertColName = new StringBuilder();
|
||||
StringBuilder insertValueStmt = new StringBuilder();
|
||||
StringBuilder updateSetStmt = new StringBuilder();
|
||||
StringBuilder updateWhereStmt = new StringBuilder();
|
||||
List<Column> stmtStructure = new LinkedList<Column>();
|
||||
|
||||
for(IMetadataColumn column:columnList){
|
||||
stmtStructure.add(new Column(column));
|
||||
}
|
||||
|
||||
int counterOuter =0;
|
||||
boolean firstKey = true;
|
||||
boolean firstNoneKey = true;
|
||||
|
||||
for(Column colStmt:stmtStructure){
|
||||
String suffix = ",";
|
||||
|
||||
if(colStmt.isReplaced()){
|
||||
List<Column> replacedColumns = colStmt.getReplacement();
|
||||
int counterReplace = 0;
|
||||
if(counterOuter==(stmtStructure.size()-1) && counterReplace==(replacedColumns.size()-1) ){
|
||||
suffix = "";
|
||||
}
|
||||
for(Column replacement:replacedColumns){
|
||||
insertColName.append(replacement.getName()+suffix);
|
||||
insertValueStmt.append(replacement.getSqlStmt()+suffix);
|
||||
if(!colStmt.getColumn().isKey()){
|
||||
if(!firstNoneKey){
|
||||
updateSetStmt.append(",");
|
||||
}else{
|
||||
firstNoneKey = false;
|
||||
}
|
||||
updateSetStmt.append(replacement.getName());
|
||||
updateSetStmt.append(replacement.getSqlStmt());
|
||||
}else{
|
||||
if(!firstKey){
|
||||
updateWhereStmt.append(" AND ");
|
||||
}else{
|
||||
firstKey = false;
|
||||
}
|
||||
updateWhereStmt.append(replacement.getName());
|
||||
updateWhereStmt.append(replacement.getSqlStmt());
|
||||
}
|
||||
counterReplace++;
|
||||
}
|
||||
}else{
|
||||
if(counterOuter==(stmtStructure.size()-1)){
|
||||
suffix = "";
|
||||
}
|
||||
if(colStmt.isAddCol()){
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getSqlStmt()+suffix);
|
||||
updateSetStmt.append(colStmt.getName());
|
||||
updateSetStmt.append(colStmt.getSqlStmt()+suffix);
|
||||
}else{
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getValue()+suffix);
|
||||
updateSetStmt.append(colStmt.getName()+"=(\"+select_query_"+ cid +".replaceFirst(java.util.regex.Pattern.quote(selectQueryColumnsName_"+ cid +"),routines.system.StringUtils.splitSQLColumns(selectQueryColumnsName_"+ cid +")[ "+ counterOuter + "])+\")" +suffix);
|
||||
}
|
||||
}
|
||||
counterOuter ++;
|
||||
}
|
||||
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
String insertQuery_<%=cid %> = "INSERT INTO "+tableName_<%=cid%>+" (<%=insertColName.toString()%>) ("+select_query_<%=cid %>+")";
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(insertQuery_<%=cid %>);
|
||||
<%
|
||||
} else if (("UPDATE").equals(dataAction)) {
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> "
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+ select_query_<%=cid %>.replaceAll(selectQueryColumnsName_<%=cid %>, "*")+") "
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
int nb_line_<%=cid%> = 0;
|
||||
int nb_line_updated_<%=cid%> = 0;
|
||||
int nb_line_inserted_<%=cid%> = 0;
|
||||
int nb_line_deleted_<%=cid%> = 0;
|
||||
<%
|
||||
|
||||
}
|
||||
|
||||
if(dbtable != null && columnList != null){
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Inserting with : \n" + insertQuery_<%=cid %> + "\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+insertQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_inserted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_inserted_<%=cid%> + " rows inserted. \n");
|
||||
<%
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_updated_<%=cid%> + " rows updated. \n");
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_deleted_<%=cid%> + " rows deleted. \n");
|
||||
<%
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
|
||||
|
||||
%>
|
||||
pstmt_<%=cid %>.close();
|
||||
|
||||
<%
|
||||
if(!useExistingConn) {
|
||||
%>
|
||||
if(conn_<%=cid%> != null && !conn_<%=cid%>.isClosed()) {
|
||||
<%log4jCodeGenerateUtil.close(node);%>
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
globalMap.put("<%=cid %>_NB_LINE",nb_line_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_UPDATED",nb_line_updated_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_INSERTED",nb_line_inserted_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_DELETED",nb_line_deleted_<%=cid%>);
|
||||
|
||||
<%
|
||||
if(isLog4jEnabled){
|
||||
Map<String,String> actionMap=new java.util.HashMap<String,String>();
|
||||
actionMap.put("INSERT","inserted");
|
||||
actionMap.put("UPDATE","updated");
|
||||
actionMap.put("DELETE","deleted");
|
||||
%>
|
||||
log.info("<%=cid%> - Has <%=actionMap.get(dataAction)%> records count: " + nb_line_<%=actionMap.get(dataAction)%>_<%=cid%> + ".");
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
java.sql.Connection conn_<%=cid%> = null;
|
||||
<%
|
||||
log4jCodeGenerateUtil.debugConnectionParams(node);
|
||||
log4jCodeGenerateUtil.connect(node);
|
||||
}
|
||||
%>
|
||||
|
||||
<%
|
||||
List<IMetadataColumn> columnList = null;
|
||||
List<IMetadataTable> metadatas = node.getMetadataList();
|
||||
if(metadatas !=null && metadatas.size()>0){
|
||||
IMetadataTable metadata = metadatas.get(0);
|
||||
if(metadata != null){
|
||||
columnList = metadata.getListColumns();
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
java.sql.PreparedStatement pstmt_<%=cid %> =null;
|
||||
|
||||
<%
|
||||
|
||||
if(columnList != null && columnList.size()>0){
|
||||
|
||||
class Column{
|
||||
|
||||
IMetadataColumn column;
|
||||
|
||||
String name;
|
||||
|
||||
String sqlStmt;
|
||||
|
||||
String value;
|
||||
|
||||
boolean addCol;
|
||||
|
||||
List<Column> replacement = new ArrayList<Column>();
|
||||
|
||||
public Column(IMetadataColumn column){
|
||||
this.column = column;
|
||||
String columname = column.getOriginalDbColumnName();
|
||||
if(columname!=null && columname.trim().length()>0){
|
||||
this.name = columname;
|
||||
}else{
|
||||
this.name = column.getLabel();
|
||||
}
|
||||
this.sqlStmt = "=?";
|
||||
this.value = "?";
|
||||
this.addCol =false;
|
||||
}
|
||||
|
||||
public boolean isReplaced(){
|
||||
return replacement.size()>0;
|
||||
}
|
||||
|
||||
public List<Column> getReplacement(){
|
||||
return this.replacement;
|
||||
}
|
||||
|
||||
public IMetadataColumn getColumn(){
|
||||
return this.column;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isAddCol(){
|
||||
return this.addCol;
|
||||
}
|
||||
|
||||
public String getSqlStmt(){
|
||||
return this.sqlStmt;
|
||||
}
|
||||
|
||||
public String getValue(){
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder insertColName = new StringBuilder();
|
||||
StringBuilder insertValueStmt = new StringBuilder();
|
||||
StringBuilder updateSetStmt = new StringBuilder();
|
||||
StringBuilder updateWhereStmt = new StringBuilder();
|
||||
List<Column> stmtStructure = new LinkedList<Column>();
|
||||
|
||||
for(IMetadataColumn column:columnList){
|
||||
stmtStructure.add(new Column(column));
|
||||
}
|
||||
|
||||
int counterOuter =0;
|
||||
boolean firstKey = true;
|
||||
boolean firstNoneKey = true;
|
||||
|
||||
for(Column colStmt:stmtStructure){
|
||||
String suffix = ",";
|
||||
|
||||
if(colStmt.isReplaced()){
|
||||
List<Column> replacedColumns = colStmt.getReplacement();
|
||||
int counterReplace = 0;
|
||||
if(counterOuter==(stmtStructure.size()-1) && counterReplace==(replacedColumns.size()-1) ){
|
||||
suffix = "";
|
||||
}
|
||||
for(Column replacement:replacedColumns){
|
||||
insertColName.append(replacement.getName()+suffix);
|
||||
insertValueStmt.append(replacement.getSqlStmt()+suffix);
|
||||
if(!colStmt.getColumn().isKey()){
|
||||
if(!firstNoneKey){
|
||||
updateSetStmt.append(",");
|
||||
}else{
|
||||
firstNoneKey = false;
|
||||
}
|
||||
updateSetStmt.append(replacement.getName());
|
||||
updateSetStmt.append(replacement.getSqlStmt());
|
||||
}else{
|
||||
if(!firstKey){
|
||||
updateWhereStmt.append(" AND ");
|
||||
}else{
|
||||
firstKey = false;
|
||||
}
|
||||
updateWhereStmt.append(replacement.getName());
|
||||
updateWhereStmt.append(replacement.getSqlStmt());
|
||||
}
|
||||
counterReplace++;
|
||||
}
|
||||
}else{
|
||||
if(counterOuter==(stmtStructure.size()-1)){
|
||||
suffix = "";
|
||||
}
|
||||
if(colStmt.isAddCol()){
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getSqlStmt()+suffix);
|
||||
updateSetStmt.append(colStmt.getName());
|
||||
updateSetStmt.append(colStmt.getSqlStmt()+suffix);
|
||||
}else{
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getValue()+suffix);
|
||||
updateSetStmt.append(colStmt.getName()+"=(\"+select_query_"+ cid +".replaceFirst(java.util.regex.Pattern.quote(selectQueryColumnsName_"+ cid +"),routines.system.StringUtils.splitSQLColumns(selectQueryColumnsName_"+ cid +")[ "+ counterOuter + "])+\")" +suffix);
|
||||
}
|
||||
}
|
||||
counterOuter ++;
|
||||
}
|
||||
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
String insertQuery_<%=cid %> = "INSERT INTO "+tableName_<%=cid%>+" (<%=insertColName.toString()%>) ("+select_query_<%=cid %>+")";
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(insertQuery_<%=cid %>);
|
||||
<%
|
||||
} else if (("UPDATE").equals(dataAction)) {
|
||||
%>
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> ");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+ select_query_<%=cid %>.replaceAll(selectQueryColumnsName_<%=cid %>, "*")+") ");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
<%
|
||||
}
|
||||
%>
|
||||
int nb_line_<%=cid%> = 0;
|
||||
int nb_line_updated_<%=cid%> = 0;
|
||||
int nb_line_inserted_<%=cid%> = 0;
|
||||
int nb_line_deleted_<%=cid%> = 0;
|
||||
<%
|
||||
|
||||
}
|
||||
|
||||
if(dbtable != null && columnList != null){
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Inserting with : \n" + insertQuery_<%=cid %> + "\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+insertQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_inserted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_inserted_<%=cid%> + " rows inserted. \n");
|
||||
<%
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_updated_<%=cid%> + " rows updated. \n");
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
System.out.println("--> " + nb_line_deleted_<%=cid%> + " rows deleted. \n");
|
||||
<%
|
||||
}
|
||||
}
|
||||
|
||||
// END
|
||||
|
||||
|
||||
%>
|
||||
pstmt_<%=cid %>.close();
|
||||
|
||||
<%
|
||||
if(!useExistingConn) {
|
||||
%>
|
||||
if(conn_<%=cid%> != null && !conn_<%=cid%>.isClosed()) {
|
||||
<%log4jCodeGenerateUtil.close(node);%>
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
globalMap.put("<%=cid %>_NB_LINE",nb_line_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_UPDATED",nb_line_updated_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_INSERTED",nb_line_inserted_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_LINE_DELETED",nb_line_deleted_<%=cid%>);
|
||||
|
||||
<%
|
||||
if(isLog4jEnabled){
|
||||
Map<String,String> actionMap=new java.util.HashMap<String,String>();
|
||||
actionMap.put("INSERT","inserted");
|
||||
actionMap.put("UPDATE","updated");
|
||||
actionMap.put("DELETE","deleted");
|
||||
%>
|
||||
log.info("<%=cid%> - Has <%=actionMap.get(dataAction)%> records count: " + nb_line_<%=actionMap.get(dataAction)%>_<%=cid%> + ".");
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
@@ -41,6 +41,22 @@ WHERE_CLAUSE.NAME=Where clauses \n(for UPDATE and DELETE only)
|
||||
ELT_TABLE_NAME.NAME=Default Table Name
|
||||
ELT_SCHEMA_NAME.NAME=Default Schema Name
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
|
||||
NB_LINE_UPDATED.NAME=Number Of Updated Lines
|
||||
NB_LINE_INSERTED.NAME=Number Of Inserted Lines
|
||||
NB_LINE_DELETED.NAME=Number Of Deleted Lines
|
||||
|
||||
@@ -55,15 +55,41 @@
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="10"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="12"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER
|
||||
NAME="ELT_TABLE_NAME"
|
||||
FIELD="TEXT"
|
||||
NUM_ROW="10"
|
||||
NUM_ROW="13"
|
||||
>
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
@@ -10,7 +10,7 @@ imports="
|
||||
org.talend.commons.utils.generation.CodeGenerationUtils
|
||||
java.util.List
|
||||
java.util.LinkedList
|
||||
java.util.StringJoiner
|
||||
java.util.StringJoiner
|
||||
java.util.Map;
|
||||
"
|
||||
%>
|
||||
@@ -111,8 +111,9 @@ imports="
|
||||
queryBandList = (List<Map<String,String>>)ElementParameterParser.getObjectValue(previousNode, "__QUERY_BAND_PARAMETERS__");
|
||||
}
|
||||
|
||||
boolean useWhereTable = ("true").equals(ElementParameterParser.getValue(previousNode, "__USE_WHERE_CONDITIONS_TABLE__"));
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
|
||||
List<Map<String, String>> whereConditions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__WHERE_CONDITIONS_TABLE__");
|
||||
%>
|
||||
|
||||
<%
|
||||
@@ -247,31 +248,31 @@ for(IMetadataColumn column:columnList){
|
||||
}
|
||||
|
||||
int counterOuter =0;
|
||||
List<Map<String, String>> setColumns = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__SET_COLUMN__");
|
||||
boolean isUpdate = "UPDATE".equals(dataAction);
|
||||
String suffix = ",";
|
||||
StringJoiner updateSetStmt = new StringJoiner(suffix);
|
||||
List<Map<String, String>> setColumns = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__SET_COLUMN__");
|
||||
boolean isUpdate = "UPDATE".equals(dataAction);
|
||||
String suffix = ",";
|
||||
StringJoiner updateSetStmt = new StringJoiner(suffix);
|
||||
for(Column colStmt:stmtStructure){
|
||||
if(counterOuter==(stmtStructure.size()-1)){
|
||||
suffix = "";
|
||||
}
|
||||
boolean isUpdateColumn = "true".equals(setColumns.get(counterOuter).get("UPDATE_COLUMN"));
|
||||
boolean isUpdateColumn = "true".equals(setColumns.get(counterOuter).get("UPDATE_COLUMN"));
|
||||
if(colStmt.isAddCol()){
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getSqlStmt()+suffix);
|
||||
if (isUpdate && isUpdateColumn) {
|
||||
updateSetStmt.add(colStmt.getName() + colStmt.getSqlStmt());
|
||||
}
|
||||
if (isUpdate && isUpdateColumn) {
|
||||
updateSetStmt.add(colStmt.getName() + colStmt.getSqlStmt());
|
||||
}
|
||||
}else{
|
||||
insertColName.append(colStmt.getName()+suffix);
|
||||
insertValueStmt.append(colStmt.getValue()+suffix);
|
||||
if (isUpdate && isUpdateColumn) {
|
||||
updateSetStmt.add(
|
||||
if (isUpdate && isUpdateColumn) {
|
||||
updateSetStmt.add(
|
||||
colStmt.getName()
|
||||
+ "= \"+ strUtil_"
|
||||
+ cid
|
||||
+ ".transform(routines.system.StringUtils.splitSQLColumns(selectQueryColumnsName_"+ cid +")[" + counterOuter + "]) +\"");
|
||||
}
|
||||
+ ".transform(routines.system.StringUtils.splitSQLColumns(selectQueryColumnsName_"+ cid +")[" + counterOuter + "]) +\"");
|
||||
}
|
||||
}
|
||||
counterOuter ++;
|
||||
}
|
||||
@@ -290,38 +291,65 @@ try{
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"error",cid+" - Fail to create PreparedStatement with SQL: \"+insertQuery_"+ cid +"+\"");%>
|
||||
throw e;
|
||||
}
|
||||
<%
|
||||
<%
|
||||
}else if (("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
%>
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE "+tableName_<%=cid%>+" FROM (" + select_query_<%=cid %> + ") src SET <%=updateSetStmt.toString()%>");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {%>
|
||||
updateQuery_<%=cid %>.append(" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
updateQuery_<%=cid %>.append(" WHERE ");
|
||||
<%
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
<%
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
try{
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
} catch (Exception e){
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"error",cid+" - Fail to create PreparedStatement with SQL: \"+updateQuery_"+ cid +"+\"");%>
|
||||
throw e;
|
||||
}
|
||||
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" FROM (" + select_query_<%=cid %> + ") src SET <%=updateSetStmt.toString()%>"
|
||||
<%if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {%>
|
||||
+" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%}%>
|
||||
;
|
||||
try{
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
} catch (Exception e){
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"error",cid+" - Fail to create PreparedStatement with SQL: \"+updateQuery_"+ cid +"+\"");%>
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
<%
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") "
|
||||
<%if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%}%>
|
||||
;
|
||||
try {
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
} catch (Exception e){
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"error",cid+" - Fail to create PreparedStatement with SQL: \"+deleteQuery_"+ cid +"+\"");%>
|
||||
throw e;
|
||||
}
|
||||
%>
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") ");
|
||||
<%
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
try {
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
} catch (Exception e){
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"error",cid+" - Fail to create PreparedStatement with SQL: \"+deleteQuery_"+ cid +"+\"");%>
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
<%
|
||||
@@ -353,7 +381,7 @@ if(dbtable != null && columnList != null){
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");
|
||||
try{
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL: \"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
@@ -367,7 +395,7 @@ if(dbtable != null && columnList != null){
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString +"\n");
|
||||
try{
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL: \"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
|
||||
@@ -41,6 +41,22 @@ USER.NAME=Username
|
||||
WHERE_CLAUSE.NAME=Where clauses \n(for UPDATE and DELETE only)
|
||||
ELT_TABLE_NAME.NAME=Default Table Name
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
|
||||
SET_COLUMN.ITEM.UPDATE_COLUMN=Update column
|
||||
SET_COLUMN.NAME=Clause SET
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
<PARAMETER
|
||||
NAME="DATA_ACTION"
|
||||
FIELD="CLOSED_LIST"
|
||||
NUM_ROW="6"
|
||||
NUM_ROW="2"
|
||||
>
|
||||
<ITEMS DEFAULT="INSERT">
|
||||
<ITEM NAME="INSERT" VALUE="INSERT" />
|
||||
@@ -52,15 +52,41 @@
|
||||
<PARAMETER
|
||||
NAME="SCHEMA"
|
||||
FIELD="SCHEMA_TYPE"
|
||||
NUM_ROW="7"
|
||||
NUM_ROW="3"
|
||||
>
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="8"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<PARAMETER NAME="USE_WHERE_CONDITIONS_TABLE" FIELD="CHECK" NUM_ROW="6"
|
||||
SHOW_IF="(DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CLAUSE" FIELD="MEMO" NUM_ROW="7"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="WHERE_CONDITIONS_TABLE" FIELD="TABLE" NUM_ROW="8"
|
||||
SHOW_IF="((DATA_ACTION == 'UPDATE') OR (DATA_ACTION == 'DELETE')) AND (USE_WHERE_CONDITIONS_TABLE == 'true')">
|
||||
<ITEMS>
|
||||
<ITEM NAME="COLUMN" VALUE='""'/>
|
||||
<ITEM NAME="FUNCTION" FIELD="CLOSED_LIST">
|
||||
<ITEMS DEFAULT="EQUAL">
|
||||
<ITEM NAME="EQUAL" VALUE=""=""/>
|
||||
<ITEM NAME="GREATER" VALUE="">""/>
|
||||
<ITEM NAME="LESS" VALUE=""<""/>
|
||||
<ITEM NAME="GREATER_OR_EQUAL" VALUE="">=""/>
|
||||
<ITEM NAME="LESS_OR_EQUAL" VALUE=""<=""/>
|
||||
<ITEM NAME="NOT_EQUAL" VALUE=""<>""/>
|
||||
<ITEM NAME="BETWEEN" VALUE=""BETWEEN""/>
|
||||
<ITEM NAME="LIKE" VALUE=""LIKE""/>
|
||||
<ITEM NAME="IN" VALUE=""IN""/>
|
||||
</ITEMS>
|
||||
</ITEM>
|
||||
<ITEM NAME="VALUE_SQL" VALUE='""'/>
|
||||
</ITEMS>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER
|
||||
NAME="ELT_TABLE_NAME"
|
||||
|
||||
@@ -81,7 +81,9 @@ imports="
|
||||
dbproperties = ElementParameterParser.getValue(previousNode, "__PROPERTIES__");
|
||||
}
|
||||
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
boolean useWhereTable = ("true").equals(ElementParameterParser.getValue(node, "__USE_WHERE_CONDITIONS_TABLE__"));
|
||||
String whereClause = ElementParameterParser.getValue(node, "__WHERE_CLAUSE__");
|
||||
List<Map<String, String>> whereConditions = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__WHERE_CONDITIONS_TABLE__");
|
||||
|
||||
if(useExistingConn) {
|
||||
String connection = ElementParameterParser.getValue(previousNode, "__CONNECTION__");
|
||||
@@ -293,30 +295,50 @@ imports="
|
||||
<%
|
||||
} else if (("UPDATE").equals(dataAction)) {
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE " + info_<%=cid%> + " "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> "
|
||||
StringBuffer updateQuery_<%=cid %> = new StringBuffer("UPDATE " + info_<%=cid%> + " "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> ");
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
updateQuery_<%=cid %>.append(" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
updateQuery_<%=cid %>.append(<%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>.toString());
|
||||
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
String deleteQuery_<%=cid %> = "DELETE " + info_<%=cid%> + " FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+ select_query_<%=cid %>.replaceAll(selectQueryColumnsName_<%=cid %>, "*")+") "
|
||||
StringBuffer deleteQuery_<%=cid %> = new StringBuffer("DELETE " + info_<%=cid%> + " FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+ select_query_<%=cid %>.replaceAll(selectQueryColumnsName_<%=cid %>, "*")+") ");
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
if(!useWhereTable) {
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>);
|
||||
<%
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(Map<String, String> whereCondition : whereConditions) {
|
||||
String column_condition = whereCondition.get("COLUMN");
|
||||
String function_condition = whereCondition.get("FUNCTION");
|
||||
String value_condition = whereCondition.get("VALUE_SQL");
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
deleteQuery_<%=cid %>.append(" AND " + <%=column_condition %> + " " + <%=function_condition %> + " " + <%=value_condition %> + " ");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>.toString());
|
||||
<%
|
||||
}
|
||||
%>
|
||||
@@ -338,7 +360,7 @@ imports="
|
||||
<%
|
||||
}else if(("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %> +"\n");
|
||||
System.out.println("Updating with : \n" + updateQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+updateQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_updated_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
@@ -346,7 +368,7 @@ imports="
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %> +"\n");
|
||||
System.out.println("Deleting with : \n" + deleteQuery_<%=cid %>.toString() +"\n");
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executing SQL:\"+deleteQuery_"+ cid +"+\"");%>
|
||||
nb_line_<%=cid%> += nb_line_deleted_<%=cid%> = pstmt_<%=cid %>.executeUpdate();
|
||||
<%log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Executed successfully.");%>
|
||||
|
||||
@@ -41,6 +41,22 @@ WHERE_CLAUSE.NAME=Where clauses \n(for UPDATE and DELETE only)
|
||||
ELT_TABLE_NAME.NAME=Default Table Name
|
||||
ELT_SCHEMA_NAME.NAME=Default Schema Name
|
||||
|
||||
USE_WHERE_CONDITIONS_TABLE.NAME=Use WHERE conditions table
|
||||
|
||||
WHERE_CONDITIONS_TABLE.NAME=WHERE conditions table \n(for UPDATE and DELETE only)
|
||||
WHERE_CONDITIONS_TABLE.ITEM.COLUMN=Column
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION=Function
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.EQUAL==
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER=>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS=<
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.GREATER_OR_EQUAL=>=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LESS_OR_EQUAL=<=
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.NOT_EQUAL=<>
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.BETWEEN=BETWEEN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.LIKE=LIKE
|
||||
WHERE_CONDITIONS_TABLE.ITEM.FUNCTION.ITEM.IN=IN
|
||||
WHERE_CONDITIONS_TABLE.ITEM.VALUE_SQL=Value
|
||||
|
||||
NB_LINE_UPDATED.NAME=Number Of Updated Lines
|
||||
NB_LINE_INSERTED.NAME=Number Of Inserted Lines
|
||||
NB_LINE_DELETED.NAME=Number Of Deleted Lines
|
||||
|
||||
Reference in New Issue
Block a user