forked from haeusler/tMongoDBConnection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtMongoDBConnection_begin.javajet
42 lines (39 loc) · 1.6 KB
/
tMongoDBConnection_begin.javajet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<%@ jet
imports="
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.core.model.process.IConnectionCategory
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.core.model.metadata.types.JavaTypesManager
org.talend.core.model.metadata.types.JavaType
java.util.List
java.util.Map
"
%>
<%
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
INode node = (INode)codeGenArgument.getArgument();
String cid = node.getUniqueName();
String dbhost = ElementParameterParser.getValue(node, "__HOST__");
String dbname = ElementParameterParser.getValue(node, "__DATABASE__");
String dbuser = ElementParameterParser.getValue(node, "__USERNAME__");
String dbpass = ElementParameterParser.getValue(node, "__PASSWORD__");
Integer dbport = new Integer(ElementParameterParser.getValue(node, "__PORT__"));
String writeConcern = ElementParameterParser.getValue(node, "__WRITE_CONCERN__");
%>
com.mongodb.Mongo mongo_<%=cid%> = new com.mongodb.Mongo(<%=dbhost%>, <%=dbport%>);
mongo_<%=cid%>.setWriteConcern(com.mongodb.WriteConcern.<%=writeConcern%>);
com.mongodb.DB db_<%=cid%> = mongo_<%=cid%>.getDB(<%=dbname%>);
globalMap.put("mongo_<%=cid%>", mongo_<%=cid%>);
globalMap.put("db_<%=cid%>", db_<%=cid%>);
<%
if ((dbuser.length() > 0) && (dbpass.length() > 0))
{
%>
db_<%=cid%>.authenticate(<%=dbuser%>, <%=dbpass%>);
<%
}
%>