1 package com.melloware.jukes.gui.view.dialogs;
2
3 import java.beans.BeanInfo;
4 import java.beans.PropertyChangeEvent;
5 import java.beans.PropertyChangeListener;
6
7 import javax.swing.JPanel;
8
9 import org.hibernate.stat.Statistics;
10
11 import com.l2fprod.common.beans.BaseBeanInfo;
12 import com.l2fprod.common.beans.ExtendedPropertyDescriptor;
13 import com.l2fprod.common.model.DefaultBeanInfoResolver;
14 import com.l2fprod.common.propertysheet.Property;
15 import com.l2fprod.common.propertysheet.PropertySheet;
16 import com.l2fprod.common.propertysheet.PropertySheetPanel;
17 import com.l2fprod.common.swing.LookAndFeelTweaks;
18 import com.melloware.jukes.db.HibernateUtil;
19
20
21
22
23
24
25
26
27 public final class PropertySheetHibernateStats
28 extends JPanel {
29
30 private static final String ENTITY = "Entity";
31 private static final String CACHE = "Cache";
32 private static final String COLLECTIONS = "Collections";
33 private static final String SESSION = "Session";
34 private static final String TRANSACTION = "Transaction";
35 private static final String QUERY = "Query";
36
37 public PropertySheetHibernateStats() {
38 setLayout(LookAndFeelTweaks.createVerticalPercentLayout());
39
40 final Bean data = new Bean();
41
42 Statistics stats = HibernateUtil.getSessionFactory().getStatistics();
43 data.setSessionOpenCount(stats.getSessionOpenCount());
44 data.setSessionCloseCount(stats.getSessionCloseCount());
45 data.setSuccessfulTransactionCount(stats.getSuccessfulTransactionCount());
46 data.setTransactionCount(stats.getTransactionCount());
47 data.setOptimisticFailureCount(stats.getOptimisticFailureCount());
48 data.setFlushCount(stats.getFlushCount());
49 data.setConnectCount(stats.getConnectCount());
50 data.setPrepareStatementCount(stats.getPrepareStatementCount());
51 data.setCloseStatementCount(stats.getCloseStatementCount());
52 data.setSecondLevelCachePutCount(stats.getSecondLevelCachePutCount());
53 data.setSecondLevelCacheHitCount(stats.getSecondLevelCacheHitCount());
54 data.setSecondLevelCacheMissCount(stats.getSecondLevelCacheMissCount());
55 data.setEntityLoadCount(stats.getEntityLoadCount());
56 data.setEntityUpdateCount(stats.getEntityUpdateCount());
57 data.setEntityInsertCount(stats.getEntityInsertCount());
58 data.setEntityDeleteCount(stats.getEntityDeleteCount());
59 data.setEntityFetchCount(stats.getEntityFetchCount());
60 data.setQueryExecutionCount(stats.getQueryExecutionCount());
61 data.setQueryCachePutCount(stats.getQueryCachePutCount());
62 data.setQueryCacheHitCount(stats.getQueryCacheHitCount());
63 data.setQueryCacheMissCount(stats.getQueryCacheMissCount());
64 data.setQueryExecutionMaxTime(stats.getQueryExecutionMaxTime());
65 data.setCollectionLoadCount(stats.getCollectionLoadCount());
66 data.setCollectionRecreateCount(stats.getCollectionRecreateCount());
67 data.setCollectionRemoveCount(stats.getCollectionRemoveCount());
68 data.setCollectionUpdateCount(stats.getCollectionUpdateCount());
69
70 DefaultBeanInfoResolver resolver = new DefaultBeanInfoResolver();
71 BeanInfo beanInfo = resolver.getBeanInfo(data);
72
73 PropertySheetPanel sheet = new PropertySheetPanel();
74 sheet.setMode(PropertySheet.VIEW_AS_CATEGORIES);
75 sheet.setProperties(beanInfo.getPropertyDescriptors());
76 sheet.readFromObject(data);
77 sheet.setDescriptionVisible(true);
78 sheet.setSortingCategories(true);
79 sheet.setSortingProperties(true);
80 add(sheet, "*");
81
82
83 PropertyChangeListener listener = new PropertyChangeListener() {
84 public void propertyChange(PropertyChangeEvent evt) {
85 Property prop = (Property)evt.getSource();
86 prop.writeToObject(data);
87 }
88 };
89 sheet.addPropertySheetChangeListener(listener);
90 }
91
92
93
94
95 public static class Bean {
96 private long closeStatementCount;
97 private long collectionFetchCount;
98 private long collectionLoadCount;
99 private long collectionRecreateCount;
100 private long collectionRemoveCount;
101 private long collectionUpdateCount;
102 private long connectCount;
103 private long entityDeleteCount;
104 private long entityFetchCount;
105 private long entityInsertCount;
106 private long entityLoadCount;
107 private long entityUpdateCount;
108 private long flushCount;
109 private long optimisticFailureCount;
110 private long prepareStatementCount;
111 private long queryCacheHitCount;
112 private long queryCacheMissCount;
113 private long queryCachePutCount;
114 private long queryExecutionCount;
115 private long queryExecutionMaxTime;
116 private long secondLevelCacheHitCount;
117 private long secondLevelCacheMissCount;
118 private long secondLevelCachePutCount;
119 private long sessionCloseCount;
120
121 private long sessionOpenCount;
122 private long successfulTransactionCount;
123 private long transactionCount;
124
125
126
127
128
129
130 public long getCloseStatementCount() {
131 return this.closeStatementCount;
132 }
133
134
135
136
137
138
139 public long getCollectionFetchCount() {
140 return this.collectionFetchCount;
141 }
142
143
144
145
146
147
148 public long getCollectionLoadCount() {
149 return this.collectionLoadCount;
150 }
151
152
153
154
155
156
157 public long getCollectionRecreateCount() {
158 return this.collectionRecreateCount;
159 }
160
161
162
163
164
165
166 public long getCollectionRemoveCount() {
167 return this.collectionRemoveCount;
168 }
169
170
171
172
173
174
175 public long getCollectionUpdateCount() {
176 return this.collectionUpdateCount;
177 }
178
179
180
181
182
183
184 public long getConnectCount() {
185 return this.connectCount;
186 }
187
188
189
190
191
192
193 public long getEntityDeleteCount() {
194 return this.entityDeleteCount;
195 }
196
197
198
199
200
201
202 public long getEntityFetchCount() {
203 return this.entityFetchCount;
204 }
205
206
207
208
209
210
211 public long getEntityInsertCount() {
212 return this.entityInsertCount;
213 }
214
215
216
217
218
219
220 public long getEntityLoadCount() {
221 return this.entityLoadCount;
222 }
223
224
225
226
227
228
229 public long getEntityUpdateCount() {
230 return this.entityUpdateCount;
231 }
232
233
234
235
236
237
238 public long getFlushCount() {
239 return this.flushCount;
240 }
241
242
243
244
245
246
247 public long getOptimisticFailureCount() {
248 return this.optimisticFailureCount;
249 }
250
251
252
253
254
255
256 public long getPrepareStatementCount() {
257 return this.prepareStatementCount;
258 }
259
260
261
262
263
264
265 public long getQueryCacheHitCount() {
266 return this.queryCacheHitCount;
267 }
268
269
270
271
272
273
274 public long getQueryCacheMissCount() {
275 return this.queryCacheMissCount;
276 }
277
278
279
280
281
282
283 public long getQueryCachePutCount() {
284 return this.queryCachePutCount;
285 }
286
287
288
289
290
291
292 public long getQueryExecutionCount() {
293 return this.queryExecutionCount;
294 }
295
296
297
298
299
300
301 public long getQueryExecutionMaxTime() {
302 return this.queryExecutionMaxTime;
303 }
304
305
306
307
308
309
310 public long getSecondLevelCacheHitCount() {
311 return this.secondLevelCacheHitCount;
312 }
313
314
315
316
317
318
319 public long getSecondLevelCacheMissCount() {
320 return this.secondLevelCacheMissCount;
321 }
322
323
324
325
326
327
328 public long getSecondLevelCachePutCount() {
329 return this.secondLevelCachePutCount;
330 }
331
332
333
334
335
336
337 public long getSessionCloseCount() {
338 return this.sessionCloseCount;
339 }
340
341
342
343
344
345
346 public long getSessionOpenCount() {
347 return this.sessionOpenCount;
348 }
349
350
351
352
353
354
355 public long getSuccessfulTransactionCount() {
356 return this.successfulTransactionCount;
357 }
358
359
360
361
362
363
364 public long getTransactionCount() {
365 return this.transactionCount;
366 }
367
368
369
370
371
372
373 public void setCloseStatementCount(long aCloseStatementCount) {
374 this.closeStatementCount = aCloseStatementCount;
375 }
376
377
378
379
380
381
382 public void setCollectionFetchCount(long aCollectionFetchCount) {
383 this.collectionFetchCount = aCollectionFetchCount;
384 }
385
386
387
388
389
390
391 public void setCollectionLoadCount(long aCollectionLoadCount) {
392 this.collectionLoadCount = aCollectionLoadCount;
393 }
394
395
396
397
398
399
400 public void setCollectionRecreateCount(long aCollectionRecreateCount) {
401 this.collectionRecreateCount = aCollectionRecreateCount;
402 }
403
404
405
406
407
408
409 public void setCollectionRemoveCount(long aCollectionRemoveCount) {
410 this.collectionRemoveCount = aCollectionRemoveCount;
411 }
412
413
414
415
416
417
418 public void setCollectionUpdateCount(long aCollectionUpdateCount) {
419 this.collectionUpdateCount = aCollectionUpdateCount;
420 }
421
422
423
424
425
426
427 public void setConnectCount(long aConnectCount) {
428 this.connectCount = aConnectCount;
429 }
430
431
432
433
434
435
436 public void setEntityDeleteCount(long aEntityDeleteCount) {
437 this.entityDeleteCount = aEntityDeleteCount;
438 }
439
440
441
442
443
444
445 public void setEntityFetchCount(long aEntityFetchCount) {
446 this.entityFetchCount = aEntityFetchCount;
447 }
448
449
450
451
452
453
454 public void setEntityInsertCount(long aEntityInsertCount) {
455 this.entityInsertCount = aEntityInsertCount;
456 }
457
458
459
460
461
462
463 public void setEntityLoadCount(long aEntityLoadCount) {
464 this.entityLoadCount = aEntityLoadCount;
465 }
466
467
468
469
470
471
472 public void setEntityUpdateCount(long aEntityUpdateCount) {
473 this.entityUpdateCount = aEntityUpdateCount;
474 }
475
476
477
478
479
480
481 public void setFlushCount(long aFlushCount) {
482 this.flushCount = aFlushCount;
483 }
484
485
486
487
488
489
490 public void setOptimisticFailureCount(long aOptimisticFailureCount) {
491 this.optimisticFailureCount = aOptimisticFailureCount;
492 }
493
494
495
496
497
498
499 public void setPrepareStatementCount(long aPrepareStatementCount) {
500 this.prepareStatementCount = aPrepareStatementCount;
501 }
502
503
504
505
506
507
508 public void setQueryCacheHitCount(long aQueryCacheHitCount) {
509 this.queryCacheHitCount = aQueryCacheHitCount;
510 }
511
512
513
514
515
516
517 public void setQueryCacheMissCount(long aQueryCacheMissCount) {
518 this.queryCacheMissCount = aQueryCacheMissCount;
519 }
520
521
522
523
524
525
526 public void setQueryCachePutCount(long aQueryCachePutCount) {
527 this.queryCachePutCount = aQueryCachePutCount;
528 }
529
530
531
532
533
534
535 public void setQueryExecutionCount(long aQueryExecutionCount) {
536 this.queryExecutionCount = aQueryExecutionCount;
537 }
538
539
540
541
542
543
544 public void setQueryExecutionMaxTime(long aQueryExecutionMaxTime) {
545 this.queryExecutionMaxTime = aQueryExecutionMaxTime;
546 }
547
548
549
550
551
552
553 public void setSecondLevelCacheHitCount(long aSecondLevelCacheHitCount) {
554 this.secondLevelCacheHitCount = aSecondLevelCacheHitCount;
555 }
556
557
558
559
560
561
562 public void setSecondLevelCacheMissCount(long aSecondLevelCacheMissCount) {
563 this.secondLevelCacheMissCount = aSecondLevelCacheMissCount;
564 }
565
566
567
568
569
570
571 public void setSecondLevelCachePutCount(long aSecondLevelCachePutCount) {
572 this.secondLevelCachePutCount = aSecondLevelCachePutCount;
573 }
574
575
576
577
578
579
580 public void setSessionCloseCount(long aSessionCloseCount) {
581 this.sessionCloseCount = aSessionCloseCount;
582 }
583
584
585
586
587
588
589 public void setSessionOpenCount(long aSessionOpenCount) {
590 this.sessionOpenCount = aSessionOpenCount;
591 }
592
593
594
595
596
597
598 public void setSuccessfulTransactionCount(long aSuccessfulTransactionCount) {
599 this.successfulTransactionCount = aSuccessfulTransactionCount;
600 }
601
602
603
604
605
606
607 public void setTransactionCount(long aTransactionCount) {
608 this.transactionCount = aTransactionCount;
609 }
610
611 }
612
613
614
615
616 public static class BeanBeanInfo
617 extends BaseBeanInfo {
618
619 public BeanBeanInfo() {
620 super(Bean.class);
621 ExtendedPropertyDescriptor descriptor = null;
622
623 descriptor = addProperty("queryExecutionCount");
624 descriptor.setCategory(QUERY);
625 descriptor.setDisplayName("Query Execution Count");
626 descriptor.setShortDescription("Number of queries executed.");
627
628 descriptor = addProperty("queryExecutionMaxTime");
629 descriptor.setCategory(QUERY);
630 descriptor.setDisplayName("Query Execution Max Time");
631 descriptor.setShortDescription("Maximum amount of time it took to execute a query.");
632
633 descriptor = addProperty("entityLoadCount");
634 descriptor.setCategory(ENTITY);
635 descriptor.setDisplayName("Entity Load Count");
636 descriptor.setShortDescription("Number of entities loaded.");
637
638 descriptor = addProperty("entityInsertCount");
639 descriptor.setCategory(ENTITY);
640 descriptor.setDisplayName("Entity Insert Count");
641 descriptor.setShortDescription("Number of entities inserted.");
642
643 descriptor = addProperty("entityUpdateCount");
644 descriptor.setCategory(ENTITY);
645 descriptor.setDisplayName("Entity Update Count");
646 descriptor.setShortDescription("Number of entities updated.");
647
648 descriptor = addProperty("entityDeleteCount");
649 descriptor.setCategory(ENTITY);
650 descriptor.setDisplayName("Entity Delete Count");
651 descriptor.setShortDescription("Number of entities deleted.");
652
653 descriptor = addProperty("entityFetchCount");
654 descriptor.setCategory(ENTITY);
655 descriptor.setDisplayName("Entity Fetch Count");
656 descriptor.setShortDescription("Number of entities fetched.");
657
658 descriptor = addProperty("collectionFetchCount");
659 descriptor.setCategory(COLLECTIONS);
660 descriptor.setDisplayName("Collection Fetch Count");
661 descriptor.setShortDescription("Number of collections fetched.");
662
663 descriptor = addProperty("collectionLoadCount");
664 descriptor.setCategory(COLLECTIONS);
665 descriptor.setDisplayName("Collection Load Count");
666 descriptor.setShortDescription("Number of collections loaded.");
667
668 descriptor = addProperty("collectionRecreateCount");
669 descriptor.setCategory(COLLECTIONS);
670 descriptor.setDisplayName("Collection Recreate Count");
671 descriptor.setShortDescription("Number of collections recreated.");
672
673 descriptor = addProperty("collectionRemoveCount");
674 descriptor.setCategory(COLLECTIONS);
675 descriptor.setDisplayName("Collection Removed Count");
676 descriptor.setShortDescription("Number of collections removed.");
677
678 descriptor = addProperty("collectionUpdateCount");
679 descriptor.setCategory(COLLECTIONS);
680 descriptor.setDisplayName("Collection Update Count");
681 descriptor.setShortDescription("Number of collections updated.");
682
683 descriptor = addProperty("secondLevelCachePutCount");
684 descriptor.setCategory(CACHE);
685 descriptor.setDisplayName("Second Level Cache Puts");
686 descriptor.setShortDescription("Number of second level cache puts.");
687
688 descriptor = addProperty("secondLevelCacheHitCount");
689 descriptor.setCategory(CACHE);
690 descriptor.setDisplayName("Second Level Cache Hits");
691 descriptor.setShortDescription("Number of second level cache hits.");
692
693 descriptor = addProperty("secondLevelCacheMissCount");
694 descriptor.setCategory(CACHE);
695 descriptor.setDisplayName("Second Level Cache Misses");
696 descriptor.setShortDescription("Number of second level cache misses.");
697
698 descriptor = addProperty("queryCachePutCount");
699 descriptor.setCategory(CACHE);
700 descriptor.setDisplayName("Query Cache Puts");
701 descriptor.setShortDescription("Number of query cache puts.");
702
703 descriptor = addProperty("queryCacheHitCount");
704 descriptor.setCategory(CACHE);
705 descriptor.setDisplayName("Query Cache Hits");
706 descriptor.setShortDescription("Number of query cache hits.");
707
708 descriptor = addProperty("queryCacheMissCount");
709 descriptor.setCategory(CACHE);
710 descriptor.setDisplayName("Query Cache Misses");
711 descriptor.setShortDescription("Number of query cache misses.");
712
713 descriptor = addProperty("sessionOpenCount");
714 descriptor.setCategory(SESSION);
715 descriptor.setDisplayName("Sessions Opened");
716 descriptor.setShortDescription("Number of sessions opened.");
717
718 descriptor = addProperty("sessionCloseCount");
719 descriptor.setCategory(SESSION);
720 descriptor.setDisplayName("Sessions Closed");
721 descriptor.setShortDescription("Number of sessions closed.");
722
723 descriptor = addProperty("flushCount");
724 descriptor.setCategory(SESSION);
725 descriptor.setDisplayName("Flushes");
726 descriptor.setShortDescription("Number of sessions flushed.");
727
728 descriptor = addProperty("connectCount");
729 descriptor.setCategory(SESSION);
730 descriptor.setDisplayName("Connections");
731 descriptor.setShortDescription("Number of sessions connections.");
732
733 descriptor = addProperty("prepareStatementCount");
734 descriptor.setCategory(SESSION);
735 descriptor.setDisplayName("Prepared Statements");
736 descriptor.setShortDescription("Number of session prepared statements.");
737
738 descriptor = addProperty("closeStatementCount");
739 descriptor.setCategory(SESSION);
740 descriptor.setDisplayName("Closed Statements");
741 descriptor.setShortDescription("Number of session closed statements.");
742
743 descriptor = addProperty("successfulTransactionCount");
744 descriptor.setCategory(TRANSACTION);
745 descriptor.setDisplayName("Successful Transactions");
746 descriptor.setShortDescription("Number of successful transactions.");
747
748 descriptor = addProperty("transactionCount");
749 descriptor.setCategory(TRANSACTION);
750 descriptor.setDisplayName("Transactions");
751 descriptor.setShortDescription("Number of transactions.");
752
753 descriptor = addProperty("optimisticFailureCount");
754 descriptor.setCategory(TRANSACTION);
755 descriptor.setDisplayName("Optimistic Lock Failures");
756 descriptor.setShortDescription("Number of failed optimistic locks.");
757 }
758 }
759
760 }