-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit.db;\r
-\r
-import java.sql.SQLException;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.UnsupportedException;\r
-import org.argeo.slc.build.Distribution;\r
-import org.argeo.slc.deploy.DeployedSystem;\r
-import org.argeo.slc.deploy.Deployment;\r
-import org.argeo.slc.deploy.DeploymentData;\r
-import org.argeo.slc.deploy.TargetData;\r
-import org.argeo.slc.support.deploy.db.DbModel;\r
-import org.argeo.slc.support.deploy.db.JdbcAware;\r
-import org.dbunit.DataSourceDatabaseTester;\r
-import org.dbunit.DatabaseUnitException;\r
-import org.dbunit.IDatabaseTester;\r
-import org.dbunit.database.IDatabaseConnection;\r
-import org.dbunit.dataset.IDataSet;\r
-import org.dbunit.operation.DatabaseOperation;\r
-\r
-public class DbUnitDeployment implements Deployment {\r
- private static Log log = LogFactory.getLog(DbUnitDeployment.class);\r
-\r
- private JdbcAware jdbcAware;\r
- private DbUnitDeploymentData deploymentData;\r
- private DbModel dbModel;\r
-\r
- public void run() {\r
- try {\r
- IDatabaseTester databaseTester = new DataSourceDatabaseTester(\r
- jdbcAware.getDataSource());\r
- databaseTester.setSetUpOperation(new DatabaseOperation() {\r
-\r
- @Override\r
- public void execute(IDatabaseConnection connection,\r
- IDataSet dataSet) throws DatabaseUnitException,\r
- SQLException {\r
- if (dbModel != null) {\r
- dbModel.createSchema(connection.getConnection());\r
- DatabaseOperation.INSERT.execute(connection, dataSet);\r
- } else {\r
- DatabaseOperation.UPDATE.execute(connection, dataSet);\r
- }\r
- }\r
-\r
- });\r
- databaseTester.setDataSet(deploymentData.createDataSet());\r
- databaseTester.onSetup();\r
- databaseTester.onTearDown();\r
-\r
- log.info("Database deployed.");\r
- } catch (Exception e) {\r
- throw new SlcException("Could not initialize the database", e);\r
- }\r
- }\r
-\r
- public DeployedSystem getDeployedSystem() {\r
- throw new UnsupportedOperationException();\r
- }\r
-\r
- public void setDbModel(DbModel dbModel) {\r
- this.dbModel = dbModel;\r
- }\r
-\r
- public void setDeploymentData(DeploymentData deploymentData) {\r
- this.deploymentData = (DbUnitDeploymentData) deploymentData;\r
- }\r
-\r
- public void setTargetData(TargetData targetData) {\r
- this.jdbcAware = (JdbcAware) targetData;\r
-\r
- }\r
-\r
- public void setDistribution(Distribution distribution) {\r
- throw new UnsupportedException("Method not supported");\r
- }\r
-\r
-}\r