conn.close();
}
@Override
public Object find(Object primaryKey) throws SQLException {
Usuario u = null;
PreparedStatement st = conn
.prepareStatement("select u.username, u.senha, u.nome, t.id ,t.descricao from usuario u join tipousuario t on u.tipousuarioId = t.id where username = ? order by u.username");
st.setString(1, primaryKey.toString());
ResultSet r = st.executeQuery();
if (r.next()) {
st = conn
.prepareStatement("select o.id, o.descricao, o.comando from tipousuariooperacoes uo join operacao o on uo.operacaoId = o.id where uo.tipousuarioId = ?");
st.setInt(1, r.getInt(4));
ResultSet op = st.executeQuery();
HashSet<Operacao> operacoes = new HashSet<Operacao>();
while (op.next()) {
operacoes.add(new Operacao(op.getInt(1), op.getString(2),op.getString(3)));
}
u = new Usuario(r.getString(1), r.getString(2), r.getString(3),
new TipoUsuario(r.getInt(4), r.getString(5), operacoes));
}
return u;
}