01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.lucene.engine.store.jdbc;
18:
19: import javax.sql.DataSource;
20:
21: import org.compass.core.CompassException;
22: import org.compass.core.config.CompassSettings;
23: import org.compass.core.lucene.LuceneEnvironment;
24:
25: /**
26: * @author kimchy
27: */
28: public abstract class AbstractDataSourceProvider implements
29: DataSourceProvider {
30:
31: private DataSource dataSource;
32:
33: protected String driverClass;
34:
35: protected String username;
36:
37: protected String password;
38:
39: protected boolean autoCommit;
40:
41: protected boolean externalAutoCommit;
42:
43: public void configure(String url, CompassSettings settings)
44: throws CompassException {
45: driverClass = settings
46: .getSetting(LuceneEnvironment.JdbcStore.Connection.DRIVER_CLASS);
47: username = settings
48: .getSetting(LuceneEnvironment.JdbcStore.Connection.USERNAME);
49: password = settings
50: .getSetting(LuceneEnvironment.JdbcStore.Connection.PASSWORD);
51: String autoCommitSetting = settings.getSetting(
52: LuceneEnvironment.JdbcStore.Connection.AUTO_COMMIT,
53: "false");
54: if ("external".equalsIgnoreCase(autoCommitSetting)) {
55: externalAutoCommit = true;
56: } else {
57: externalAutoCommit = false;
58: autoCommit = "true".equalsIgnoreCase(autoCommitSetting);
59: }
60: this .dataSource = doCreateDataSource(url, settings);
61: }
62:
63: public DataSource getDataSource() {
64: return this .dataSource;
65: }
66:
67: public void closeDataSource() {
68: // do nothing
69: }
70:
71: protected abstract DataSource doCreateDataSource(String url,
72: CompassSettings settings) throws CompassException;
73: }
|