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.apache.lucene.store.jdbc;
18:
19: import java.io.File;
20: import java.io.FileInputStream;
21: import java.util.Properties;
22: import javax.sql.DataSource;
23:
24: import junit.framework.TestCase;
25: import org.apache.lucene.store.jdbc.datasource.DriverManagerDataSource;
26: import org.apache.lucene.store.jdbc.datasource.TransactionAwareDataSourceProxy;
27: import org.apache.lucene.store.jdbc.dialect.Dialect;
28: import org.apache.lucene.store.jdbc.dialect.DialectResolver;
29: import org.apache.lucene.store.jdbc.support.JdbcTemplate;
30:
31: /**
32: * @author kimchy
33: */
34: public abstract class AbstractJdbcDirectoryTests extends TestCase {
35:
36: private String dialect;
37:
38: protected DataSource dataSource;
39:
40: protected JdbcTemplate jdbcTemplate;
41:
42: protected void setUp() throws Exception {
43: File testPropsFile = new File("compass.test.properties");
44: Properties testProps = new Properties();
45: if (testPropsFile.exists()) {
46: testProps.load(new FileInputStream(testPropsFile));
47: }
48: String url = testProps.getProperty("compass.engine.connection");
49: if (url == null || !url.startsWith("jdbc://")) {
50: url = "jdbc:hsqldb:mem:test";
51: } else {
52: url = url.substring("jdbc://".length());
53: }
54: String driver = testProps.getProperty(
55: "compass.engine.store.jdbc.connection.driverClass",
56: "org.hsqldb.jdbcDriver");
57: String username = testProps.getProperty(
58: "compass.engine.store.jdbc.connection.username", "sa");
59: String password = testProps.getProperty(
60: "compass.engine.store.jdbc.connection.password", "");
61: DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource(
62: driver, url, username, password, false);
63: this .dataSource = new TransactionAwareDataSourceProxy(
64: driverManagerDataSource);
65: dialect = testProps
66: .getProperty("compass.engine.store.jdbc.dialect");
67: this .jdbcTemplate = new JdbcTemplate(dataSource,
68: new JdbcDirectorySettings());
69: }
70:
71: protected void tearDown() throws Exception {
72: }
73:
74: protected Dialect createDialect() throws Exception {
75: if (dialect == null) {
76: return new DialectResolver().getDialect(dataSource);
77: }
78: return (Dialect) Class.forName(dialect).newInstance();
79: }
80: }
|