2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.system.components;
18 import org.wamblee.support.persistence.Database;
19 import org.wamblee.support.persistence.DerbyDatabase;
21 import org.wamblee.system.components.ORMappingConfig.DatabaseType;
22 import org.wamblee.system.core.AbstractComponent;
23 import org.wamblee.system.core.DefaultProvidedInterface;
24 import org.wamblee.system.core.ProvidedInterface;
25 import org.wamblee.system.core.Scope;
27 import java.util.Properties;
34 public class DatabaseComponent extends AbstractComponent<Database> {
35 private static ProvidedInterface DB_PROPS = new DefaultProvidedInterface(
36 "dbProps", Properties.class);
38 private Database database;
41 * Creates a new DatabaseComponent object.
44 public DatabaseComponent(String aName, Database aDatabase) {
47 addProvidedInterface(DB_PROPS);
51 protected Database doStart(Scope aScope) {
54 Properties props = new Properties();
56 if (database instanceof DerbyDatabase) {
57 props.put("database.type", DatabaseType.DERBY.toString());
59 throw new IllegalArgumentException("Unknown database type " +
63 // props.put("database.driver", database.getDriverClassName());
64 props.put("database.url", database.getJdbcUrl());
65 props.put("database.username", database.getUsername());
66 props.put("database.password", database.getPassword());
68 addInterface(DB_PROPS, props, aScope);
74 protected void doStop(Database aRuntime) {