Marcos
Marcos

Reputation: 4643

Using DAO with JDBC

I have an architecture that looks like this: (client: android, server: web services axis2)

Presentation layer (Android activities and controllers):
    LoginActivity.java

WebServices Layer:
    Services.java

Domain Layer:
    userManagement:
        UserManager.java
    entities (POJOS):
        User.java

Persistence:
    IDaoUser.java
    DaoUserImpl.java

Ok. I do this to perform the login:

LoginActivity.java:
    call the web service (using AsyncTask)

Services.java
    ...
    public User login(String username, String passwd) {
        return userManager.login(username, passwd);
    }

UserManager.java:
    ...
    public UserManager() {
        IDaoUser dao = new DaoUserImpl();
    }
    public User login(String username, String passwd) {
        return dao.login(username, passwd);
    }
    ...

DaoUser.java
    ...
    public User login(String username, String passwd);

DaoUserImpl.java:
    ...
    public User login(String username, String passwd) {
        /* JDBC stuff */
    }
    ...

Is this approach correct? (or at least, does it make sense?). In DaoUserImpl.java I'm just checking if exists an user with an username and passwd equals to the arguments (again, I don't know if this approach is correct). Thanks.

Upvotes: 0

Views: 380

Answers (1)

wrschneider
wrschneider

Reputation: 18770

In general it looks like you're on the track. Two incremental improvements to suggest:

  1. try to see if you can do with fewer layers on the server side - perhaps you could go straight from service to DAO without a separate Manager object. You probably also don't need separate DAO interface/implementation unless you're planning to have multiple implementations.

  2. consider REST services instead of SOAP and JAX-RS instead of Axis. REST has less transport / envelope overhead so it may work better for you in a mobile application.

See: [iPhone and Web Services]: REST vs SOAP

Upvotes: 1

Related Questions