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