/*
- * Copyright 2008 the original author or authors.
+ * Copyright 2005-2010 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.
import java.util.Properties;
-import org.wamblee.support.persistence.Database;
-import org.wamblee.support.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;
+import org.wamblee.test.persistence.Database;
+import org.wamblee.test.persistence.DerbyDatabase;
+/**
+ *
+ * @author $author$
+ * @version $Revision$
+ */
public class DatabaseComponent extends AbstractComponent<Database> {
-
- private static ProvidedInterface DB_PROPS = new DefaultProvidedInterface("dbProps", Properties.class);
-
- private Database database;
-
- public DatabaseComponent(String aName, Database aDatabase) {
- super(aName);
+ private static ProvidedInterface DB_PROPS = new DefaultProvidedInterface(
+ "dbProps", Properties.class);
+
+ private Database database;
+
+ /**
+ * Creates a new DatabaseComponent object.
+ *
+ */
+ public DatabaseComponent(String aName, Database aDatabase) {
+ super(aName);
database = aDatabase;
addProvidedInterface(DB_PROPS);
}
@Override
protected Database doStart(Scope aScope) {
- database.start();
-
+ database.start();
+
Properties props = new Properties();
- if ( database instanceof DerbyDatabase ) {
+
+ if (database instanceof DerbyDatabase) {
props.put("database.type", DatabaseType.DERBY.toString());
- } else {
- throw new IllegalArgumentException("Unknown database type " + database);
+ } else {
+ throw new IllegalArgumentException("Unknown database type " +
+ database);
}
- //props.put("database.driver", database.getDriverClassName());
+
+ // 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;
+
+ return database;
}
@Override
protected void doStop(Database aRuntime) {
database.stop();
}
-
}