-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEnterPoint.java
executable file
·346 lines (299 loc) · 11.9 KB
/
EnterPoint.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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import javax.swing.*;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import bc.connection.Connector;
public class EnterPoint extends JFrame {
private final static long serialVersionUID=1L;
private String user="bc_reports";
private String password="bc_reports";
/*private String user="bc_reports";
private String password="bc_reports";
*/
private void debug(Object information){
System.out.print("EnterPoint");
System.out.print(" DEBUG ");
StackTraceElement[] ste = (new Throwable()).getStackTrace();
System.out.print(ste[1].getMethodName()+": ");
System.out.println(information);
}
private void error(Object information){
System.out.print("EnterPoint");
System.out.print(" ERROR ");
StackTraceElement[] ste = (new Throwable()).getStackTrace();
System.out.print(ste[1].getMethodName()+": ");
System.out.println(information);
}
public static void main(String[] args){
new EnterPoint();
}
public EnterPoint(){
super("JFrame");
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(org.apache.log4j.Level.WARN);
initComponents();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(600,400);
this.setVisible(true);
this.pack();
}
private JTextField fieldLogin;
private JTextField fieldPassword;
/** ïîëó÷èòü ïàíåëü ñ îáåðíóòûì â íåå âèçóàëüíûì êîìïîíåíòîì
* @param component - êîìïîíåíò, êîòîðûé íóæíî îáåðíóòü
* @param caption - çàãîëîâîê, êîòîðûé íóæíî íàçíà÷èòü êîìïîíåíòó
* */
private JPanel getTitlePanelWrap(JComponent component, String caption){
JPanel returnValue=new JPanel(new GridLayout(1,1));
returnValue.add(component);
returnValue.setBorder(javax.swing.BorderFactory.createTitledBorder(caption));
return returnValue;
}
private void initComponents(){
// create element's
JButton buttonGetConnection=new JButton("Get Connection (U,P) and Close It");
JButton buttonGetConnection2=new JButton("Get Connection (U,P) without Close");
JButton buttonGetConnection5=new JButton("Get Connection (session) and Close It");
JButton buttonGetConnection7=new JButton("Remove session by \"DBA\" ");
JButton buttonGetConnection3=new JButton("User Connection (U,P) and Close It");
JButton buttonGetConnection4=new JButton("User Connection (U,P) without Close");
JButton buttonGetConnection6=new JButton("User Connection (session) and Close It");
JButton buttonDropUser=new JButton("Drop User <First>");
JButton buttonPrintAllConnection=new JButton("print ALL connection ");
fieldLogin=new JTextField();
fieldPassword=new JTextField();
JButton buttonConnectCustom=new JButton("Connect with any");
JPanel panelCustom=new JPanel(new GridLayout(1,2));
panelCustom.add(getTitlePanelWrap(fieldLogin, "login"));
panelCustom.add(getTitlePanelWrap(fieldPassword, "password"));
JPanel panelChangePassword=new JPanel();
panelChangePassword.setBorder(javax.swing.BorderFactory.createTitledBorder("Ñìåíà ïàðîëÿ äëÿ ïîëüçîâàòåëÿ"));
GroupLayout groupLayout=new GroupLayout(panelChangePassword);
panelChangePassword.setLayout(groupLayout);
GroupLayout.SequentialGroup groupLayoutHorizontal=groupLayout.createSequentialGroup();
GroupLayout.SequentialGroup groupLayoutVertical=groupLayout.createSequentialGroup();
groupLayout.setVerticalGroup(groupLayoutVertical);
groupLayout.setHorizontalGroup(groupLayoutHorizontal);
final JTextField fieldUserName=new JTextField();
final JTextField fieldPasswordBefore=new JTextField();
final JTextField fieldPasswordAfter=new JTextField();
JPanel panelUserName=getTitlePanelWrap(fieldUserName, "Èìÿ ïîëüçîâàòåëÿ");
JPanel panelPasswordBefore=getTitlePanelWrap(fieldPasswordBefore, "Ïàðîëü äî");
JPanel panelPasswordAfter=getTitlePanelWrap(fieldPasswordAfter, "Ïàðîëü ïîñëå");
JButton buttonChange=new JButton("Ñìåíèòü ïàðîëü");
groupLayoutHorizontal.addGroup(groupLayout.createParallelGroup()
.addComponent(panelUserName)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(panelPasswordBefore)
.addComponent(panelPasswordAfter)
)
.addComponent(buttonChange,GroupLayout.PREFERRED_SIZE,GroupLayout.PREFERRED_SIZE,Short.MAX_VALUE)
);
groupLayoutVertical.addComponent(panelUserName);
groupLayoutVertical.addGroup(groupLayout.createParallelGroup()
.addComponent(panelPasswordBefore)
.addComponent(panelPasswordAfter)
);
groupLayoutVertical.addComponent(buttonChange);
// set listener's
buttonChange.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
EnterPoint.this.changePassword(fieldUserName.getText(), fieldPasswordBefore.getText(), fieldPasswordAfter.getText());
}
});
buttonConnectCustom.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonConnectCustom();
}
});
buttonGetConnection.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonGetConnection();
}
});
buttonGetConnection2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonGetConnection2();
}
});
buttonGetConnection3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonGetConnection3();
}
});
buttonGetConnection4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonGetConnection4();
}
});
buttonGetConnection5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonGetConnection5();
}
});
buttonGetConnection6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonGetConnection6();
}
});
buttonGetConnection7.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonGetConnection7();
}
});
buttonDropUser.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonDropUser();
}
});
buttonPrintAllConnection.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
onButtonPrintAllConnection();
}
});
// placing component's
JPanel panelMain=new JPanel();
groupLayout=new GroupLayout(panelMain);
panelMain.setLayout(groupLayout);
groupLayoutHorizontal=groupLayout.createSequentialGroup();
groupLayoutVertical=groupLayout.createSequentialGroup();
groupLayout.setHorizontalGroup(groupLayoutHorizontal);
groupLayout.setVerticalGroup(groupLayoutVertical);
groupLayoutHorizontal.addGroup(groupLayout.createParallelGroup()
.addGroup(
groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup()
.addComponent(buttonGetConnection)
.addComponent(buttonGetConnection2)
.addComponent(buttonGetConnection5)
.addComponent(buttonGetConnection7)
)
.addGroup(groupLayout.createParallelGroup()
.addComponent(buttonGetConnection3)
.addComponent(buttonGetConnection4)
.addComponent(buttonGetConnection6)
.addComponent(buttonDropUser)
)
)
.addComponent(buttonPrintAllConnection,GroupLayout.PREFERRED_SIZE,GroupLayout.PREFERRED_SIZE,Short.MAX_VALUE)
.addComponent(panelCustom)
.addComponent(buttonConnectCustom,GroupLayout.PREFERRED_SIZE,GroupLayout.PREFERRED_SIZE,Short.MAX_VALUE)
.addComponent(panelChangePassword)
);
groupLayoutVertical.addGroup(groupLayout.createParallelGroup()
.addGroup(groupLayout.createSequentialGroup()
.addComponent(buttonGetConnection)
.addComponent(buttonGetConnection2)
.addComponent(buttonGetConnection5)
.addComponent(buttonGetConnection7)
)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(buttonGetConnection3)
.addComponent(buttonGetConnection4)
.addComponent(buttonGetConnection6)
.addComponent(buttonDropUser)
)
);
groupLayoutVertical.addGap(20);
groupLayoutVertical.addComponent(buttonPrintAllConnection);
groupLayoutVertical.addGap(10);
groupLayoutVertical.addComponent(panelCustom);
groupLayoutVertical.addComponent(buttonConnectCustom);
groupLayoutVertical.addGap(20);
groupLayoutVertical.addComponent(panelChangePassword);
this.getContentPane().add(panelMain);
}
private void onButtonConnectCustom() {
Connection connection=Connector.getConnection(this.fieldLogin.getText(),this.fieldPassword.getText(),"222");
try{
debug("new Custom Connection:"+connection+" USERNAME:"+connection.getMetaData().getUserName());
}catch(Exception ex){
}
try{
connection.close();
debug("connection is closed ");
}catch(Exception ex){
error("Exception: "+ex.getMessage());
}
}
private void onButtonGetConnection(){
Connection connection=Connector.getConnection(user, password, "id1");
try{
debug("new Connection1:"+connection+" USERNAME:"+connection.getMetaData().getUserName());
}catch(Exception ex){
}
try{
connection.close();
debug("connection is closed ");
}catch(Exception ex){
error("Exception: "+ex.getMessage());
}
}
private void onButtonGetConnection2(){
Connection connection=Connector.getConnection(user, password, "id1");
try{
debug("new Connection1:"+connection+" USERNAME:"+connection.getMetaData().getUserName());
}catch(Exception ex){
}
}
private void onButtonGetConnection5(){
Connection connection=Connector.getConnection("id1");
try{
debug("new Connection1:"+connection+" USERNAME:"+connection.getMetaData().getUserName());
connection.close();
}catch(Exception ex){
}
}
private void onButtonGetConnection3(){
Connection connection=Connector.getConnection("first", "first", "id1");
try{
debug("new Connection1:"+connection+" USERNAME:"+connection.getMetaData().getUserName());
}catch(Exception ex){
}
try{
connection.close();
debug("connection is closed ");
}catch(Exception ex){
error("Exception: "+ex.getMessage());
}
}
private void onButtonGetConnection4(){
Connection connection=Connector.getConnection("first", "first", "id1");
try{
debug("new Connection1:"+connection+" USERNAME:"+connection.getMetaData().getUserName());
}catch(Exception ex){
}
}
private void onButtonGetConnection6(){
Connection connection=Connector.getConnection("id1");
try{
debug("new Connection1:"+connection+" USERNAME:"+connection.getMetaData().getUserName());
connection.close();
}catch(Exception ex){
}
}
private void onButtonGetConnection7(){
Connector.removeSessionId("id1");
/* try{
Connection connection=Connector.getConnection("id1");
debug("new Connection1:"+connection+" USERNAME:"+connection.getMetaData().getUserName());
connection.close();
}catch(Exception ex){
}
*/
}
private void onButtonDropUser(){
System.out.println("drop User name:"+Connector.dropUserConnection("first"));
}
private void onButtonPrintAllConnection(){
Connector.printAllConnectionCount(System.out);
}
/** ôóíêöèÿ, êîòîðàÿ ïðîèçâîäèò èçìíåíåíèÿ â ïàðîëå*/
private void changePassword(String userName, String passwordBefore, String passwordAfter){
// TODO
Connector.dropUserConnection(userName);
}
}