src/main/java/de/uapcore/lightpit/dao/postgres/PGProjectDao.java

changeset 75
33b6843fdf8a
parent 59
c759c60507a2
child 81
1a2e7b5d48f7
--- a/src/main/java/de/uapcore/lightpit/dao/postgres/PGProjectDao.java	Fri May 22 17:26:27 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/dao/postgres/PGProjectDao.java	Fri May 22 21:23:57 2020 +0200
@@ -49,29 +49,29 @@
 
     public PGProjectDao(Connection connection) throws SQLException {
         list = connection.prepareStatement(
-                "select id, name, description, repourl, " +
+                "select projectid, name, description, repourl, " +
                         "userid, username, lastname, givenname, mail " +
                         "from lpit_project " +
                         "left join lpit_user owner on lpit_project.owner = owner.userid " +
                         "order by name");
 
         find = connection.prepareStatement(
-                "select id, name, description, repourl, " +
+                "select projectid, name, description, repourl, " +
                         "userid, username, lastname, givenname, mail " +
                         "from lpit_project " +
                         "left join lpit_user owner on lpit_project.owner = owner.userid " +
-                        "where id = ?");
+                        "where projectid = ?");
 
         insert = connection.prepareStatement(
                 "insert into lpit_project (name, description, repourl, owner) values (?, ?, ?, ?)"
         );
         update = connection.prepareStatement(
-                "update lpit_project set name = ?, description = ?, repourl = ?, owner = ? where id = ?"
+                "update lpit_project set name = ?, description = ?, repourl = ?, owner = ? where projectid = ?"
         );
     }
 
     public Project mapColumns(ResultSet result) throws SQLException {
-        final var proj = new Project(result.getInt("id"));
+        final var proj = new Project(result.getInt("projectid"));
         proj.setName(result.getString("name"));
         proj.setDescription(result.getString("description"));
         proj.setRepoUrl(result.getString("repourl"));
@@ -101,6 +101,7 @@
 
     @Override
     public boolean update(Project instance) throws SQLException {
+        if (instance.getId() < 0) return false;
         Objects.requireNonNull(instance.getName());
         update.setString(1, instance.getName());
         setStringOrNull(update, 2, instance.getDescription());

mercurial