1 package org
.argeo
.slc
.support
.deploy
.db
;
3 import java
.sql
.SQLException
;
5 import org
.apache
.commons
.logging
.Log
;
6 import org
.apache
.commons
.logging
.LogFactory
;
7 import org
.argeo
.slc
.core
.SlcException
;
8 import org
.argeo
.slc
.core
.UnsupportedException
;
9 import org
.argeo
.slc
.core
.build
.Distribution
;
10 import org
.argeo
.slc
.core
.deploy
.DeployedSystem
;
11 import org
.argeo
.slc
.core
.deploy
.Deployment
;
12 import org
.argeo
.slc
.core
.deploy
.DeploymentData
;
13 import org
.argeo
.slc
.core
.deploy
.TargetData
;
14 import org
.dbunit
.DataSourceDatabaseTester
;
15 import org
.dbunit
.DatabaseUnitException
;
16 import org
.dbunit
.IDatabaseTester
;
17 import org
.dbunit
.database
.IDatabaseConnection
;
18 import org
.dbunit
.dataset
.IDataSet
;
19 import org
.dbunit
.operation
.DatabaseOperation
;
21 public class DbUnitDeployment
implements Deployment
{
22 private static Log log
= LogFactory
.getLog(DbUnitDeployment
.class);
24 private JdbcAware mxDatabase
;
25 private DbUnitDeploymentData deploymentData
;
26 private DbModel dbModel
;
28 public void execute() {
30 IDatabaseTester databaseTester
= new DataSourceDatabaseTester(
31 mxDatabase
.getDataSource());
32 databaseTester
.setSetUpOperation(new DatabaseOperation() {
35 public void execute(IDatabaseConnection connection
,
36 IDataSet dataSet
) throws DatabaseUnitException
,
38 if (dbModel
!= null) {
39 dbModel
.createSchema(connection
.getConnection());
40 DatabaseOperation
.INSERT
.execute(connection
, dataSet
);
42 DatabaseOperation
.UPDATE
.execute(connection
, dataSet
);
47 databaseTester
.setDataSet(deploymentData
.createDataSet());
48 databaseTester
.onSetup();
49 databaseTester
.onTearDown();
51 log
.info("Database deployed.");
52 } catch (Exception e
) {
53 throw new SlcException("Could not initialize the database", e
);
57 public DeployedSystem
getDeployedSystem() {
58 // TODO: think of a more generic approach. MxDtaabse deployed system?
59 // (with deployment id etc.)
60 throw new UnsupportedException("Method not supported");
63 public void setDbModel(DbModel dbModel
) {
64 this.dbModel
= dbModel
;
67 public void setDeploymentData(DeploymentData deploymentData
) {
68 this.deploymentData
= (DbUnitDeploymentData
) deploymentData
;
71 public void setTargetData(TargetData targetData
) {
72 this.mxDatabase
= (JdbcAware
) targetData
;
76 public void setDistribution(Distribution distribution
) {
77 throw new UnsupportedException("Method not supported");