empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1526840 - in /empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db: SampleApp.java SampleDB.java
Date Fri, 27 Sep 2013 09:21:36 GMT
Author: doebele
Date: Fri Sep 27 09:21:35 2013
New Revision: 1526840

URL: http://svn.apache.org/r1526840
Log:
Improved definition of Gender options in example.

Modified:
    empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
    empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleDB.java

Modified: empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java?rev=1526840&r1=1526839&r2=1526840&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
(original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
Fri Sep 27 09:21:35 2013
@@ -34,6 +34,7 @@ import org.apache.empire.db.derby.DBData
 import org.apache.empire.db.h2.DBDatabaseDriverH2;
 import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
 import org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL;
+import org.apache.empire.samples.db.SampleDB.Gender;
 import org.apache.empire.xml.XMLWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -117,9 +118,9 @@ public class SampleApp 
 			int idDevDep = insertDepartment(conn, "Development", "ITTK");
 			int idSalDep = insertDepartment(conn, "Sales", "ITTK");
 			// Insert Employees
-			int idPers1 = insertEmployee(conn, "Peter", "Sharp", "M", idDevDep);
-			int idPers2 = insertEmployee(conn, "Fred", "Bloggs", "M", idDevDep);
-			int idPers3 = insertEmployee(conn, "Emma", "White", "F", idSalDep);
+			int idPers1 = insertEmployee(conn, "Peter", "Sharp", Gender.M, idDevDep);
+			int idPers2 = insertEmployee(conn, "Fred", "Bloggs", Gender.M, idDevDep);
+			int idPers3 = insertEmployee(conn, "Emma", "White",  Gender.F, idSalDep);
 
 			// STEP 7: Update Records (by setting the phone Number)
 			System.out.println("*** Step 7: updateEmployee() ***");
@@ -295,7 +296,7 @@ public class SampleApp 
 	 * Inserts an Employee into the Employees table.
      * </PRE>
 	 */
-	private static int insertEmployee(Connection conn, String firstName, String lastName, String
gender, int departmentId)
+	private static int insertEmployee(Connection conn, String firstName, String lastName, Gender
gender, int departmentId)
     {
 		// Insert an Employee
 		DBRecord rec = new DBRecord();
@@ -445,13 +446,13 @@ public class SampleApp 
 	{
         // Query all males
 	    BeanResult<SampleBean> result = new BeanResult<SampleBean>(SampleBean.class,
db.EMPLOYEES);
-        result.getCommand().where(db.EMPLOYEES.GENDER.is("M"));
+        result.getCommand().where(db.EMPLOYEES.GENDER.is(Gender.M));
 	    result.fetch(conn);
 	    
 	    System.out.println("Number of male employees is: "+result.size());
 
 	    // And now, the females
-	    result.getCommand().where(db.EMPLOYEES.GENDER.is("F"));
+	    result.getCommand().where(db.EMPLOYEES.GENDER.is(Gender.F));
 	    result.fetch(conn);
 	    
         System.out.println("Number of female employees is: "+result.size());

Modified: empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleDB.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleDB.java?rev=1526840&r1=1526839&r2=1526840&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleDB.java
(original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleDB.java
Fri Sep 27 09:21:35 2013
@@ -44,6 +44,12 @@ import org.apache.empire.db.DBTableColum
 public class SampleDB extends DBDatabase
 {
     private final static long serialVersionUID = 1L;
+    
+    public enum Gender
+    {
+    	M,	// Male
+    	F; 	// Female
+    }
 
     /**
      * This class represents the definition of the Departments table.
@@ -123,8 +129,8 @@ public class SampleDB extends DBDatabase
 
             // Create Options for GENDER column
             Options genders = new Options();
-            genders.set("M", "Male");
-            genders.set("F", "Female");
+            genders.set(Gender.M, "Male");
+            genders.set(Gender.F, "Female");
             GENDER.setOptions(genders);
         }
     }



Mime
View raw message