Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .project
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>yanbasic_code_1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>yanbasic_code_1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
245 changes: 245 additions & 0 deletions T1.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,252 @@
<<<<<<< HEAD
<%@ jet
imports="
org.talend.core.model.process.INode
org.talend.core.model.process.ElementParameterParser
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.designer.codegen.config.CodeGeneratorArgument
"
%>
<%@ include file="Log4jFileUtil.javajet"%>
<%
class DefaultLog4jCodeGenerateUtil extends DefaultLog4jFileUtil{

String connection = "";
boolean hasInit = false;
String dataAction ;
String dataOperationPrefix;
String useBatchSize;
String batchSize;
String dbSchema;
boolean logCommitCounter = false;

public DefaultLog4jCodeGenerateUtil(){
}

public DefaultLog4jCodeGenerateUtil(INode node) {
super(node);
init();
}

public void beforeComponentProcess(INode node){
this.node = node;
init();
}

private void init() {
if(hasInit){
return;
}
this.cid = node.getUniqueName();
this.isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
String useConn = ElementParameterParser.getValue(node,"__USE_EXISTING_CONNECTION__");
if(useConn == null || "".equals(useConn) || "true".equals(useConn)){
connection = ElementParameterParser.getValue(node,"__CONNECTION__");
if(!"".equals(connection)){
connection = "'" + connection+"' ";
}
}
//for output
dataAction = ElementParameterParser.getValue(node,"__DATA_ACTION__");
if(dataAction != null && !("").equals(dataAction)){
logCommitCounter=true;
}
useBatchSize = ElementParameterParser.getValue(node, "__USE_BATCH_SIZE__");
batchSize =ElementParameterParser.getValue(node, "__BATCH_SIZE__");
hasInit = true;
}

public void debugDriverClassName() {
logInfo(node,"debug",cid+" - Driver ClassName: \"+driverClass_"+cid+"+\".");
}

public void debugConnectionParams(INode node) {
beforeComponentProcess(node);
debugDriverClassName();
}

public void useExistConnection(INode node){
beforeComponentProcess(node);
if(isLog4jEnabled) {
%>
if(conn_<%=cid%> != null) {
try{
if(conn_<%=cid%>.getMetaData() != null) {
log.info("<%=cid%> - Uses an existing connection with username '" + conn_<%=cid%>.getMetaData().getUserName() + "'. Connection URL: " + conn_<%=cid%>.getMetaData().getURL() + ".");
}
}catch(java.sql.SQLException ex){
log.warn(ex.getMessage());
}
}
<%
}
}

public void connect(INode node){
beforeComponentProcess(node);
connect();
}

public void connect(){
connect_begin();
%>
conn_<%=cid%> = java.sql.DriverManager.getConnection(url_<%=cid %>, dbUser_<%=cid%>, dbPwd_<%=cid%>);
<%
connect_end();
}

public void connect_begin(){
logInfo(node,"info",cid+" - Connection attempt to '\" + url_"+cid+" + \"' with the username '\" + dbUser_"+cid+" + \"'.");
}

public void connect_begin_noUser(){
logInfo(node,"info",cid+" - Connection attempt to '\" + url_"+cid+" + \"'.");
}

public void connect_end(){
logInfo(node,"info",cid+" - Connection to '\" + url_"+cid+" + \"' has succeeded.");
}

public void rollback(INode node){
beforeComponentProcess(node);
logInfo(node,"debug",cid+" - Connection "+connection+"starting to rollback.");
%>
conn_<%=cid%>.rollback();
<%
logInfo(node,"debug",cid+" - Connection "+connection+"rollback has succeeded.");
}

public void commit(INode node){
beforeComponentProcess(node);
commit();
}

private void commit(){
commit_begin();
%>
conn_<%=cid%>.commit();
<%
commit_end();
}

private void commit_begin(){
if(logCommitCounter){
logInfo(node,"debug",cid+" - Connection "+connection+"starting to commit \" + commitCounter_"+cid+"+ \" records.");
}else{
logInfo(node,"debug",cid+" - Connection "+connection+"starting to commit.");
}
}
private void commit_end(){
logInfo(node,"debug",cid+" - Connection "+connection+"commit has succeeded.");
}

public void close(INode node){
beforeComponentProcess(node);
close();
}

private void close(){
close_begin();
%>
conn_<%=cid%>.close();
<%
close_end();
}

public void close_begin(){
logInfo(node,"info",cid+" - Closing the connection "+connection+"to the database.");
}
public void close_end(){
logInfo(node,"info",cid+" - Connection "+connection+"to the database closed.");
}

public void autoCommit(INode node,boolean autoCommit){
beforeComponentProcess(node);
logInfo(node,"debug",cid+" - Connection is set auto commit to '"+autoCommit+"'.");
%>
conn_<%=cid%>.setAutoCommit(<%=autoCommit%>);
<%
}

public void query(INode node){
beforeComponentProcess(node);
//for input
String dbquery= ElementParameterParser.getValue(node, "__QUERY__");
dbquery = dbquery.replaceAll("\n"," ");
dbquery = dbquery.replaceAll("\r"," ");
logInfo(node,"info",cid+" - Executing the query: '\" + "+dbquery +" + \"'.");
}

public void retrieveRecordsCount(INode node){
beforeComponentProcess(node);
logInfo(node,"info",cid+" - Retrieved records count: \"+nb_line_"+cid+" + \" .");
}

public void logError(INode node,String logLevel,String exception){
beforeComponentProcess(node);
if(isLog4jEnabled){
%>
log.<%=logLevel%>("<%=cid%> - " + <%=exception%>.getMessage());
<%
}
}

public void logError(INode node,String logLevel){
logError(node,logLevel,"e");
}

public void logInfo(INode node,String logLevel,String message){
beforeComponentProcess(node);
if(isLog4jEnabled){
%>
log.<%=logLevel%>("<%=message%>");
<%
}
}
/**
*batchType :
* 1: do not get return value of executeBatch();
* 2: get return value of executeBatch();
*
*/
public void executeBatch(INode node,int batchType){
beforeComponentProcess(node);
boolean logBatch = ("true").equals(useBatchSize) && !("").equals(batchSize) && !("0").equals(batchSize);
if(logBatch){
logInfo(node,"debug",cid+" - Executing the "+dataAction+" batch.");
}
if(batchType==1){
%>
pstmt_<%=cid %>.executeBatch();
<%
}else if(batchType==2){
boolean isMysqlBatchInsert = false;
if ((node.getUniqueName().contains("tMysqlOutput")||node.getUniqueName().contains("tAmazonMysqlOutput")) && ("INSERT").equals(dataAction)) {
isMysqlBatchInsert = true;
}
%>
int countSum_<%=cid%> = 0;
for(int countEach_<%=cid%>: pstmt_<%=cid %>.executeBatch()) {
countSum_<%=cid%> += (countEach_<%=cid%> < 0 ? 0 : <%=isMysqlBatchInsert? "1" : "countEach_"+cid %>);
}
<%
}
if(logBatch){
logInfo(node,"debug",cid+" - The "+dataAction+" batch execution has succeeded.");
}
}
}

DefaultLog4jCodeGenerateUtil log4jCodeGenerateUtil = new DefaultLog4jCodeGenerateUtil();
%>
=======
<%@ jet
imports="
org.talend.core.model.process.INode
org.talend.core.model.process.ElementParameterParser
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.designer.codegen.config.CodeGeneratorArgument
"
%>
<%@ include file="Log4jFileUtil.javajet"%>
Expand Down Expand Up @@ -237,3 +481,4 @@ public void executeBatch(INode node,int batchType){

DefaultLog4jCodeGenerateUtil log4jCodeGenerateUtil = new DefaultLog4jCodeGenerateUtil();
%>
>>>>>>> a766afd2d171fc43414f782616e0421a282d8ec6
26 changes: 26 additions & 0 deletions main/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions main/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>githiutools</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions main/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
5 changes: 5 additions & 0 deletions main/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
4 changes: 4 additions & 0 deletions main/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
25 changes: 25 additions & 0 deletions main/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>test.githiutools</groupId>
<artifactId>githiutools</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>githiutools</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
13 changes: 13 additions & 0 deletions main/src/main/java/test/githiutools/githiutools/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package test.githiutools.githiutools;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
Loading