You need to sign in or sign up before continuing.
Commit fa5608c2 authored by Administrator's avatar Administrator

Refactorizes the backend

Some backend classes have been refactorized and simplified.
parent 940c14a8
...@@ -24,8 +24,10 @@ import es.uvigo.esei.daa.rest.UsersResource; ...@@ -24,8 +24,10 @@ import es.uvigo.esei.daa.rest.UsersResource;
public class DAAExampleApplication extends Application { public class DAAExampleApplication extends Application {
@Override @Override
public Set<Class<?>> getClasses() { public Set<Class<?>> getClasses() {
return Stream.of(PeopleResource.class, UsersResource.class) return Stream.of(
.collect(toSet()); PeopleResource.class,
UsersResource.class
).collect(toSet());
} }
@Override @Override
......
...@@ -5,7 +5,6 @@ import java.sql.SQLException; ...@@ -5,7 +5,6 @@ import java.sql.SQLException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.sql.DataSource; import javax.sql.DataSource;
...@@ -27,11 +26,8 @@ public abstract class DAO { ...@@ -27,11 +26,8 @@ public abstract class DAO {
* Constructs a new instance of {@link DAO}. * Constructs a new instance of {@link DAO}.
*/ */
public DAO() { public DAO() {
Context initContext;
try { try {
initContext = new InitialContext(); this.dataSource = (DataSource) new InitialContext().lookup(JNDI_NAME);
this.dataSource = (DataSource) initContext.lookup(JNDI_NAME);
} catch (NamingException e) { } catch (NamingException e) {
LOG.log(Level.SEVERE, "Error initializing DAO", e); LOG.log(Level.SEVERE, "Error initializing DAO", e);
throw new RuntimeException(e); throw new RuntimeException(e);
......
...@@ -19,6 +19,7 @@ import es.uvigo.esei.daa.entities.User; ...@@ -19,6 +19,7 @@ import es.uvigo.esei.daa.entities.User;
public class UsersDAO extends DAO { public class UsersDAO extends DAO {
private final static Logger LOG = Logger.getLogger(UsersDAO.class.getName()); private final static Logger LOG = Logger.getLogger(UsersDAO.class.getName());
// Yes, SALT should come from external configuration (for example, a property in Tomcat's context).
private final static String SALT = "daaexample-"; private final static String SALT = "daaexample-";
/** /**
......
...@@ -89,7 +89,7 @@ public class Person { ...@@ -89,7 +89,7 @@ public class Person {
return true; return true;
if (obj == null) if (obj == null)
return false; return false;
if (getClass() != obj.getClass()) if (!(obj instanceof Person))
return false; return false;
Person other = (Person) obj; Person other = (Person) obj;
if (id != other.id) if (id != other.id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment