} else // c.getDataBaseOpenMode().equals("open")
{
- ObjectSet<DB4oManagerAux> res = db.queryByExample(DB4oManagerAux.class);
+ ObjectSet<DB4oManagerAux> res = db
+ .queryByExample(DB4oManagerAux.class);
ListIterator<DB4oManagerAux> listIter = res.listIterator();
if (listIter.hasNext())
theDB4oManagerAux = (DB4oManagerAux) res.next();
configuration.common().updateDepth(c.getUpdateDepth());
configuration.common().objectClass(Owner.class).cascadeOnUpdate(true);
configuration.common().objectClass(Owner.class).cascadeOnDelete(true);
- configuration.common().objectClass(RuralHouse.class).cascadeOnUpdate(true);
+ configuration.common().objectClass(RuralHouse.class)
+ .cascadeOnUpdate(true);
configuration.common().objectClass(Account.class).cascadeOnUpdate(true);
db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename());
}
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);
- Account admin = new Account("admin","admin", true);
- db.store(Administrator.giveAdmin());
+ Account admin = new Account("admin", "admin", true);
+ db.store(Administrator.getInstance());
db.store(jonAcc);
db.store(alfredoAcc);
db.store(admin);
db.commit();
} finally {
- db.close();
+ db.close();
}
}
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();
return o;
}
-
- public void deleteOffer(Offer offer) throws RemoteException,
- Exception {
+ public void deleteOffer(Offer offer) throws RemoteException, Exception {
if (c.isDatabaseLocal() == false)
openSDB();
else
try {
ObjectSet<Offer> of = db.queryByExample(offer);
- RuralHouse rh =of.get(0).getRuralHouse();
+ RuralHouse rh = of.get(0).getRuralHouse();
System.out.println(rh.offers.remove(of.get(0)));
db.store(rh);
db.commit();
}
}
-
- @SuppressWarnings("static-access")
- public LinkedList<RuralHouse>[] getAdminData(){
+ public Administrator getAdminData() {
if (c.isDatabaseLocal() == false)
openSDB();
else
openDB();
- @SuppressWarnings("unchecked")
- LinkedList<RuralHouse>[] ret = new LinkedList[2];
-
+
try {
-
- List<Administrator> admL = db.query(new Predicate<Administrator>(){
+
+ List<Administrator> admL = db.query(new Predicate<Administrator>() {
/**
*
*/
private static final long serialVersionUID = 1L;
- public boolean match(Administrator admin){
+ public boolean match(Administrator admin) {
return true;
}
});
-
- ret[0] = admL.get(0).getAddRequest();
- ret[1] = admL.get(0).getRemoveRequest();
- return ret;
- }
- finally {
+
+ return admL.get(0);
+ } finally {
db.close();
-
+
}
-
+
}
-
+
@SuppressWarnings("static-access")
public void storeAdmin() {
if (c.isDatabaseLocal() == false)
openSDB();
else
- openDB();
+ openDB();
try {
-
- List<Administrator> admL = db.query(new Predicate<Administrator>(){
+
+ List<Administrator> admL = db.query(new Predicate<Administrator>() {
/**
*
*/
private static final long serialVersionUID = 1L;
- public boolean match(Administrator admin){
+ public boolean match(Administrator admin) {
return true;
}
});
-
- admL.get(0).setAddRequest(Administrator.getAddRequest());
- admL.get(0).setRemoveRequest(Administrator.getRemoveRequest());
+
+ 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){
-
- }
- finally {
+
+ } catch (Exception e) {
+
+ } finally {
db.close();
}
-
-
+
}
-
-
+
/**
* This method creates a book with a corresponding parameters
*
openDB();
Booking bok = null;
-
try {
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())
/**
* @param usr
- * @param pwd
+ * @param ps
* @return
* @throws RemoteException
* @throws Exception
*/
- public Vector<Account> getAccount(String usr, String pwd)
- throws RemoteException, Exception {
+ public Vector<Account> getAccount(Account proto) throws RemoteException,
+ Exception {
if (c.isDatabaseLocal() == false)
openSDB();
openDB();
try {
- Account proto = new Account(usr, pwd, null);
ObjectSet<Account> result = db.queryByExample(proto);
Vector<Account> accounts = new Vector<Account>();
while (result.hasNext())
ObjectSet<Owner> result = db.queryByExample(owner);
ObjectSet<RuralHouse> rhs = db.queryByExample(rh);
if (!rhs.isEmpty()) {
- Owner found = result.get(0);
+ Owner found = result.get(0);
found.getRuralHouses().remove(rhs.get(0));
db.delete(rhs.get(0));
db.store(found);
}
-
public Vector<RuralHouse> getRuralHouses(String name, String town,
int nBed, int nKit, int nBath, int nPark, int nLiv) {
HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark);
}
+ 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;
+ }
+
}