Possibility of registering new owners added
[RRRRHHHH_Code] / ruralHouses / src / dataAccess / DB4oManager.java
index 5ccfda4..61dd24b 100644 (file)
@@ -119,18 +119,18 @@ public class DB4oManager {
        public void initializeDB() {
 
                try {
-                       Owner jon = new Owner("Jon");
-                       Owner alfredo = new Owner("Alfredo");
+                       Owner jon = new Owner("Jon", "1349 5677 21 2133567777",
+                                       "Jon@gmail.com");
+                       Owner alfredo = new Owner("Alfredo", "4144 0087 23 9700002133",
+                                       "alfredo@gmail.com");
                        jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Beatriz", 3, 3, 3,
                                        3, 3);
                        jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Guazate", 4, 4,
                                        4, 4, 4);
-                       jon.setBankAccount("1349 5677 21 2133567777");
                        alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Vegas", 5, 5,
                                        5, 5, 5);
 
                        alfredo.addRuralHouse("Murgoitz", "", "Cedro", 6, 6, 6, 6, 6);
-                       alfredo.setBankAccount("4144 0087 23 9700002133");
                        Account jonAcc = new Account("1", "1", jon);
                        Account alfredoAcc = new Account("userAlfredo", "passAlfredo",
                                        alfredo);
@@ -154,7 +154,7 @@ public class DB4oManager {
                        openDB();
 
                try {
-                       Owner proto = new Owner(null, null);
+                       Owner proto = new Owner(null, null, null);
                        ObjectSet<Owner> result = db.queryByExample(proto);
                        while (result.hasNext()) {
                                Owner o = (Owner) result.next();
@@ -219,7 +219,6 @@ public class DB4oManager {
                }
        }
 
-
        public Administrator getAdminData() {
                if (c.isDatabaseLocal() == false)
                        openSDB();
@@ -266,10 +265,12 @@ public class DB4oManager {
                                }
                        });
 
-                       
-                       admL.get(0).setAddRequest(Administrator.getInstance().getAddRequest());
-                       admL.get(0).setRemoveRequest(Administrator.getInstance().getRemoveRequest());
-                       admL.get(0).setNewOwnerRequest(Administrator.getInstance().getNewOwnerRequest());
+                       admL.get(0).setAddRequest(
+                                       Administrator.getInstance().getAddRequest());
+                       admL.get(0).setRemoveRequest(
+                                       Administrator.getInstance().getRemoveRequest());
+                       admL.get(0).setNewOwnerRequest(
+                                       Administrator.getInstance().getNewOwnerRequest());
                        db.commit();
 
                } catch (Exception e) {
@@ -344,7 +345,7 @@ public class DB4oManager {
                        openDB();
 
                try {
-                       Owner proto = new Owner(null, null);
+                       Owner proto = new Owner(null, null, null);
                        ObjectSet<Owner> result = db.queryByExample(proto);
                        Vector<Owner> owners = new Vector<Owner>();
                        while (result.hasNext())
@@ -417,8 +418,8 @@ public class DB4oManager {
         * @throws RemoteException
         * @throws Exception
         */
-       public Vector<Account> getAccount(Account proto)
-                       throws RemoteException, Exception {
+       public Vector<Account> getAccount(Account proto) throws RemoteException,
+                       Exception {
 
                if (c.isDatabaseLocal() == false)
                        openSDB();
@@ -516,4 +517,28 @@ public class DB4oManager {
 
        }
 
+       public boolean addAccount(Account acc) {
+               if (c.isDatabaseLocal() == false)
+                       openSDB();
+               else
+                       openDB();
+
+               try {
+                               //TODO realize if there is another account with same username. Quite difficult with the f***ing salt
+                               db.store(acc);
+                               db.commit();
+               } catch (Exception exc) {
+                       exc.printStackTrace();
+               } finally {
+                       db.close();
+               }
+               return true;
+       }
+       
+       //TODO remove account
+
+       public boolean removeAccount(Account acc) {
+               return false;
+       }
+
 }