summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-23 13:49:48 +0200
committerSimon Rettberg2015-07-23 13:49:48 +0200
commit411eb5251e4d93e206f2b2847d856ded4240e84a (patch)
tree90f698a08cd5ced9256949a9176b4d0ebb93561c /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
parentMerge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff)
downloadtutor-module-411eb5251e4d93e206f2b2847d856ded4240e84a.tar.gz
tutor-module-411eb5251e4d93e206f2b2847d856ded4240e84a.tar.xz
tutor-module-411eb5251e4d93e206f2b2847d856ded4240e84a.zip
[server] Adapt to RPC changes
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java38
1 files changed, 23 insertions, 15 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
index adf0f26c..9b6b7966 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
@@ -160,10 +160,7 @@ public class DbImage {
stmt.setString("imagebaseid", imageBaseId);
ResultSet rs = stmt.executeQuery();
if (!rs.next()) {
- LOGGER.info("Image " + imageBaseId + " not found");
throw new TNotFoundException();
- } else {
- LOGGER.info("Image " + imageBaseId + " found");
}
return resultSetToSummary(rs);
}
@@ -211,7 +208,6 @@ public class DbImage {
stmt.setString("userid", user.userId);
stmt.executeUpdate();
connection.commit();
- LOGGER.info("Created image '" + imageUuid + "'");
return imageUuid;
} catch (SQLException e) {
LOGGER.error("Query failed in DbImage.createImage()", e);
@@ -317,19 +313,29 @@ public class DbImage {
* @param imageVersionId UUID of image version
* @param image meta data to set
* @throws SQLException
+ * @throws TNotFoundException
*/
public static void updateImageVersion(UserInfo user, String imageVersionId, ImageVersionWrite image)
- throws SQLException {
+ throws SQLException, TNotFoundException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("UPDATE imageversion v, imagebase b SET"
- + " v.isenabled = :isenabled, v.isrestricted = :isrestricted,"
+ String baseId = getBaseIdForVersionId(connection, imageVersionId);
+ if (baseId == null)
+ throw new TNotFoundException();
+ // First update version table
+ MysqlStatement stmtVersion = connection.prepareStatement("UPDATE imageversion v SET"
+ + " v.isenabled = :isenabled, v.isrestricted = :isrestricted"
+ + " WHERE v.imageversionid = :versionid");
+ stmtVersion.setString("versionid", imageVersionId);
+ stmtVersion.setBoolean("isenabled", image.isEnabled);
+ stmtVersion.setBoolean("isrestricted", image.isRestricted);
+ stmtVersion.executeUpdate();
+ // Then base table
+ MysqlStatement stmtBase = connection.prepareStatement("UPDATE imagebase b SET"
+ " b.updaterid = :userid, b.updatetime = UNIX_TIMESTAMP()"
- + " WHERE v.imageversionid = :versionid AND v.imagebaseid = b.imagebaseid");
- stmt.setString("versionid", imageVersionId);
- stmt.setString("userid", user.userId);
- stmt.setBoolean("isenabled", image.isEnabled);
- stmt.setBoolean("isrestricted", image.isRestricted);
- stmt.executeUpdate();
+ + " WHERE b.imagebaseid = :baseid");
+ stmtBase.setString("userid", user.userId);
+ stmtBase.setString("baseid", baseId);
+ stmtBase.executeUpdate();
connection.commit();
} catch (SQLException e) {
LOGGER.error("Query failed in DbImage.updateImageVersion()", e);
@@ -374,7 +380,9 @@ public class DbImage {
}
}
- public static void createImageVersion(String imageBaseId, String imageVersionId, UserInfo owner, long fileSize, String filePath, ImageVersionWrite versionSettings, ChunkList chunks) throws SQLException {
+ public static void createImageVersion(String imageBaseId, String imageVersionId, UserInfo owner,
+ long fileSize, String filePath, ImageVersionWrite versionSettings, ChunkList chunks,
+ byte[] machineDescription) throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
final long nowSecs = System.currentTimeMillis() / 1000;
MysqlStatement stmt = connection.prepareStatement("INSERT INTO imageversion"
@@ -395,7 +403,7 @@ public class DbImage {
stmt.setBoolean("isvalid", true); // TODO
stmt.setBoolean("isprocessed", false);
stmt.setBinary("mastersha1", null); // TODO
- stmt.setString("virtualizerconfig", null); // TODO
+ stmt.setBinary("virtualizerconfig", machineDescription);
stmt.executeUpdate();
// TODO: Write chunk hashes to DB
connection.commit();