From 10f0687fe551bda88120c2dc2b003035dd9bbea8 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 28 Aug 2015 18:04:16 +0200 Subject: [server] Working on image download from master server --- .../openslx/bwlp/sat/database/mappers/DbImage.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java') 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 2e2393f8..c03d8322 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 @@ -21,6 +21,7 @@ import org.openslx.bwlp.sat.util.Util; import org.openslx.bwlp.thrift.iface.ImageBaseWrite; import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.bwlp.thrift.iface.ImagePermissions; +import org.openslx.bwlp.thrift.iface.ImagePublishData; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.ImageVersionDetails; import org.openslx.bwlp.thrift.iface.ImageVersionWrite; @@ -283,6 +284,49 @@ public class DbImage { } } + /** + * Create or update a base image with the given publish data. + * Used for replication from master server. + * + * @param user The user who triggered the download, and will be considered + * the creator; if null, the creator of the image will be used + * @param image The image to create + * @throws SQLException + */ + public static void writeBaseImage(UserInfo user, ImagePublishData image) throws SQLException { + if (user == null) { + user = image.user; + } + try (MysqlConnection connection = Database.getConnection()) { + MysqlStatement stmt = connection.prepareStatement("INSERT INTO imagebase" + + " (imagebaseid, displayname, description, osid, virtid, createtime," + + " updatetime, ownerid, updaterid, sharemode, istemplate," + + " canlinkdefault, candownloaddefault, caneditdefault, canadmindefault)" + + " VALUES " + + " (:imagebaseid, :displayname, :description, :osid, :virtid, :unixtime," + + " :unixtime, :userid, :userid, :sharemode, :istemplate," + + " 1, 1, 0, 0) " + + " ON DUPLICATE KEY UPDATE " + + " displayname = VALUES(displayname), description = VALUES(description)," + + " osid = VALUES(osid), virtid = VALUES(virtid), updatetime = VALUES(updatetime)," + + " updaterid = VALUES(updaterid), istemplate = VALUES(istemplate)"); + stmt.setString("imagebaseid", image.imageBaseId); + stmt.setString("displayname", image.imageName); + stmt.setString("description", image.description); + stmt.setInt("osid", image.osId); + stmt.setString("virtid", image.virtId); + stmt.setLong("unixtime", Util.unixTime()); + stmt.setString("userid", user.userId); + stmt.setString("sharemode", "DOWNLOAD"); + stmt.setBoolean("istemplate", image.isTemplate); + stmt.executeUpdate(); + connection.commit(); + } catch (SQLException e) { + LOGGER.error("Query failed in DbImage.writeBaseImage()", e); + throw e; + } + } + public static void updateImageMetadata(UserInfo user, String imageBaseId, ImageBaseWrite image) throws SQLException { if (image.imageName.length() > 100) { -- cgit v1.2.3-55-g7522