Changeset 28 for trunk/fmgVen/test/com/fmguler/ven/sample/Sample.java
- Timestamp:
- Feb 9, 2011, 10:53:45 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fmgVen/test/com/fmguler/ven/sample/Sample.java
r27 r28 18 18 package com.fmguler.ven.sample; 19 19 20 import com.fmguler.ven.LiquibaseUtil; 20 21 import com.fmguler.ven.Ven; 22 import com.fmguler.ven.sample.domain.AnotherDomainObject; 21 23 import com.fmguler.ven.sample.domain.SomeDomainObject; 22 import java.sql.SQLException;23 24 import java.util.Date; 25 import java.util.HashSet; 24 26 import java.util.List; 25 import java.util.Locale; 26 import javax.sql.DataSource; 27 import liquibase.FileSystemFileOpener; 28 import liquibase.exception.JDBCException; 29 import liquibase.exception.LiquibaseException; 30 import org.springframework.jdbc.datasource.DriverManagerDataSource; 31 import liquibase.Liquibase; 32 import liquibase.database.Database; 33 import liquibase.database.DatabaseFactory; 27 import java.util.Set; 34 28 35 29 /** … … 40 34 public static void main(String[] args) { 41 35 //build the sample database 42 buildDatabase();36 LiquibaseUtil.buildDatabase(); 43 37 44 38 //save an object 45 39 testSave(); 40 //get an object 41 testGet(); 46 42 //delete an object 47 43 testDelete(); 48 44 49 45 //rollback the sample database to original state 50 rollbackDatabase();46 LiquibaseUtil.rollbackDatabase("tag-init"); 51 47 } 52 48 … … 76 72 public static void testDelete() { 77 73 Ven ven = getVen(); 78 ven.delete( 1, SomeDomainObject.class);74 ven.delete(2, SomeDomainObject.class); 79 75 } 80 76 … … 84 80 public static void testGet() { 85 81 Ven ven = getVen(); 86 SomeDomainObject obj = (SomeDomainObject)ven.get(1, SomeDomainObject.class); 82 83 //get with includes 84 Set joins = new HashSet(); 85 joins.add("SomeDomainObject.anotherDomainObjects"); 86 joins.add("SomeDomainObject.anotherDomainObject"); 87 SomeDomainObject obj = (SomeDomainObject)ven.get(1, SomeDomainObject.class, joins); 87 88 System.out.println(obj); 89 90 Set joins2 = new HashSet(); 91 joins2.add("AnotherDomainObject.someDomainObject"); 92 AnotherDomainObject obj2 = (AnotherDomainObject)ven.get(1, AnotherDomainObject.class, joins2); 93 System.out.println(obj2); 88 94 } 89 95 … … 109 115 private static Ven getVen() { 110 116 Ven ven = new Ven(); 111 ven.setDataSource( getDataSource());117 ven.setDataSource(LiquibaseUtil.getDataSource()); 112 118 ven.addDomainPackage("com.fmguler.ven.sample.domain").addDomainPackage("another.package"); 113 119 return ven; 114 120 } 115 116 private static DataSource getDataSource() {117 DriverManagerDataSource ds = new DriverManagerDataSource();118 ds.setDriverClassName("org.postgresql.Driver");119 ds.setUsername("postgres");120 ds.setPassword("qwerty");121 ds.setUrl("jdbc:postgresql://127.0.0.1:5432/ven-test");122 return ds;123 }124 125 private static void buildDatabase() {126 try {127 Locale currLocale = Locale.getDefault();128 Locale.setDefault(Locale.ENGLISH);129 Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(getDataSource().getConnection());130 Liquibase liquibase = new Liquibase("etc/test-db/test-db-changelog.xml", new FileSystemFileOpener(), database);131 liquibase.update("");132 Locale.setDefault(currLocale);133 } catch (SQLException ex) {134 ex.printStackTrace();135 } catch (JDBCException ex) {136 ex.printStackTrace();137 } catch (LiquibaseException ex) {138 ex.printStackTrace();139 }140 }141 142 private static void rollbackDatabase() {143 try {144 Locale currLocale = Locale.getDefault();145 Locale.setDefault(Locale.ENGLISH);146 Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(getDataSource().getConnection());147 Liquibase liquibase = new Liquibase("etc/test-db/test-db-changelog.xml", new FileSystemFileOpener(), database);148 liquibase.rollback("tag-single-table", "");149 Locale.setDefault(currLocale);150 } catch (SQLException ex) {151 ex.printStackTrace();152 } catch (JDBCException ex) {153 ex.printStackTrace();154 } catch (LiquibaseException ex) {155 ex.printStackTrace();156 }157 }158 121 }
Note: See TracChangeset
for help on using the changeset viewer.