summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Schwär2021-04-19 21:44:02 +0200
committerStephan Schwär2021-04-19 21:44:02 +0200
commit47ace6f32ff007548779b2630daf49f0785e5467 (patch)
tree23f9003eef30e733a6987c318df182716097e9fe
parent[server] Remove redundant null values in sql query (diff)
downloadtutor-module-47ace6f32ff007548779b2630daf49f0785e5467.tar.gz
tutor-module-47ace6f32ff007548779b2630daf49f0785e5467.tar.xz
tutor-module-47ace6f32ff007548779b2630daf49f0785e5467.zip
[server] Run formatter for DbImage.java
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java240
1 files changed, 122 insertions, 118 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 8482087a..d1798331 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
@@ -70,8 +70,7 @@ public class DbImage {
+ " LEFT JOIN imageversion lat ON (lat.imageversionid = i.latestversionid)"
+ " LEFT JOIN imageversion allv ON (allv.imagebaseid = i.imagebaseid)"
+ " LEFT JOIN imagepermission perm ON (i.imagebaseid = perm.imagebaseid AND perm.userid = :userid)"
- + " GROUP BY imagebaseid"
- + Paginator.limitStatement(page));
+ + " GROUP BY imagebaseid" + Paginator.limitStatement(page));
stmt.setString("userid", user.userId);
ResultSet rs = stmt.executeQuery();
List<ImageSummaryRead> list = new ArrayList<>(100);
@@ -90,21 +89,19 @@ public class DbImage {
try (MysqlConnection connection = Database.getConnection()) {
MysqlStatement stmt = null;
// Students should only be able to request a download of an image. Therefore not all information is needed for this task.
- if (user.role == Role.STUDENT)
- {
+ if (user.role == Role.STUDENT) {
stmt = connection.prepareStatement("SELECT i.imagebaseid, i.latestversionid"
- + " FROM imagebase i"
- + " LEFT JOIN imagepermission perm ON (i.imagebaseid = perm.imagebaseid AND perm.userid = :userid)"
- + " WHERE i.imagebaseid = :imagebaseid");
+ + " FROM imagebase i"
+ + " LEFT JOIN imagepermission perm ON (i.imagebaseid = perm.imagebaseid AND perm.userid = :userid)"
+ + " WHERE i.imagebaseid = :imagebaseid");
} else {
stmt = connection.prepareStatement("SELECT i.imagebaseid, i.latestversionid,"
- + " i.displayname, i.description, i.osid, i.virtid, i.createtime, i.updatetime, i.ownerid, i.updaterid,"
- + " i.sharemode, i.istemplate,"
- + " i.canlinkdefault, i.candownloaddefault, i.caneditdefault, i.canadmindefault,"
- + " perm.canlink, perm.candownload, perm.canedit, perm.canadmin"
- + " FROM imagebase i"
- + " LEFT JOIN imagepermission perm ON (i.imagebaseid = perm.imagebaseid AND perm.userid = :userid)"
- + " WHERE i.imagebaseid = :imagebaseid");
+ + " i.displayname, i.description, i.osid, i.virtid, i.createtime, i.updatetime, i.ownerid, i.updaterid,"
+ + " i.sharemode, i.istemplate,"
+ + " i.canlinkdefault, i.candownloaddefault, i.caneditdefault, i.canadmindefault,"
+ + " perm.canlink, perm.candownload, perm.canedit, perm.canadmin" + " FROM imagebase i"
+ + " LEFT JOIN imagepermission perm ON (i.imagebaseid = perm.imagebaseid AND perm.userid = :userid)"
+ + " WHERE i.imagebaseid = :imagebaseid");
}
stmt.setString("userid", user == null ? "-" : user.userId);
stmt.setString("imagebaseid", imageBaseId);
@@ -120,17 +117,18 @@ public class DbImage {
// Students should only have download permissions.
// todo evaluate if this is needed and if there is a nicer way to create ImageDetailsRead object
ImagePermissions defaultPermissions = new ImagePermissions(false, true, false, false);
- image = new ImageDetailsRead(rs.getString("imagebaseid"),
- rs.getString("latestversionid"), versions, imageBaseId, imageBaseId, tags, 0, imageBaseId, 0, 0, imageBaseId, imageBaseId, null, false, defaultPermissions);
+ image = new ImageDetailsRead(rs.getString("imagebaseid"), rs.getString("latestversionid"),
+ versions, imageBaseId, imageBaseId, tags, 0, imageBaseId, 0, 0, imageBaseId,
+ imageBaseId, null, false, defaultPermissions);
image.setUserPermissions(defaultPermissions);
} else {
ImagePermissions defaultPermissions = DbImagePermissions.fromResultSetDefault(rs);
- image = new ImageDetailsRead(rs.getString("imagebaseid"),
- rs.getString("latestversionid"), versions, rs.getString("displayname"),
- rs.getString("description"), tags, rs.getInt("osid"), rs.getString("virtid"),
- rs.getLong("createtime"), rs.getLong("updatetime"), rs.getString("ownerid"),
- rs.getString("updaterid"), toShareMode(rs.getString("sharemode")),
- rs.getByte("istemplate") != 0, defaultPermissions);
+ image = new ImageDetailsRead(rs.getString("imagebaseid"), rs.getString("latestversionid"),
+ versions, rs.getString("displayname"), rs.getString("description"), tags,
+ rs.getInt("osid"), rs.getString("virtid"), rs.getLong("createtime"),
+ rs.getLong("updatetime"), rs.getString("ownerid"), rs.getString("updaterid"),
+ toShareMode(rs.getString("sharemode")), rs.getByte("istemplate") != 0,
+ defaultPermissions);
image.setUserPermissions(DbImagePermissions.fromResultSetUser(rs));
}
User.setCombinedUserPermissions(image, user);
@@ -152,11 +150,11 @@ public class DbImage {
rs.getString("deletestate"));
}
- public static LocalImageVersion getLocalImageData(String imageVersionId) throws TNotFoundException,
- SQLException {
+ public static LocalImageVersion getLocalImageData(String imageVersionId)
+ throws TNotFoundException, SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement(localImageBaseSql
- + " WHERE imageversionid = :imageversionid");
+ MysqlStatement stmt = connection
+ .prepareStatement(localImageBaseSql + " WHERE imageversionid = :imageversionid");
stmt.setString("imageversionid", imageVersionId);
ResultSet rs = stmt.executeQuery();
if (!rs.next())
@@ -170,8 +168,8 @@ public class DbImage {
protected static List<LocalImageVersion> getLocalImageVersions(MysqlConnection connection,
String imageBaseId) throws SQLException {
- MysqlStatement stmt = connection.prepareStatement(localImageBaseSql
- + " WHERE imagebaseid = :imagebaseid");
+ MysqlStatement stmt = connection
+ .prepareStatement(localImageBaseSql + " WHERE imagebaseid = :imagebaseid");
stmt.setString("imagebaseid", imageBaseId);
ResultSet rs = stmt.executeQuery();
List<LocalImageVersion> list = new ArrayList<>();
@@ -184,8 +182,8 @@ public class DbImage {
public static List<LocalImageVersion> getExpiringLocalImageVersions(int maxRemainingDays)
throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement(localImageBaseSql
- + " WHERE expiretime < :deadline");
+ MysqlStatement stmt = connection
+ .prepareStatement(localImageBaseSql + " WHERE expiretime < :deadline");
stmt.setLong("deadline", Util.unixTime() + (maxRemainingDays * 86400));
ResultSet rs = stmt.executeQuery();
List<LocalImageVersion> list = new ArrayList<>();
@@ -236,8 +234,8 @@ public class DbImage {
* @throws SQLException
* @throws TNotFoundException
*/
- public static ImageSummaryRead getImageSummary(UserInfo user, String imageBaseId) throws SQLException,
- TNotFoundException {
+ public static ImageSummaryRead getImageSummary(UserInfo user, String imageBaseId)
+ throws SQLException, TNotFoundException {
try (MysqlConnection connection = Database.getConnection()) {
return getImageSummary(connection, user, imageBaseId);
} catch (SQLException e) {
@@ -255,8 +253,7 @@ public class DbImage {
+ " i.caneditdefault, i.canadmindefault,"
+ " lat.expiretime, lat.filesize, lat.isrestricted, lat.isvalid,"
+ " lat.uploaderid, lat.isprocessed, lat.createtime AS uploadtime,"
- + " perm.canlink, perm.candownload, perm.canedit, perm.canadmin"
- + " FROM imagebase i"
+ + " perm.canlink, perm.candownload, perm.canedit, perm.canadmin" + " FROM imagebase i"
+ " LEFT JOIN imageversion lat ON (lat.imageversionid = i.latestversionid)"
+ " LEFT JOIN imagepermission perm ON (i.imagebaseid = perm.imagebaseid AND perm.userid = :userid)"
+ " WHERE i.imagebaseid = :imagebaseid");
@@ -269,24 +266,24 @@ public class DbImage {
return resultSetToSummary(user, rs);
}
- protected static List<ImageVersionDetails> getImageVersions(MysqlConnection connection, String imageBaseId, UserInfo user)
- throws SQLException {
+ protected static List<ImageVersionDetails> getImageVersions(MysqlConnection connection,
+ String imageBaseId, UserInfo user) throws SQLException {
List<ImageVersionDetails> versionList = new ArrayList<>();
- MysqlStatement stmt = null;
+ MysqlStatement stmt = null;
if (user.role == Role.STUDENT) {
- stmt = connection.prepareStatement("SELECT"
- + " imageversionid, createtime, expiretime, filesize, null,"
- + " isrestricted, isvalid, isprocessed" + " FROM imageversion"
- + " WHERE imagebaseid = :imagebaseid");
+ stmt = connection
+ .prepareStatement("SELECT" + " imageversionid, createtime, expiretime, filesize, null,"
+ + " isrestricted, isvalid, isprocessed" + " FROM imageversion"
+ + " WHERE imagebaseid = :imagebaseid");
} else {
- stmt = connection.prepareStatement("SELECT"
- + " imageversionid, createtime, expiretime, filesize, uploaderid,"
- + " isrestricted, isvalid, isprocessed" + " FROM imageversion"
- + " WHERE imagebaseid = :imagebaseid");
+ stmt = connection.prepareStatement(
+ "SELECT" + " imageversionid, createtime, expiretime, filesize, uploaderid,"
+ + " isrestricted, isvalid, isprocessed" + " FROM imageversion"
+ + " WHERE imagebaseid = :imagebaseid");
}
stmt.setString("imagebaseid", imageBaseId);
ResultSet rs = stmt.executeQuery();
-
+
while (rs.next()) {
String imageVersionId = rs.getString("imageversionid");
String uploaderID = "";
@@ -297,8 +294,8 @@ public class DbImage {
versionList.add(new ImageVersionDetails(imageVersionId, rs.getLong("createtime"),
rs.getLong("expiretime"), rs.getLong("filesize"), uploaderID,
rs.getByte("isrestricted") != 0, rs.getByte("isvalid") != 0,
- rs.getByte("isprocessed") != 0, DbSoftwareTag.getImageVersionSoftwareList(connection,
- imageVersionId)));
+ rs.getByte("isprocessed") != 0,
+ DbSoftwareTag.getImageVersionSoftwareList(connection, imageVersionId)));
}
stmt.close();
return versionList;
@@ -381,14 +378,14 @@ public class DbImage {
image.imageName = image.imageName.substring(0, 100);
}
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("UPDATE imagebase"
- + " SET displayname = :imagename, description = :description,"
- + " osid = :osid, virtid = :virtid,"
- + (user == null || User.isSuperUser(user) ? " istemplate = :istemplate," : "")
- + " canlinkdefault = :canlink,"
- + " candownloaddefault = :candownload, caneditdefault = :canedit,"
- + (user != null ? " updaterid = :updaterid, updatetime = UNIX_TIMESTAMP()," : "")
- + " canadmindefault = :canadmin" + " WHERE imagebaseid = :baseid");
+ MysqlStatement stmt = connection.prepareStatement(
+ "UPDATE imagebase" + " SET displayname = :imagename, description = :description,"
+ + " osid = :osid, virtid = :virtid,"
+ + (user == null || User.isSuperUser(user) ? " istemplate = :istemplate," : "")
+ + " canlinkdefault = :canlink,"
+ + " candownloaddefault = :candownload, caneditdefault = :canedit,"
+ + (user != null ? " updaterid = :updaterid, updatetime = UNIX_TIMESTAMP()," : "")
+ + " canadmindefault = :canadmin" + " WHERE imagebaseid = :baseid");
stmt.setString("baseid", imageBaseId);
stmt.setString("imagename", image.imageName);
stmt.setString("description", image.description);
@@ -419,8 +416,8 @@ public class DbImage {
try (MysqlConnection connection = Database.getConnection()) {
MysqlStatement stmt;
if (changingUser == null) {
- stmt = connection.prepareStatement("UPDATE imagebase"
- + " SET ownerid = :ownerid WHERE imagebaseid = :baseid");
+ stmt = connection.prepareStatement(
+ "UPDATE imagebase" + " SET ownerid = :ownerid WHERE imagebaseid = :baseid");
stmt.setString("ownerid", newOwnerId);
stmt.setString("baseid", imageBaseId);
} else {
@@ -448,7 +445,8 @@ public class DbImage {
* @throws SQLException
* @throws TNotFoundException
*/
- public static String getBaseIdForVersionId(String imageVersionId) throws SQLException, TNotFoundException {
+ public static String getBaseIdForVersionId(String imageVersionId)
+ throws SQLException, TNotFoundException {
try (MysqlConnection connection = Database.getConnection()) {
return getBaseIdForVersionId(connection, imageVersionId);
} catch (SQLException e) {
@@ -467,8 +465,8 @@ public class DbImage {
*/
protected static String getBaseIdForVersionId(MysqlConnection connection, String imageVersionId)
throws SQLException, TNotFoundException {
- MysqlStatement stmt = connection.prepareStatement("SELECT imagebaseid FROM imageversion"
- + " WHERE imageversionid = :imageversionid LIMIT 1");
+ MysqlStatement stmt = connection.prepareStatement(
+ "SELECT imagebaseid FROM imageversion" + " WHERE imageversionid = :imageversionid LIMIT 1");
stmt.setString("imageversionid", imageVersionId);
ResultSet rs = stmt.executeQuery();
if (!rs.next())
@@ -502,9 +500,9 @@ public class DbImage {
stmtVersion.setBoolean("isrestricted", image.isRestricted);
if (stmtVersion.executeUpdate() != 0) {
// Then base table
- MysqlStatement stmtBase = connection.prepareStatement("UPDATE imagebase b SET"
- + " b.updaterid = :userid, b.updatetime = UNIX_TIMESTAMP()"
- + " WHERE b.imagebaseid = :baseid");
+ MysqlStatement stmtBase = connection.prepareStatement(
+ "UPDATE imagebase b SET" + " b.updaterid = :userid, b.updatetime = UNIX_TIMESTAMP()"
+ + " WHERE b.imagebaseid = :baseid");
stmtBase.setString("userid", user.userId);
stmtBase.setString("baseid", baseId);
stmtBase.executeUpdate();
@@ -533,9 +531,9 @@ public class DbImage {
try (MysqlConnection connection = Database.getConnection()) {
{
// Disable version in question
- MysqlStatement checkStmt = connection.prepareStatement("SELECT imageversionid FROM"
- + " imageversion WHERE imageversionid = :versionid AND"
- + " (expiretime > UNIX_TIMESTAMP() OR isvalid <> 0)");
+ MysqlStatement checkStmt = connection.prepareStatement(
+ "SELECT imageversionid FROM" + " imageversion WHERE imageversionid = :versionid AND"
+ + " (expiretime > UNIX_TIMESTAMP() OR isvalid <> 0)");
MysqlStatement disableStmt = connection.prepareStatement("UPDATE imageversion SET"
+ " expiretime = 1234567890, isvalid = 0" + " WHERE imageversionid = :versionid");
affectedList = new ArrayList<>(imageVersionIds.length);
@@ -570,8 +568,8 @@ public class DbImage {
public static void setShareMode(String imageBaseId, ImageBaseWrite newData) throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("UPDATE imagebase"
- + " SET sharemode = :sharemode WHERE imagebaseid = :baseid LIMIT 1");
+ MysqlStatement stmt = connection.prepareStatement(
+ "UPDATE imagebase" + " SET sharemode = :sharemode WHERE imagebaseid = :baseid LIMIT 1");
stmt.setString("baseid", imageBaseId);
stmt.setString("sharemode", newData.shareMode.name());
stmt.executeUpdate();
@@ -601,7 +599,8 @@ public class DbImage {
verStmt.setLong("filesize", fileSize);
verStmt.setString("filepath", filePath);
verStmt.setString("uploaderid", owner.userId);
- verStmt.setBoolean("isrestricted", versionSettings == null ? false : versionSettings.isRestricted);
+ verStmt.setBoolean("isrestricted",
+ versionSettings == null ? false : versionSettings.isRestricted);
verStmt.setBoolean("isvalid", true);
verStmt.setBoolean("isprocessed", false);
verStmt.setBinary("mastersha1", null); // TODO
@@ -612,9 +611,9 @@ public class DbImage {
owner.userId, nowSecs, expireTime, true, DeleteState.KEEP.name());
DbLecture.autoUpdateUsedImage(connection, imageBaseId, liv);
// Update edit timestamp and edit user
- MysqlStatement baseStmt = connection.prepareStatement("UPDATE imagebase SET"
- + " updatetime = :updatetime, updaterid = :updaterid"
- + " WHERE imagebaseid = :imagebaseid LIMIT 1");
+ MysqlStatement baseStmt = connection.prepareStatement(
+ "UPDATE imagebase SET" + " updatetime = :updatetime, updaterid = :updaterid"
+ + " WHERE imagebaseid = :imagebaseid LIMIT 1");
baseStmt.setString("imagebaseid", imageBaseId);
baseStmt.setString("updaterid", owner.userId);
baseStmt.setLong("updatetime", nowSecs);
@@ -662,8 +661,8 @@ public class DbImage {
LocalImageVersion... imageVersion) throws SQLException {
if (imageVersion == null || imageVersion.length == 0)
return new LocalImageVersion[0];
- MysqlStatement stmt = connection.prepareStatement("UPDATE imageversion SET isvalid = :valid"
- + " WHERE imageversionid = :imageversionid");
+ MysqlStatement stmt = connection.prepareStatement(
+ "UPDATE imageversion SET isvalid = :valid" + " WHERE imageversionid = :imageversionid");
stmt.setBoolean("valid", valid);
List<LocalImageVersion> retList = new ArrayList<>(imageVersion.length);
for (LocalImageVersion version : imageVersion) {
@@ -701,12 +700,13 @@ public class DbImage {
DbLecture.unlinkFromImageVersion(connection, image.imageVersionId);
//DbLecture.deletePermanently(connection, image);
// Unlink latest version field from image base
- MysqlStatement unlinkStmt = connection.prepareStatement("UPDATE imagebase SET latestversionid = NULL"
- + " WHERE latestversionid = :imageversionid");
+ MysqlStatement unlinkStmt = connection
+ .prepareStatement("UPDATE imagebase SET latestversionid = NULL"
+ + " WHERE latestversionid = :imageversionid");
unlinkStmt.setString("imageversionid", image.imageVersionId);
unlinkStmt.executeUpdate();
- MysqlStatement stmt = connection.prepareStatement("DELETE FROM imageversion"
- + " WHERE imageversionid = :imageversionid");
+ MysqlStatement stmt = connection
+ .prepareStatement("DELETE FROM imageversion" + " WHERE imageversionid = :imageversionid");
stmt.setString("imageversionid", image.imageVersionId);
stmt.executeUpdate();
connection.commit();
@@ -800,7 +800,8 @@ public class DbImage {
}
}
if (changingVersion == null) {
- LOGGER.warn("BUG: oldVersion ninjad away on updateLatestVersion (" + changingImageVersionId + ")");
+ LOGGER.warn(
+ "BUG: oldVersion ninjad away on updateLatestVersion (" + changingImageVersionId + ")");
} else {
// Switch any lectures linking to this version if applicable
if (changingVersion.isValid) {
@@ -837,7 +838,8 @@ public class DbImage {
// Determine manually if anything changed, as executeQuery() always returns 1 for some reason
boolean latestVersionChanged = true;
do {
- MysqlStatement ds = connection.prepareStatement("SELECT latestversionid FROM imagebase WHERE imagebaseid = :imagebaseid");
+ MysqlStatement ds = connection.prepareStatement(
+ "SELECT latestversionid FROM imagebase WHERE imagebaseid = :imagebaseid");
ds.setString("imagebaseid", imageBaseId);
ResultSet drs = ds.executeQuery();
if (drs.next()) {
@@ -851,8 +853,8 @@ public class DbImage {
}
} while (false);
// Update latestversionid reference in imagebase table
- MysqlStatement latestStmt = connection.prepareStatement("UPDATE imagebase SET latestversionid = :newversionid"
- + " WHERE imagebaseid = :imagebaseid");
+ MysqlStatement latestStmt = connection.prepareStatement(
+ "UPDATE imagebase SET latestversionid = :newversionid" + " WHERE imagebaseid = :imagebaseid");
latestStmt.setString("newversionid", newLatest == null ? null : newLatest.imageVersionId);
latestStmt.setString("imagebaseid", imageBaseId);
// If nothing changed (because the deleted version was not the latest), bail out
@@ -890,9 +892,9 @@ public class DbImage {
*/
public static List<LocalImageVersion> getVersionsWithMissingData() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement(localImageBaseSql
- + " INNER JOIN imagebase b USING (imagebaseid)"
- + " WHERE b.virtid IS NULL OR b.osid IS NULL");
+ MysqlStatement stmt = connection
+ .prepareStatement(localImageBaseSql + " INNER JOIN imagebase b USING (imagebaseid)"
+ + " WHERE b.virtid IS NULL OR b.osid IS NULL");
ResultSet rs = stmt.executeQuery();
List<LocalImageVersion> list = new ArrayList<>();
while (rs.next()) {
@@ -912,16 +914,15 @@ public class DbImage {
try (MysqlConnection connection = Database.getConnection()) {
// Get all image base entries which have no image version
MysqlStatement sel = connection.prepareStatement("SELECT i.imagebaseid FROM imagebase i"
- + " LEFT JOIN imageversion v USING (imagebaseid)"
- + " WHERE ("
+ + " LEFT JOIN imageversion v USING (imagebaseid)" + " WHERE ("
+ " i.updatetime < :cutoff1 OR (i.updatetime < :cutoff2 AND (i.updatetime - i.createtime) < 600))"
+ " AND v.imageversionid IS NULL");
sel.setLong("cutoff1", Util.unixTime() - 86400 * 14);
sel.setLong("cutoff2", Util.unixTime() - 3600 * 2);
ResultSet rs = sel.executeQuery();
// Now delete them all
- MysqlStatement stmt = connection.prepareStatement("DELETE FROM imagebase"
- + " WHERE imagebaseid = :imagebaseid");
+ MysqlStatement stmt = connection
+ .prepareStatement("DELETE FROM imagebase" + " WHERE imagebaseid = :imagebaseid");
int ret = 0;
while (rs.next()) {
String baseId = null;
@@ -941,30 +942,29 @@ public class DbImage {
}
}
- public static ImageVersionMeta getVersionDetails(String imageVersionId) throws SQLException,
- TNotFoundException {
+ public static ImageVersionMeta getVersionDetails(String imageVersionId)
+ throws SQLException, TNotFoundException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("SELECT"
- + " imageversionid, imagebaseid, virtualizerconfig FROM imageversion"
- + " WHERE imageversionid = :imageversionid");
+ MysqlStatement stmt = connection.prepareStatement(
+ "SELECT" + " imageversionid, imagebaseid, virtualizerconfig FROM imageversion"
+ + " WHERE imageversionid = :imageversionid");
stmt.setString("imageversionid", imageVersionId);
ResultSet rs = stmt.executeQuery();
if (!rs.next())
throw new TNotFoundException();
return new ImageVersionMeta(imageVersionId, rs.getString("imagebaseid"),
- rs.getBytes("virtualizerconfig"), DbImageBlock.getBlockHashes(connection, imageVersionId));
+ rs.getBytes("virtualizerconfig"),
+ DbImageBlock.getBlockHashes(connection, imageVersionId));
} catch (SQLException e) {
LOGGER.error("Query failed in DbImage.getVersionDetails()", e);
throw e;
}
}
- public static byte[] getVirtualizerConfig(String imageVersionId) throws SQLException,
- TNotFoundException {
+ public static byte[] getVirtualizerConfig(String imageVersionId) throws SQLException, TNotFoundException {
try (MysqlConnection connection = Database.getConnection()) {
MysqlStatement stmt = connection.prepareStatement("SELECT"
- + " virtualizerconfig FROM imageversion"
- + " WHERE imageversionid = :imageversionid");
+ + " virtualizerconfig FROM imageversion" + " WHERE imageversionid = :imageversionid");
stmt.setString("imageversionid", imageVersionId);
ResultSet rs = stmt.executeQuery();
if (!rs.next())
@@ -975,14 +975,15 @@ public class DbImage {
throw e;
}
}
-
- public static void setVirtualizerConfig(String imageVersionId, byte[] machineDescription) throws SQLException,
- TNotFoundException {
+
+ public static void setVirtualizerConfig(String imageVersionId, byte[] machineDescription)
+ throws SQLException, TNotFoundException {
if (imageVersionId == null || machineDescription == null || machineDescription.length == 0)
return;
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("UPDATE imageversion SET virtualizerconfig = :virtualizerconfig"
- + " WHERE imageversionid = :imageversionid");
+ MysqlStatement stmt = connection
+ .prepareStatement("UPDATE imageversion SET virtualizerconfig = :virtualizerconfig"
+ + " WHERE imageversionid = :imageversionid");
stmt.setString("imageversionid", imageVersionId);
stmt.setBinary("virtualizerconfig", machineDescription);
stmt.executeUpdate();
@@ -1009,8 +1010,9 @@ public class DbImage {
ignoredOldState = "invalid";
}
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("UPDATE imageversion SET deletestate = :newstate"
- + " WHERE imageversionid = :imageversionid AND deletestate <> :oldstate");
+ MysqlStatement stmt = connection
+ .prepareStatement("UPDATE imageversion SET deletestate = :newstate"
+ + " WHERE imageversionid = :imageversionid AND deletestate <> :oldstate");
stmt.setString("newstate", shouldDelete.name());
stmt.setString("oldstate", ignoredOldState);
for (String imageVersionId : imageVersionIds) {
@@ -1028,8 +1030,8 @@ public class DbImage {
public static List<LocalImageVersion> getLocalWithState(DeleteState state) throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement(localImageBaseSql
- + " WHERE deletestate = :deletestate");
+ MysqlStatement stmt = connection
+ .prepareStatement(localImageBaseSql + " WHERE deletestate = :deletestate");
stmt.setString("deletestate", state.name());
ResultSet rs = stmt.executeQuery();
List<LocalImageVersion> list = new ArrayList<>();
@@ -1045,8 +1047,8 @@ public class DbImage {
public static void deleteBasePermanently(String imageBaseId) throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("DELETE FROM imagebase"
- + " WHERE imagebaseid = :imagebaseid");
+ MysqlStatement stmt = connection
+ .prepareStatement("DELETE FROM imagebase" + " WHERE imagebaseid = :imagebaseid");
stmt.setString("imagebaseid", imageBaseId);
stmt.executeUpdate();
connection.commit();
@@ -1067,8 +1069,8 @@ public class DbImage {
public static Set<String> resetDeleteState() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
// Get
- MysqlStatement sstmt = connection.prepareStatement("SELECT imageversionid FROM imageversion"
- + " WHERE deletestate = :should");
+ MysqlStatement sstmt = connection.prepareStatement(
+ "SELECT imageversionid FROM imageversion" + " WHERE deletestate = :should");
sstmt.setString("should", DeleteState.SHOULD_DELETE.name());
ResultSet rs = sstmt.executeQuery();
Set<String> list = new HashSet<>();
@@ -1076,8 +1078,8 @@ public class DbImage {
list.add(rs.getString("imageversionid"));
}
// Update
- MysqlStatement ustmt = connection.prepareStatement("UPDATE imageversion SET deletestate = :keep"
- + " WHERE deletestate = :should");
+ MysqlStatement ustmt = connection.prepareStatement(
+ "UPDATE imageversion SET deletestate = :keep" + " WHERE deletestate = :should");
ustmt.setString("keep", DeleteState.KEEP.name());
ustmt.setString("should", DeleteState.SHOULD_DELETE.name());
ustmt.executeUpdate();
@@ -1091,8 +1093,9 @@ public class DbImage {
public static void setExpireDate(String imageVersionId, long expireTime) throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("UPDATE imageversion SET expiretime = :expiretime"
- + " WHERE imageversionid = :imageversionid");
+ MysqlStatement stmt = connection
+ .prepareStatement("UPDATE imageversion SET expiretime = :expiretime"
+ + " WHERE imageversionid = :imageversionid");
stmt.setString("imageversionid", imageVersionId);
stmt.setLong("expiretime", expireTime);
stmt.executeUpdate();
@@ -1104,7 +1107,8 @@ public class DbImage {
}
/**
- * Get all known file names of images, regardless of whether they are working/valid.
+ * Get all known file names of images, regardless of whether they are
+ * working/valid.
*/
public static Set<String> getAllFilenames() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {