HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

DAO for happenings registration website

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
websiteregistrationdaoforhappenings

Problem

As a learn-by-doing project to learn Java webapps, I'm creating a website for registering and displaying happenings using JSP/Servlets, Apache Tomcat server, JDBC and a MySQL database.

I use JSP for views, Servlets for controller functionality and business logic, and I've created ONE DBManager.java class (my only DAO) to abstract SQL statements from my Servlets and JSPs. In my Servlets, I use the DBManager class by declaring a new instance and calling its public methods.

For instance:

DBManager dbm = new DBManager();
Boolean userIsUpdated = dbm.updateUserInDB(user);


My DAO looks briefly like this:

```
public class DBManager {

final String DATABASE_URL = "NOPE, I won't give you this one ;)";
Connection connection = null;
PreparedStatement pstmt = null;

public DBManager() {
//Nothing in constructor yet.
}

public ArrayList getAllActivatedHappenings() {
//code removed for readability
}

public User logInAndGetUserByEmailAndPassword(String email, String password) {
//code removed for readability
}

public User insertUserIntoDB(User user) {
//code removed for readability
}

public boolean updateUserInDB(User user) {
//code removed for readability
}

public boolean insertHappeningIntoDB(Happening happening) {
//code removed for readability
}

public boolean deleteHappeningFromDB(int happeningId, int userId) {
//code removed for readability
}

public ArrayList getAllHappeningTypes() {
//code removed for readability
}

public ArrayList getAllHappeningsByUserId(int userid) {
//code removed for readability
}

public byte[] getPhotoByHappeningId(int happeningId, String imageType) {
//code removed for readability
}

public Map getCountiesMap() {
//code removed for readability
}

public Boolean userIsHappeningOwner(int userId, int happeningId) {
//code removed for r

Solution

Just a quick note: ArrayList return types should be simply List. See: Effective Java, 2nd edition, Item 52: Refer to objects by their interfaces

Context

StackExchange Code Review Q#14475, answer score: 2

Revisions (0)

No revisions yet.