KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > database > DatabaseConfig


1 /*
2  *
3  * The DbUnit Database Testing Framework
4  * Copyright (C)2002-2004, DbUnit.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */

21 package org.dbunit.database;
22
23 import org.dbunit.database.statement.PreparedStatementFactory;
24 import org.dbunit.dataset.datatype.DefaultDataTypeFactory;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.Set JavaDoc;
30
31 /**
32  *
33  * @author manuel.laflamme
34  * @since Jul 17, 2003
35  * @version $Revision: 1.5 $
36  */

37 public class DatabaseConfig
38 {
39     public static final String JavaDoc PROPERTY_STATEMENT_FACTORY =
40             "http://www.dbunit.org/properties/statementFactory";
41     public static final String JavaDoc PROPERTY_RESULTSET_TABLE_FACTORY =
42             "http://www.dbunit.org/properties/resultSetTableFactory";
43     public static final String JavaDoc PROPERTY_DATATYPE_FACTORY =
44             "http://www.dbunit.org/properties/datatypeFactory";
45     public static final String JavaDoc PROPERTY_ESCAPE_PATTERN =
46             "http://www.dbunit.org/properties/escapePattern";
47     public static final String JavaDoc PROPERTY_TABLE_TYPE =
48             "http://www.dbunit.org/properties/tableType";
49     public static final String JavaDoc PROPERTY_PRIMARY_KEY_FILTER =
50             "http://www.dbunit.org/properties/primaryKeyFilter";
51
52     public static final String JavaDoc FEATURE_QUALIFIED_TABLE_NAMES =
53             "http://www.dbunit.org/features/qualifiedTableNames";
54     public static final String JavaDoc FEATURE_BATCHED_STATEMENTS =
55             "http://www.dbunit.org/features/batchedStatements";
56     public static final String JavaDoc FEATURE_DATATYPE_WARNING =
57             "http://www.dbunit.org/features/datatypeWarning";
58
59     private static final DefaultDataTypeFactory DEFAULT_DATA_TYPE_FACTORY =
60             new DefaultDataTypeFactory();
61     private static final PreparedStatementFactory PREPARED_STATEMENT_FACTORY =
62             new PreparedStatementFactory();
63     private static final CachedResultSetTableFactory RESULT_SET_TABLE_FACTORY =
64             new CachedResultSetTableFactory();
65     private static final String JavaDoc DEFAULT_ESCAPE_PATTERN = null;
66     private static final String JavaDoc[] DEFAULT_TABLE_TYPE = {"TABLE"};
67
68     private Set JavaDoc _featuresSet = new HashSet JavaDoc();
69     private Map JavaDoc _propertyMap = new HashMap JavaDoc();
70
71     public DatabaseConfig()
72     {
73         setFeature(FEATURE_BATCHED_STATEMENTS, false);
74         setFeature(FEATURE_QUALIFIED_TABLE_NAMES, false);
75         setFeature(FEATURE_DATATYPE_WARNING, true);
76
77         setProperty(PROPERTY_STATEMENT_FACTORY, PREPARED_STATEMENT_FACTORY);
78         setProperty(PROPERTY_RESULTSET_TABLE_FACTORY, RESULT_SET_TABLE_FACTORY);
79         setProperty(PROPERTY_DATATYPE_FACTORY, DEFAULT_DATA_TYPE_FACTORY);
80         setProperty(PROPERTY_ESCAPE_PATTERN, DEFAULT_ESCAPE_PATTERN);
81         setProperty(PROPERTY_TABLE_TYPE, DEFAULT_TABLE_TYPE);
82     }
83
84     /**
85      * Set the value of a feature flag.
86      *
87      * @param name the feature id
88      * @param value the feature status
89      */

90     public void setFeature(String JavaDoc name, boolean value)
91     {
92         if (value)
93         {
94             _featuresSet.add(name);
95         }
96         else
97         {
98             _featuresSet.remove(name);
99         }
100     }
101
102     /**
103      * Look up the value of a feature flag.
104      *
105      * @param name the feature id
106      * @return the feature status
107      */

108     public boolean getFeature(String JavaDoc name)
109     {
110         return _featuresSet.contains(name);
111     }
112
113     /**
114      * Set the value of a property.
115      *
116      * @param name the property id
117      * @param value the property value
118      */

119     public void setProperty(String JavaDoc name, Object JavaDoc value)
120     {
121         _propertyMap.put(name, value);
122     }
123
124     /**
125      * Look up the value of a property.
126      *
127      * @param name the property id
128      * @return the property value
129      */

130     public Object JavaDoc getProperty(String JavaDoc name)
131     {
132        return _propertyMap.get(name);
133     }
134
135
136 }
137
Popular Tags