Dsylaiev/tdi 35682 add logging when use existing connection (#1571)

* fix(TDI-35682): Add logging into tRedshiftConnection

* Input component won't create and close logfile when using existing connection

* Close component will close logwriter stream also

* chore(TDI-35682): fix indentation
This commit is contained in:
Dmytro Sylaiev
2017-07-28 12:46:34 +03:00
committed by GitHub
parent e19c349c0b
commit c660e00a20
6 changed files with 60 additions and 16 deletions

View File

@@ -1 +1,5 @@
<%@ include file="../templates/DB/Close/AbstractDBClose.javajet"%>
<%@ include file="../templates/DB/Close/AbstractDBClose.javajet"%>
if (null != java.sql.DriverManager.getLogWriter()) {
java.sql.DriverManager.getLogWriter().close();
}

View File

@@ -11,16 +11,28 @@ imports="
public void createURL(INode node) {
super.createURL(node);
if(dbproperties == null || ("\"\"").equals(dbproperties) || ("").equals(dbproperties)) {
%>
String url_<%=cid %> = "jdbc:redshift://"+<%=dbhost%>+":"+<%=dbport%>+"/"+<%=dbname%>;
<%
} else {
%>
String url_<%=cid%> = "jdbc:redshift://" + <%=dbhost%> + ":" + <%=dbport%> + "/" + <%=dbname%> + "?" + <%=dbproperties%>;
<%
}
String logLevel= ElementParameterParser.getValue(node, "__LOG_LEVEL__");
String logFile= ElementParameterParser.getValue(node, "__LOG_FILE__");
if (!logLevel.equals("0")) {
%>
java.io.Writer output_<%=cid %> = new java.io.FileWriter(<%= logFile %>, true);
java.sql.DriverManager.setLogWriter(new java.io.PrintWriter(output_<%=cid %>,true));
<%
}
%>
StringBuilder sbuilder_<%=cid%> = new StringBuilder();
sbuilder_<%=cid%>.append("jdbc:redshift://").append(<%=dbhost%>).append(":").append(<%=dbport%>).append("/").append(<%=dbname%>).append("?loglevel=").append(<%= logLevel %>);
<%
if(dbproperties != null && !"\"\"".equals(dbproperties) && !"".equals(dbproperties)) {
%>
sbuilder_<%=cid%>.append("&").append(<%=dbproperties%>);
<%
}
%>
String url_<%=cid%> = sbuilder_<%=cid%>.toString();
<%
}
public String getDirverClassName(INode node){
@@ -33,7 +45,6 @@ imports="
<%//----------------------------component codes-----------------------------------------%>
<%@ include file="../templates/DB/AbstractDBConnection.javajet"%>
globalMap.put("schema_" + "<%=cid%>",<%=dbschema%>);
globalMap.put("conn_" + "<%=cid%>",conn_<%=cid%>);

View File

@@ -152,6 +152,23 @@
</PARAMETERS>
<ADVANCED_PARAMETERS>
<PARAMETER
NAME="LOG_FILE"
FIELD="FILE"
NUM_ROW="10"
REQUIRED="true"
>
<DEFAULT>"__COMP_DEFAULT_FILE_DIR__/redshift-jdbc.log"</DEFAULT>
</PARAMETER>
<PARAMETER NAME="LOG_LEVEL" FIELD="CLOSED_LIST" NUM_ROW="12">
<ITEMS DEFAULT="INFO">
<ITEM NAME="NONE" VALUE="0" />
<ITEM NAME="INFO" VALUE="1" />
<ITEM NAME="DEBUG" VALUE="2" />
</ITEMS>
</PARAMETER>
<PARAMETER NAME="AUTO_COMMIT" FIELD="CHECK" NUM_ROW="10">
<DEFAULT>false</DEFAULT>
</PARAMETER>

View File

@@ -16,4 +16,9 @@ AUTO_COMMIT.NAME = Auto Commit
TYPE.NAME=Database Driver
PROPERTY.NAME=Property Type
LOG_FILE.NAME=Log file
LOG_LEVEL.NAME=Logging level
LOG_LEVEL.ITEM.NONE=None
LOG_LEVEL.ITEM.INFO=Info
LOG_LEVEL.ITEM.DEBUG=Debug
PROPERTIES.NAME=Additional JDBC Parameters

View File

@@ -1,5 +1,11 @@
<%@ include file="../templates/DB/Input/AbstractDBInputEnd.javajet"%>
if (null != java.sql.DriverManager.getLogWriter()) {
java.sql.DriverManager.getLogWriter().close();
}
<%
if ("false".equalsIgnoreCase(ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__"))) {
%>
if (null != java.sql.DriverManager.getLogWriter()) {
java.sql.DriverManager.getLogWriter().close();
}
<%
}
%>

View File

@@ -203,11 +203,12 @@
FIELD="FILE"
NUM_ROW="10"
REQUIRED="true"
SHOW_IF="USE_EXISTING_CONNECTION == 'false'"
>
<DEFAULT>"__COMP_DEFAULT_FILE_DIR__/redshift-jdbc.log"</DEFAULT>
</PARAMETER>
<PARAMETER NAME="LOG_LEVEL" FIELD="CLOSED_LIST" NUM_ROW="12">
<PARAMETER NAME="LOG_LEVEL" FIELD="CLOSED_LIST" NUM_ROW="12" SHOW_IF="USE_EXISTING_CONNECTION == 'false'">
<ITEMS DEFAULT="INFO">
<ITEM NAME="NONE" VALUE="0" />
<ITEM NAME="INFO" VALUE="1" />