-
Notifications
You must be signed in to change notification settings - Fork 16
/
QueueModel.java
171 lines (156 loc) · 7.29 KB
/
QueueModel.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
import java.util.Map;
import java.sql.*;
import java.net.*;
import java.io.*;
public class QueueModel
{
public static ResultSet getList(String search, String limit, String offset, String sortBy, String sort) throws SQLException
{
String strSQL = "SELECT queue_id,\n";
strSQL += "initcap(status) || CASE WHEN status = 'failed' THEN \n";
strSQL += " ' <button onclick=\"updateQueue(' || queue_id || ', ''update'')\">Rerun</button>' ||\n";
strSQL += " ' <button onclick=\"updateQueue(' || queue_id || ', ''delete'')\">Delete</button>'\n";
strSQL += " WHEN status = 'queued' THEN' <button onclick=\"updateQueue(' || queue_id || ', ''delete'')\">Delete</button>'\n";
strSQL += " WHEN status = 'success' THEN ' <button onclick=\"updateQueue(' || queue_id || ', ''update'')\">Rerun</button>'\n";
strSQL += " WHEN status = 'processing' THEN ' <button onclick=\"cancelQueue(' || id || ', ''cancel'')\">Cancel</button>'\n";
strSQL += " else ''\n";
strSQL += " END AS my_status,\n";
strSQL += "DATE_TRUNC('second', queue_date) AS my_queue_date, \n";
strSQL += "COALESCE((DATE_TRUNC('second', start_date))::text, '') AS my_start_date,\n";
strSQL += "COALESCE((DATE_TRUNC('second', end_date))::text, '') AS my_end_date,\n";
strSQL += "COALESCE((COALESCE(DATE_TRUNC('second', end_date), CURRENT_TIMESTAMP(0)::timestamp) - DATE_TRUNC('second', start_date))::text, '') AS duration,\n";
strSQL += "num_rows,\n";
strSQL += "'<a href=\"jobs?action_type=update&id=' || id || '\">' || id || '</a>',\n";
strSQL += "CASE WHEN refresh_type = 'transform' THEN SUBSTRING(sql_text, 1, 30)\n";
strSQL += "ELSE COALESCE((target_schema_name || '.' || target_table_name), '') END AS target_table_name,\n";
strSQL += "COALESCE(error_message, '') AS my_error_message\n";
strSQL += "FROM os.queue\n";
if (!search.equals(""))
{
strSQL += "WHERE LOWER(status) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(refresh_type) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(target_schema_name) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(target_table_name) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(source_type) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(source_server_name) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(source_instance_name) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(source_port) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(source_database_name) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(source_schema_name) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(source_table_name) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(source_user_name) LIKE '%' || LOWER('" + search +"') || '%'\n";
strSQL += "OR LOWER(column_name) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(sql_text) LIKE '%' || LOWER('" + search + "') || '%'\n";
}
sortBy = sortBy.toLowerCase();
if (sortBy.equals("queue_id") || sortBy.equals("status") || sortBy.equals("queue_date") || sortBy.equals("start_date") || sortBy.equals("end_date") || sortBy.equals("duration") || sortBy.equals("num_rows") || sortBy.equals("id") || sortBy.equals("target_table_name") || sortBy.equals("error_message"))
strSQL += "ORDER BY " + sortBy + " " + sort + ", start_date DESC\n";
else
strSQL += "ORDER BY status ASC, queue_id DESC\n";
if (!limit.equals(""))
strSQL += "LIMIT " + limit + " ";
if (!offset.equals(""))
strSQL += "OFFSET " + offset;
try
{
ResultSet rs = OutsourcerModel.getResults(strSQL);
return rs;
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static void updateTable(String queueId) throws SQLException
{
String strSQL = "INSERT INTO os.ao_queue\n";
strSQL += "(queue_id, status, queue_date, start_date, end_date, error_message,\n";
strSQL += "num_rows, id, refresh_type, target_schema_name, 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,\n";
strSQL += "source_database_name, source_schema_name, source_table_name,\n";
strSQL += "source_user_name, source_pass, column_name, sql_text, snapshot)\n";
strSQL += "SELECT queue_id, 'queued' as status, queue_date, NULL AS start_date, NULL AS end_date, NULL AS error_message,\n";
strSQL += "0 AS num_rows, id, refresh_type, target_schema_name, 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,\n";
strSQL += "source_database_name, source_schema_name, source_table_name,\n";
strSQL += "source_user_name, source_pass, column_name, sql_text, snapshot\n";
strSQL += "FROM os.queue\n";
strSQL += "WHERE queue_id = " + queueId + "\n";
strSQL += "AND status <> 'processing'";
try
{
OutsourcerModel.updateTable(strSQL);
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static void insertTable(String id) throws SQLException
{
String strSQL = "SELECT os.fn_queue(" + id + ")";
try
{
OutsourcerModel.getResults(strSQL);
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static void insertTableAll() throws SQLException
{
String strSQL = "SELECT os.fn_queue_all()";
try
{
OutsourcerModel.getResults(strSQL);
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static void deleteTable(String queueID) throws SQLException
{
String strSQL = "INSERT INTO os.ao_queue\n";
strSQL += "(queue_id, status, queue_date, start_date, end_date, error_message,\n";
strSQL += "num_rows, id, refresh_type, target_schema_name, 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,\n";
strSQL += "source_database_name, source_schema_name, source_table_name,\n";
strSQL += "source_user_name, source_pass, column_name, sql_text, snapshot,\n";
strSQL += "deleted)\n";
strSQL += "SELECT queue_id, status, queue_date, start_date, end_date, error_message,\n";
strSQL += "num_rows, id, refresh_type, target_schema_name, 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,\n";
strSQL += "source_database_name, source_schema_name, source_table_name,\n";
strSQL += "source_user_name, source_pass, column_name, sql_text, snapshot,\n";
strSQL += "TRUE AS deleted\n";
strSQL += "FROM os.queue\n";
strSQL += "WHERE queue_id = " + queueID + "\n";
strSQL += "AND status IN ('queued', 'failed')\n";
try
{
OutsourcerModel.updateTable(strSQL);
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static void cancelTable(String id) throws SQLException
{
String strSQL = "SELECT os.fn_cancel_job(" + id + ")";
try
{
ResultSet rs = OutsourcerModel.getResults(strSQL);
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
}