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

changeset 75
33b6843fdf8a
parent 62
833e0385572a
child 80
27a25f32048e
     1.1 --- a/src/main/java/de/uapcore/lightpit/dao/postgres/PGVersionDao.java	Fri May 22 17:26:27 2020 +0200
     1.2 +++ b/src/main/java/de/uapcore/lightpit/dao/postgres/PGVersionDao.java	Fri May 22 21:23:57 2020 +0200
     1.3 @@ -47,26 +47,27 @@
     1.4  
     1.5      public PGVersionDao(Connection connection) throws SQLException {
     1.6          list = connection.prepareStatement(
     1.7 -                "select id, project, name, ordinal, status " +
     1.8 +                "select versionid, project, name, ordinal, status " +
     1.9                          "from lpit_version " +
    1.10                          "where project = ? " +
    1.11                          "order by ordinal, lower(name)");
    1.12  
    1.13          find = connection.prepareStatement(
    1.14 -                "select id, project, name, ordinal, status " +
    1.15 +                "select versionid, project, name, ordinal, status " +
    1.16                          "from lpit_version " +
    1.17 -                        "where id = ?");
    1.18 +                        "where versionid = ?");
    1.19  
    1.20          insert = connection.prepareStatement(
    1.21                  "insert into lpit_version (project, name, ordinal, status) values (?, ?, ?, ?::version_status)"
    1.22          );
    1.23          update = connection.prepareStatement(
    1.24 -                "update lpit_version set name = ?, ordinal = ?, status = ?::version_status where id = ?"
    1.25 +                "update lpit_version set name = ?, ordinal = ?, status = ?::version_status where versionid = ?"
    1.26          );
    1.27      }
    1.28  
    1.29 -    public Version mapColumns(ResultSet result) throws SQLException {
    1.30 -        final var version = new Version(result.getInt("id"), new Project(result.getInt("project")));
    1.31 +    private Version mapColumns(ResultSet result) throws SQLException {
    1.32 +        final var project = new Project(result.getInt("project"));
    1.33 +        final var version = new Version(result.getInt("versionid"), project);
    1.34          version.setName(result.getString("name"));
    1.35          version.setOrdinal(result.getInt("ordinal"));
    1.36          version.setStatus(VersionStatus.valueOf(result.getString("status")));
    1.37 @@ -86,6 +87,7 @@
    1.38  
    1.39      @Override
    1.40      public boolean update(Version instance) throws SQLException {
    1.41 +        if (instance.getId() < 0) return false;
    1.42          Objects.requireNonNull(instance.getName());
    1.43          update.setString(1, instance.getName());
    1.44          update.setInt(2, instance.getOrdinal());
    1.45 @@ -100,7 +102,9 @@
    1.46          List<Version> versions = new ArrayList<>();
    1.47          try (var result = list.executeQuery()) {
    1.48              while (result.next()) {
    1.49 -                versions.add(mapColumns(result));
    1.50 +                final var v = mapColumns(result);
    1.51 +                v.setProject(project);
    1.52 +                versions.add(v);
    1.53              }
    1.54          }
    1.55          return versions;

mercurial