diff options
author | Simon Rettberg | 2015-08-28 18:04:16 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-08-28 18:04:16 +0200 |
commit | 10f0687fe551bda88120c2dc2b003035dd9bbea8 (patch) | |
tree | a9a3103c5ca1981bad169a6a1527f0252c4bc76f /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database | |
parent | [client] save the selected download folder and not the generated folder (diff) | |
download | tutor-module-10f0687fe551bda88120c2dc2b003035dd9bbea8.tar.gz tutor-module-10f0687fe551bda88120c2dc2b003035dd9bbea8.tar.xz tutor-module-10f0687fe551bda88120c2dc2b003035dd9bbea8.zip |
[server] Working on image download from master server
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database')
-rw-r--r-- | dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java | 44 |
1 files changed, 44 insertions, 0 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 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) { |