Started with the separated DB with the given code
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / AccountManager.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5
6 import javax.mail.MessagingException;
7
8 import common.AccountInterface;
9
10 import dataAccess.DB4oManager;
11 import domain.Account;
12 import domain.Administrator;
13 import domain.Owner;
14
15 public class AccountManager extends UnicastRemoteObject implements
16                 AccountInterface {
17
18         /**
19          * 
20          */
21         private static final long serialVersionUID = 1L;
22         private DB4oManager dbMngr;
23
24         public AccountManager() throws RemoteException {
25                 try {
26                         dbMngr = DB4oManager.getInstance();
27                 } catch (Exception e) {
28
29                         e.printStackTrace();
30                 }
31         }
32
33         public boolean addAccount(int index) throws RemoteException {
34                 Account ac = Administrator.getInstance().getNewOwnerRequest()
35                                 .get(index);
36                 if (this.dbMngr.addAccount(ac)) {
37                         try {
38                                 MailManager.getInstance().Send(ac.getOwner().getMailAccount(),
39                                                 "Entered into the system", "Congratulations");
40                         } catch (MessagingException e) {
41                                 e.printStackTrace();
42                         }
43                         return true;
44                 }
45                 return false;
46
47         }
48
49         public boolean removeAccount(int index) throws RemoteException {
50                 AdminManager adm = new AdminManager();
51                 Owner own = adm.getAllOwners().get(index);
52                 try {
53                         if (this.dbMngr.removeAccount(own)) {
54                                 try {
55                                         MailManager.getInstance().Send(own.getMailAccount(), "Removed from the system", "We are sorry");
56                                 } catch (MessagingException e) {
57                                         e.printStackTrace();
58                                 }
59                                 return true;
60                         }
61                 } catch (Exception e) {
62                         e.printStackTrace();
63                 }
64                 return false;
65
66         }
67 }