Changeset 28 for trunk/fmgVen/test/com/fmguler/ven/sample
- Timestamp:
- Feb 9, 2011, 10:53:45 PM (14 years ago)
- Location:
- trunk/fmgVen/test/com/fmguler/ven/sample
- Files:
-
- 1 added
- 2 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 } -
trunk/fmgVen/test/com/fmguler/ven/sample/domain/SomeDomainObject.java
r26 r28 18 18 package com.fmguler.ven.sample.domain; 19 19 20 import com.fmguler.ven.util.VenList; 20 21 import java.util.Date; 22 import java.util.List; 21 23 22 24 /** … … 29 31 private String description; 30 32 private Date date; 33 private List anotherDomainObjects = new VenList(AnotherDomainObject.class, "someDomainObject"); 34 private AnotherDomainObject anotherDomainObject = new AnotherDomainObject(); 31 35 32 36 /** … … 86 90 } 87 91 92 /** 93 * @return the list of AnotherDomainObject 94 */ 95 public List getAnotherDomainObjects() { 96 return anotherDomainObjects; 97 } 98 99 /** 100 * @return the anotherDomainObject 101 */ 102 public AnotherDomainObject getAnotherDomainObject() { 103 return anotherDomainObject; 104 } 105 106 /** 107 * @param anotherDomainObject the anotherDomainObject to set 108 */ 109 public void setAnotherDomainObject(AnotherDomainObject anotherDomainObject) { 110 this.anotherDomainObject = anotherDomainObject; 111 } 112 88 113 public String toString() { 89 return id + " " + name + " " + description + " " + date;114 return id + " " + name + " " + description + " another domain object: {" + anotherDomainObject + "} another domain objects:\n" + anotherDomainObjects; 90 115 } 91 116 }
Note: See TracChangeset
for help on using the changeset viewer.