X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcomponents%2FDatabaseComponent.java;fp=system%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcomponents%2FDatabaseComponent.java;h=5ec58512e87cdef6b0cbd72665da1dfb06a54cb6;hb=756145743d46d1cf4e4e32c03a32526aa059f1e1;hp=0000000000000000000000000000000000000000;hpb=a659fd277f9e80c30facc00c210cecd6f442901b;p=utils diff --git a/system/general/src/test/java/org/wamblee/system/components/DatabaseComponent.java b/system/general/src/test/java/org/wamblee/system/components/DatabaseComponent.java new file mode 100644 index 00000000..5ec58512 --- /dev/null +++ b/system/general/src/test/java/org/wamblee/system/components/DatabaseComponent.java @@ -0,0 +1,64 @@ +/* + * Copyright 2008 the original author or authors. + * + * Licensed 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.wamblee.system.components; + +import java.util.Properties; + +import org.wamblee.persistence.Database; +import org.wamblee.persistence.DerbyDatabase; +import org.wamblee.system.components.ORMappingConfig.DatabaseType; +import org.wamblee.system.core.AbstractComponent; +import org.wamblee.system.core.DefaultProvidedInterface; +import org.wamblee.system.core.ProvidedInterface; +import org.wamblee.system.core.Scope; + +public class DatabaseComponent extends AbstractComponent { + + private static ProvidedInterface DB_PROPS = new DefaultProvidedInterface("dbProps", Properties.class); + + private Database _database; + + public DatabaseComponent(String aName, Database aDatabase) { + super(aName); + _database = aDatabase; + addProvidedInterface(DB_PROPS); + } + + @Override + protected Database doStart(Scope aScope) { + _database.start(); + + Properties props = new Properties(); + if ( _database instanceof DerbyDatabase ) { + props.put("database.type", DatabaseType.DERBY.toString()); + } else { + throw new IllegalArgumentException("Unknown database type " + _database); + } + props.put("database.driver", _database.getDriverClassName()); + props.put("database.url", _database.getJdbcUrl()); + props.put("database.username", _database.getUsername()); + props.put("database.password", _database.getPassword()); + + addInterface(DB_PROPS, props, aScope); + return _database; + } + + @Override + protected void doStop(Database aRuntime) { + _database.stop(); + } + +}