From 3bd2714d8fc3eee958f3f831556175c26f0bf76b Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Wed, 20 Aug 2014 16:01:44 +0200 Subject: Add methods to update image in database --- .../org/openslx/satellitedaemon/db/DbImage.java | 38 +++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java index 5169173..be968b9 100644 --- a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java +++ b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java @@ -3,23 +3,30 @@ package org.openslx.satellitedaemon.db; import java.util.List; /** - * Represents an image in the satellite's database (mostly from + * Represents an image in the satellites database (mostly from * m_VLData_imageInfo) */ public class DbImage { - + public final String guid; public final String name; public final int rid; public final String path; public final String creator; public final long fileSize; - + + public enum Status + { + only_local, to_be_published, being_published, successfully_published, to_be_decentralized, being_decentralized, successfully_decentralized + } + public DbImage(String guid, String name, Integer rid, String path, String creator, Long fileSize) { - if (rid == null) rid = -1; - if (fileSize == null) fileSize = (long) -1; + if ( rid == null ) + rid = -1; + if ( fileSize == null ) + fileSize = (long) -1; this.guid = guid; this.name = name; this.rid = rid; @@ -38,22 +45,31 @@ public class DbImage public static List getAllMarkedForUpload() { return MySQL.findAll( DbImage.class, "SELECT image.GUID_imageID, image.image_name, image.imageVersion, image.image_path," + - " Concat(user.loginName, '@', institution.name) AS userID, image.image_filesize" + + " Concat(user.loginName, @, institution.name) AS userID, image.image_filesize" + " FROM m_VLData_imageInfo image" + " INNER JOIN m_user user ON (image.image_owner = user.userID)" + " INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" + - " WHERE image_syncMode = 'to_be_published'" ); + " WHERE image_syncMode = to_be_published" ); } - - + public static List getAllMarkedForDownload() { return MySQL.findAll( DbImage.class, "SELECT image.GUID_imageID, image.image_name, image.imageVersion, image.image_path," + - " Concat(user.loginName, '@', institution.name) AS userID, image.image_filesize" + + " Concat(user.loginName, @, institution.name) AS userID, image.image_filesize" + " FROM m_VLData_imageInfo image" + " INNER JOIN m_user user ON (image.image_owner = user.userID)" + " INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" + - " WHERE image_syncMode = 'to_be_decentralized'" ); + " WHERE image_syncMode = to_be_decentralized" ); + } + + public static void updateStatus( String uuid, Status status ) + { + MySQL.update( "UPDATE m_VLData_imageInfo SET image_syncMode=? WHERE GUID_imageID=?", status.toString(), uuid ); + } + + public static void updateFilesize( String uuid, long filesize ) + { + MySQL.update( "UPDATE m_VLData_imageInfo SET image_filesize=? WHERE GUID_imageID=?", filesize, uuid ); } } -- cgit v1.2.3-55-g7522