1 package org
.argeo
.slc
.unit
.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
.SlcException
;
8 import org
.argeo
.slc
.UnsupportedException
;
9 import org
.argeo
.slc
.build
.Distribution
;
10 import org
.argeo
.slc
.deploy
.DeployedSystem
;
11 import org
.argeo
.slc
.deploy
.Deployment
;
12 import org
.argeo
.slc
.deploy
.DeploymentData
;
13 import org
.argeo
.slc
.deploy
.TargetData
;
14 import org
.argeo
.slc
.support
.deploy
.db
.DbModel
;
15 import org
.argeo
.slc
.support
.deploy
.db
.JdbcAware
;
16 import org
.dbunit
.DataSourceDatabaseTester
;
17 import org
.dbunit
.DatabaseUnitException
;
18 import org
.dbunit
.IDatabaseTester
;
19 import org
.dbunit
.database
.IDatabaseConnection
;
20 import org
.dbunit
.dataset
.IDataSet
;
21 import org
.dbunit
.operation
.DatabaseOperation
;
23 public class DbUnitDeployment
implements Deployment
{
24 private static Log log
= LogFactory
.getLog(DbUnitDeployment
.class);
26 private JdbcAware jdbcAware
;
27 private DbUnitDeploymentData deploymentData
;
28 private DbModel dbModel
;
32 IDatabaseTester databaseTester
= new DataSourceDatabaseTester(
33 jdbcAware
.getDataSource());
34 databaseTester
.setSetUpOperation(new DatabaseOperation() {
37 public void execute(IDatabaseConnection connection
,
38 IDataSet dataSet
) throws DatabaseUnitException
,
40 if (dbModel
!= null) {
41 dbModel
.createSchema(connection
.getConnection());
42 DatabaseOperation
.INSERT
.execute(connection
, dataSet
);
44 DatabaseOperation
.UPDATE
.execute(connection
, dataSet
);
49 databaseTester
.setDataSet(deploymentData
.createDataSet());
50 databaseTester
.onSetup();
51 databaseTester
.onTearDown();
53 log
.info("Database deployed.");
54 } catch (Exception e
) {
55 throw new SlcException("Could not initialize the database", e
);
59 public DeployedSystem
<?
> getDeployedSystem() {
60 throw new UnsupportedOperationException();
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.jdbcAware
= (JdbcAware
) targetData
;
76 public void setDistribution(Distribution distribution
) {
77 throw new UnsupportedException("Method not supported");