KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > tests > JdbcConnectionPoolTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.config.serverbeans.validation.tests;
25
26 import java.util.Locale JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import com.sun.enterprise.config.serverbeans.validation.GenericValidator;
30 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor;
31 import com.sun.enterprise.config.serverbeans.validation.ValidationContext;
32 import com.sun.enterprise.config.serverbeans.validation.PropertyHelper;
33 import com.sun.enterprise.config.serverbeans.validation.Result;
34
35 import com.sun.enterprise.config.serverbeans.JdbcConnectionPool;
36 import com.sun.enterprise.config.serverbeans.ElementProperty;
37
38 import com.sun.enterprise.config.ConfigBean;
39 import com.sun.enterprise.config.ConfigContextEvent;
40 import com.sun.enterprise.config.ConfigContext;
41 import com.sun.enterprise.config.ConfigException;
42
43
44 import java.util.logging.Level JavaDoc;
45
46 /**
47     Custom Test for Jdbc Connection Pool Test which calls the Generic Validation before performing custom tests
48
49     @author Srinivas Krishnan
50     @version 2.0
51 */

52
53 public class JdbcConnectionPoolTest extends GenericValidator {
54     
55     static boolean checked = false;
56     int maxPoolSize = 0;
57     
58     public JdbcConnectionPoolTest(ValidationDescriptor desc) {
59         super(desc);
60     }
61     
62     public void validate(ValidationContext valCtx) {
63         super.validate(valCtx); // Before doing custom validation do basic validation
64

65         if(valCtx.isVALIDATE() || valCtx.isADD() || valCtx.isSET())
66         {
67             JdbcConnectionPool pool = (JdbcConnectionPool)valCtx.getTargetBean();
68             if(pool.isIsConnectionValidationRequired() && pool.getConnectionValidationMethod().equals("table")) {
69                 if(pool.getValidationTableName() == null || pool.getValidationTableName().equals(""))
70                     reportValidationError(valCtx, "requiredTableName",
71                     "Table Name is required Jdbc Connection Pool if Connection validation method is Table",
72                     null);
73             }
74             checkLazyConnectionProps(valCtx);
75         }
76     }
77     
78     //property changes reaction
79
static final String JavaDoc LAZY_CONN_ASSOCIATION = "LazyConnectionAssociation";
80     static final String JavaDoc LAZY_CONN_ENLISTMENT = "LazyConnectionEnlistment";
81     
82     public void validatePropertyChanges(ValidationContext propValCtx)
83     {
84         
85         if(propValCtx.isDELETE() || propValCtx.isVALIDATE()) //no validation
86
return;
87         
88         if(!PropertyHelper.isPropertyChanged(propValCtx, LAZY_CONN_ASSOCIATION) &&
89            !PropertyHelper.isPropertyChanged(propValCtx, LAZY_CONN_ENLISTMENT))
90             return;
91         
92         //here we are only if some changes with testing props occured
93
checkLazyConnectionProps(propValCtx);
94     }
95     
96     private void checkLazyConnectionProps(ValidationContext valCtx)
97     {
98         Map JavaDoc map;
99         ConfigBean targetBean = valCtx.getTargetBean();
100         if(targetBean==null)
101             return;
102         if(targetBean instanceof ElementProperty)
103             map = PropertyHelper.getFuturePropertiesMap(valCtx);
104         else
105             map = PropertyHelper.getPropertiesMap(targetBean);
106         String JavaDoc newAsso = (String JavaDoc)map.get(LAZY_CONN_ASSOCIATION);
107         String JavaDoc newEnlist = (String JavaDoc)map.get(LAZY_CONN_ENLISTMENT);
108         if(newAsso!=null && newEnlist!=null &&
109            Boolean.parseBoolean(newAsso) && !Boolean.parseBoolean(newEnlist))
110         {
111             reportValidationError(valCtx, "PropsConflict",
112                 "Combination of properties {0}={1} and {2}={3} is not allowed.",
113                 new Object JavaDoc[]{LAZY_CONN_ASSOCIATION, newAsso,
114                              LAZY_CONN_ENLISTMENT, newEnlist});
115         }
116     }
117 }
118
Popular Tags