-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsoleLogsViewDM.java
More file actions
293 lines (235 loc) · 6.73 KB
/
consoleLogsViewDM.java
File metadata and controls
293 lines (235 loc) · 6.73 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package Jvakt;
/*
* 2025-06-09 V.02 Michael Ekdal Changed the order of the createStatement to accomodate changes in postgresql-42.7.6.jar
* 2023-11-25 V.01 Michael Ekdal New pgm to list the logs in the DB
*/
import javax.swing.table.*;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
class consoleLogsViewDM extends AbstractTableModel {
static final long serialVersionUID = 50L;
String afn;
String columnNames[] = {"Line","Row"};
// static Vector map = new Vector(1000,100);
static Vector<consoleLogsViewROW> map = new Vector<consoleLogsViewROW>(100,100);
consoleLogsViewROW rad;
int i = 0;
static String DBUrl = "jdbc:postgresql://localhost:5433/Jvakt";
static Connection conn = null;
String version = "jVakt - consoleLogsViewDM ( 2023-NOV-21)";
String database = "Jvakt";
String dbuser = "console";
String dbpassword = "";
String dbhost = "localhost";
String dbport = "5433";
String jvhost = "localhost";
String jvport = "1956";
String id;
String origin;
String credat;
Boolean swDBopen = false;
String where = "";
public consoleLogsViewDM() throws IOException {
getProps();
// if (openDB()) refreshData();
}
public int getColumnCount() {
// System.out.println("ColumnCount: " + columnNames.length);
return columnNames.length;
}
public int getRowCount() {
// System.out.println("RowCount: " + map.size()+1);
return map.size()+1;
}
public String getColumnName(int col) {
// System.out.println("ColumnNames: " + columnNames[col]);
return columnNames[col];
}
public Object getValueAt(int row, int col) {
if ( row >= map.size()) return null;
consoleLogsViewROW rad;
rad = (consoleLogsViewROW) map.get(row);
if (col == 0) {
// System.out.println("row: "+row+" rad: "+rad.getRow());
return rad.getLine();
} else
if (col == 1) {
// System.out.println("row: "+row+" rad: "+rad.getRow());
return rad.getRow();
} else return null;
}
public Class<?> getColumnClass(int c) {
try {
// return getValueAt(0, c).getClass();
return getValueAt(0, c).getClass();
} catch (NullPointerException e) {
return String.class;
}
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void setWhere(String where) {
this.where = where;
// System.out.println("This where: " + this.where);
}
public void setId(String id) {
this.id = id;
// System.out.println("This id: " + this.id);
}
public void setOrigin(String origin) {
this.origin = origin;
// System.out.println("This origin: " + this.origin);
}
public void setCredat(String credat) {
this.credat = credat;
// System.out.println("This credat: " + this.credat);
}
public void setValueAt(Object value, int row, int col) {
// System.out.println("wD setValueAt " + value + " " + row + " "+ col);
consoleLogsViewROW rad;
if ( row >= map.size()) {
rad = new consoleLogsViewROW();
map.add(rad);
}
else rad = (consoleLogsViewROW) map.get(row);
if (col == 0) {
rad.setLine((int)value);
} if (col == 1) {
rad.setRow((String)value);
}
fireTableCellUpdated(row, col);
}
public boolean openDB() {
try {
Class.forName("org.postgresql.Driver").newInstance();
DBUrl = "jdbc:postgresql://"+dbhost+":"+dbport+"/"+database;
System.out.println(DBUrl);
System.out.println("dbuser= " + dbuser +" dbpassword "+ dbpassword);
conn = DriverManager.getConnection(DBUrl,dbuser,dbpassword);
conn.setAutoCommit(false);
conn.setNetworkTimeout(null, 5000);
swDBopen = true;
}
catch (SQLException e) {
// System.err.println(e);
System.err.println(e.getMessage());
swDBopen = false;
map.clear();
createEmptyRow();
}
catch (Exception e) {
// System.err.println(e);
System.err.println(e.getMessage());
swDBopen = false;
map.clear();
createEmptyRow();
}
return swDBopen;
}
public boolean getDBopen() {
return swDBopen;
}
public boolean refreshData() {
if (!swDBopen) {
if (!openDB()) return false;
}
try {
String s;
if (where.length() < 5 || !where.endsWith(" ") )
s = new String("SELECT line,row FROM public.logs where id='"+id+"' and origin='"+origin+"' and credat='"+credat+"' order by line;");
else
s = new String("SELECT line,row FROM public.logs where id='"+id+"' and origin='"+origin+"' and credat='"+credat+"' and "+where+" order by line;");
map.clear();
// System.out.println(s);
// Statement stmt = conn.createStatement(ResultSet.CONCUR_READ_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE);
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY,ResultSet.CLOSE_CURSORS_AT_COMMIT );
stmt.setFetchSize(1000);
stmt.setQueryTimeout(5);
ResultSet rs = stmt.executeQuery(s);
// if (!rs.first()) {
// System.out.println("createemptyrow");
// createEmptyRow();
// }
int antal = 0;
while (rs.next()) {
//--
// System.out.println("rs.next "+rs.getString("row"));
rad = new consoleLogsViewROW();
// for (int i = 1; i <= 7; i++) {
rad.setLine(rs.getInt("line"));
rad.setRow(rs.getString("row"));
// System.out.println("getRow "+rad.getRow());
// }
map.add(rad);
// consoleLogsViewROW radX;
// radX = (consoleLogsViewROW) map.get(antal);
// System.out.println("radX "+radX.getRow());
antal++;
}
rs.close();
stmt.close();
// fireTableDataChanged();
}
catch (SQLException e) {
System.err.println(e);
System.err.println(e.getMessage());
swDBopen = false;
createEmptyRow();
}
catch (Exception e) {
System.err.println(e);
System.err.println(e.getMessage());
swDBopen = false;
createEmptyRow();
}
return true;
}
private boolean createEmptyRow() {
rad = new consoleLogsViewROW();
rad.setLine(0);
rad.setRow(" ");
// map.add(rad);
return true;
}
public boolean closeDB() {
try {
if (swDBopen) conn.close();
}
catch (SQLException e) {
System.err.println(e);
System.err.println(e.getMessage());
return true;
}
return true;
}
void getProps() {
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("console.properties");
prop.load(input);
// get the property value and print it out
database = prop.getProperty("database");
dbuser = prop.getProperty("dbuser");
dbpassword = prop.getProperty("dbpassword");
if (dbpassword.startsWith("==y")) {
byte[] decodedBytes = Base64.getDecoder().decode(dbpassword.substring(3));
String decodedString = new String(decodedBytes);
dbpassword=decodedString;
}
dbhost = prop.getProperty("dbhost");
dbport = prop.getProperty("dbport");
jvport = prop.getProperty("jvport");
jvhost = prop.getProperty("jvhost");
input.close();
} catch (IOException ex) {
// ex.printStackTrace();
}
}
}