-
Notifications
You must be signed in to change notification settings - Fork 16
/
ExternalDataD.java
executable file
·187 lines (163 loc) · 4.74 KB
/
ExternalDataD.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import java.sql.*;
import java.net.*;
import java.io.*;
public class ExternalDataD
{
private static String myclass = "ExternalDataD";
public static boolean debug = true;
public static String configFile = "";
public static String dbVersion = "GPDB";
public static void main(String[] args) throws Exception
{
String method = "main";
int location = 1000;
int argsCount = args.length;
Connection conn = null;
configFile = args[0];
String action = args[1];
location = 2000;
try
{
location = 3000;
if (action.equals("start"))
{
conn = CommonDB.connectGP(configFile);
GP.cancelJobs(conn);
dbVersion = GP.getVersion(conn);
conn.close();
loadLoop();
}
else if (action.equals("stop"))
{
conn = CommonDB.connectGP(configFile);
GP.failJobs(conn);
GP.cancelJobs(conn);
conn.close();
}
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
finally
{
if (conn != null)
conn.close();
}
}
private static void loadLoop() throws Exception
{
String method = "loadLoop";
int location = 1000;
Connection conn = null;
boolean loop = true;
while (loop)
{
try
{
location = 2000;
ResultSet rs;
Statement stmt;
String strSQL = "";
int queueId = 0;
Timestamp queueDate = new Timestamp((new java.util.Date()).getTime());
Timestamp startDate = new Timestamp((new java.util.Date()).getTime());
int numRows = 0;
int id = 0;
String refreshType = "";
String targetSchema = "";
String targetTable = "";
boolean targetAppendOnly = false;
boolean targetCompressed = false;
boolean targetRowOrientation = true;
String sourceType = "";
String sourceServer = "";
String sourceInstance = "";
int sourcePort = 0;
String sourceDatabase = "";
String sourceSchema = "";
String sourceTable = "";
String sourceUser = "";
String sourcePass = "";
String columnName = "";
String sqlText = "";
boolean snapshot = false;
location = 3000;
conn = CommonDB.connectGP(configFile);
location = 3100;
strSQL = "SELECT queue_id, queue_date, start_date,\n";
strSQL += " id, refresh_type, LOWER(target_schema_name) as target_schema_name, LOWER(target_table_name) as target_table_name,\n";
strSQL += " target_append_only, target_compressed, target_row_orientation,\n";
strSQL += " source_type, source_server_name, source_instance_name, source_port, source_database_name, source_schema_name,\n";
strSQL += " source_table_name, source_user_name, source_pass, column_name,\n";
strSQL += " sql_text, snapshot\n";
strSQL += "FROM os.fn_update_status()";
location = 3200;
stmt = conn.createStatement();
location = 3300;
rs = stmt.executeQuery(strSQL);
//query only returns one record
while (rs.next())
{
location = 4000;
queueId = rs.getInt(1);
queueDate = rs.getTimestamp(2);
startDate = rs.getTimestamp(3);
id = rs.getInt(4);
refreshType = rs.getString(5);
targetSchema = rs.getString(6);
targetTable = rs.getString(7);
targetAppendOnly = rs.getBoolean(8);
targetCompressed = rs.getBoolean(9);
targetRowOrientation = rs.getBoolean(10);
sourceType = rs.getString(11);
sourceServer = rs.getString(12);
sourceInstance = rs.getString(13);
sourcePort = rs.getInt(14);
sourceDatabase = rs.getString(15);
sourceSchema = rs.getString(16);
sourceTable = rs.getString(17);
sourceUser = rs.getString(18);
sourcePass = rs.getString(19);
columnName = rs.getString(20);
sqlText = rs.getString(21);
snapshot = rs.getBoolean(22);
}
location = 4100;
if (conn != null)
conn.close();
location = 4200;
if (id != 0)
{
location = 5000;
if (debug)
Logger.printMsg("Thread working on ID: " + id);
ExternalDataThread edt = new ExternalDataThread(queueId, queueDate, startDate, id, refreshType, targetSchema, targetTable, targetAppendOnly, targetCompressed, targetRowOrientation, sourceType, sourceServer, sourceInstance, sourcePort, sourceDatabase, sourceSchema, sourceTable, sourceUser, sourcePass, columnName, sqlText, snapshot);
location = 5100;
if (debug)
Logger.printMsg("Thread is initialized");
Thread t = new Thread(edt);
location = 5200;
if (debug)
Logger.printMsg("Thread started");
t.start();
}
else
{
location = 6000;
Thread.sleep(5000);
}
}
catch (SQLException ex)
{
Logger.printMsg("(" + method + ":" + location + ":" + ex.getMessage() + ")");
Thread.sleep(5000);
}
finally
{
if (conn != null)
conn.close();
}
}
}
}