summaryrefslogtreecommitdiffstats
path: root/das-java/tags/1.0-incubating-beta1/rdb/src/main/java/org/apache/tuscany/das/rdb/ConfigHelper.java
blob: 4560c9ea58f3912de04f8a194da080e00d6cfa34 (plain)
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
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
package org.apache.tuscany.das.rdb;

import java.util.Vector;

import org.apache.tuscany.das.rdb.config.Column;
import org.apache.tuscany.das.rdb.config.Command;
import org.apache.tuscany.das.rdb.config.Config;
import org.apache.tuscany.das.rdb.config.ConfigFactory;
import org.apache.tuscany.das.rdb.config.Relationship;
import org.apache.tuscany.das.rdb.config.Table;
import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper;

/**
 * A ConfigHelper is used as an aid in programmatic construction of Config instances.
 * Manual contrution fo COnfig is an alternative to providing needed configuration
 * information in an XML file
 * 
 */
public class ConfigHelper {

    private Config config;

    private MappingWrapper configWrapper;

    private ConfigFactory factory = ConfigFactory.INSTANCE;

    /**
     * Default constructor
     */
    public ConfigHelper() {
        config = factory.createConfig();
        configWrapper = new MappingWrapper(config);
    }

    /**
     * Constructor that receives a Config object
     * @param config The configuration object
     */
    public ConfigHelper(Config config) {
        this.config = config;
        configWrapper = new MappingWrapper(config);
    }

    /**
     * Add PK information
     * @param columnName The column to be taken as PK
     */
    public void addPrimaryKey(String columnName) {
        configWrapper.addPrimaryKey(columnName);
    }

    /**
     * Add relationship information
     * @param parentName
     * @param childName
     * @return
     */
    public Relationship addRelationship(String parentName, String childName) {
        return configWrapper.addRelationship(parentName, childName);
    }
    
    /**
     * Add relationship information
     * @param parentNames
     * @param childNames
     * @return
     */
    public Relationship addRelationship(Vector parentNames, Vector childNames) {
        return configWrapper.addRelationship(parentNames, childNames);
    }

    /**
     * Add table information
     * @param name
     * @param typeName
     * @return
     */
    public Table addTable(String name, String typeName) {
        return configWrapper.addTable(name, typeName);
    }
    
    /**
     * Add table information with schema information
     * @param name
     * @param schemaName
     * @param typeName
     * @return
     */
    public Table addTable(String name, String schemaName, String typeName) {
        return configWrapper.addTable(name, schemaName, typeName);
    }
    
    /**
     * Add column information
     * @param table
     * @param columnName
     * @param propertyName
     * @return
     */
    public Column addColumn(Table table, String columnName, String propertyName) {
        return configWrapper.addColumn(table, columnName, propertyName);
    }

    /**
     * Add an update statement for a given table
     * @param table
     * @param statement
     * @param parameters
     */
    public void addUpdateStatement(Table table, String statement, String parameters) {
        configWrapper.addUpdateStatement(table, statement, parameters);
    }

    /**
     * Add create statement for a given table
     * @param table
     * @param statement
     * @param parameters
     */
    public void addCreateStatement(Table table, String statement, String parameters) {
        configWrapper.addCreateStatement(table, statement, parameters);
    }

    /**
     * Add delete statement for a given table
     * @param table
     * @param statement
     * @param parameters
     */
    public void addDeleteStatement(Table table, String statement, String parameters) {
        configWrapper.addDeleteStatement(table, statement, parameters);
    }

    /**
     * Add datasource connection information
     * @param dataSourceName
     */
    public void addConnectionInfo(String dataSourceName) {
        configWrapper.addConnectionInfo(dataSourceName, true);
    }

    /**
     * Add datasource connection information and flag about using managed transactions
     * @param dataSourceName
     * @param managedtx
     */
    public void addConnectionInfo(String dataSourceName, boolean managedtx) {
        configWrapper.addConnectionInfo(dataSourceName, managedtx);
    }

    /**
     * Add driver manager connection information
     * @param driverClass
     * @param databaseURL
     * @param user
     * @param password
     * @param loginTimeout
     */
    public void addConnectionInfo(String driverClass, String databaseURL, String user, String password, int loginTimeout) {
        configWrapper.addConnectionInfo(driverClass, databaseURL, user, password, loginTimeout);
    }

    /**
     * Set the data object model
     * @param dataObjectModel
     */
    public void setDataObjectModel(String dataObjectModel) {
        configWrapper.getConfig().setDataObjectModel(dataObjectModel);
    }

    /**
     * Add a select command
     * @param name
     * @param sql
     * @return
     */
    public Command addSelectCommand(String name, String sql) {
        return configWrapper.addCommand(name, sql, "select");
    }

    /**
     * Add a update command
     * @param name
     * @param sql
     * @return
     */
    public Command addUpdateCommand(String name, String sql) {
        return configWrapper.addCommand(name, sql, "update");
    }

    /**
     * Add a insert command
     * @param name
     * @param sql
     * @return
     */
    public Command addInsertCommand(String name, String sql) {
        return configWrapper.addCommand(name, sql, "insert");
    }

    /**
     * Add a delete command
     * @param name
     * @param sql
     * @return
     */
    public Command addDeleteCommand(String name, String sql) {
        return configWrapper.addCommand(name, sql, "delete");
    }

    /**
     * Get a reference to the config object
     * @return
     */
    public Config getConfig() {
        return config;
    }

}