diff options
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/db/DbImage.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/db/DbImage.java | 137 |
1 files changed, 72 insertions, 65 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/DbImage.java b/src/main/java/org/openslx/imagemaster/db/DbImage.java index 5070c0d..ca3265f 100644 --- a/src/main/java/org/openslx/imagemaster/db/DbImage.java +++ b/src/main/java/org/openslx/imagemaster/db/DbImage.java @@ -15,19 +15,19 @@ public class DbImage { public final String uuid; - public final int imageVersion; - public final String imageName; + public final int revision; + public final String title; /** * Relative path of image file (relative to Globals.getImageDir()) */ - public final String imagePath; - public final long imageCreateTime; - public final long imageUpdateTime; - public final int imageOwnerId; - public final String contentOperatingSystem; + public final String relativePath; + public final long createTime; + public final long updateTime; + public final int ownerId; + public final String ownerLogin; + public final String operatingSystem; public final boolean isValid; public final boolean isDeleted; - public final String shortDescription; public final String longDescription; public final long fileSize; public final int[] blockStatus; @@ -35,37 +35,37 @@ public class DbImage public DbImage( String uuid ) { this.uuid = uuid; - this.imageVersion = 0; - this.imageName = null; - this.imagePath = null; - this.imageCreateTime = 0; - this.imageUpdateTime = 0; - this.imageOwnerId = 0; - this.contentOperatingSystem = null; + this.revision = 0; + this.title = null; + this.relativePath = null; + this.createTime = 0; + this.updateTime = 0; + this.ownerId = 0; + this.ownerLogin = null; + this.operatingSystem = null; this.isValid = false; this.isDeleted = false; - this.shortDescription = null; this.longDescription = null; this.fileSize = 0; this.blockStatus = null; } public DbImage( String uuid, int imageVersion, String imageName, String imagePath, - long imageCreateTime, long imageUpdateTime, int imageOwnerId, String contentOperatingSystem, - boolean isValid, boolean isDeleted, String shortDescription, String longDescription, + long imageCreateTime, long imageUpdateTime, int imageOwnerId, String imageOwnerLogin, String contentOperatingSystem, + boolean isValid, boolean isDeleted, String longDescription, long fileSize, String missingBlocksList ) { this.uuid = uuid; - this.imageVersion = imageVersion; - this.imageName = imageName; - this.imagePath = imagePath; - this.imageCreateTime = imageCreateTime; - this.imageUpdateTime = imageUpdateTime; - this.imageOwnerId = imageOwnerId; - this.contentOperatingSystem = contentOperatingSystem; + this.revision = imageVersion; + this.title = imageName; + this.relativePath = imagePath; + this.createTime = imageCreateTime; + this.updateTime = imageUpdateTime; + this.ownerId = imageOwnerId; + this.ownerLogin = imageOwnerLogin; + this.operatingSystem = contentOperatingSystem; this.isValid = isValid; this.isDeleted = isDeleted; - this.shortDescription = shortDescription; this.longDescription = longDescription; this.fileSize = fileSize; @@ -106,19 +106,18 @@ public class DbImage for ( int i = 0; i < numBlocks; i++ ) { missingBlocksList = missingBlocksList + String.valueOf( i ) + ";"; } - DbUser user = DbUser.forLogin( imageData.imageOwner ); + DbUser user = DbUser.forLogin( imageData.ownerLogin ); int owner = 0; - if (user != null) + if ( user != null ) owner = user.userId; return MySQL .update( - "INSERT INTO images (UUID, image_version, image_name, image_path, image_createTime, image_updateTime, image_owner, content_operatingSystem, status_isValid, status_isDeleted, image_shortDescription, image_longDescription, fileSize, missingBlocks) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - imageData.uuid, imageData.imageVersion, imageData.imageName, filepath, - imageData.imageCreateTime, imageData.imageUpdateTime, owner, - imageData.contentOperatingSystem, imageData.statusIsValid, - imageData.statusIsDeleted, imageData.imageShortDescription, - imageData.imageLongDescription, imageData.fileSize, + "INSERT INTO image (uuid, revision, title, path, createtime, updatetime, ownerid, operatingsystem, isvalid, isdeleted, description, filesize, missingblocks) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + imageData.uuid, imageData.revision, imageData.title, filepath, + imageData.createTime, imageData.updateTime, owner, + imageData.operatingSystem, imageData.isValid, + imageData.isDeleted, imageData.description, imageData.fileSize, missingBlocksList ); } @@ -136,24 +135,7 @@ public class DbImage missingBlocksList = missingBlocksList + String.valueOf( block ) + ";"; } } - return MySQL.update( "UPDATE images SET images.missingBlocks = ? WHERE images.UUID = ?", missingBlocksList, uuid ); - } - - /** - * Updates the database with a new version of an image and its missing blocks. - * - * @param version - * @param amountBlocks - */ - public void updateVersion( int version, int amountBlocks ) - { - if ( version <= 0 || amountBlocks <= 0 ) - return; - String missingBlocksList = ""; - for ( int i = 0; i < amountBlocks; i++ ) { - missingBlocksList = missingBlocksList + String.valueOf( i ) + ";"; - } - MySQL.update( "UPDATE images SET images.missingBlocks, images.version VALUES (?, ?)", missingBlocksList, version ); + return MySQL.update( "UPDATE image SET image.missingblocks = ? WHERE image.uuid = ?", missingBlocksList, uuid ); } /** @@ -163,7 +145,7 @@ public class DbImage */ public int delete() { - return MySQL.update( "UPDATE images SET images.isDeleted=? WHERE images.UUID=?", true, uuid ); + return MySQL.update( "UPDATE image SET image.isdeleted = 1 WHERE image.uuid = ?", this.uuid ); } /** @@ -176,8 +158,10 @@ public class DbImage return MySQL .findAll( DbImage.class, - "SELECT images.UUID, images.image_version, images.image_name, images.image_path, images.image_createTime, images.image_updateTime, images.image_owner, images.content_operatingSystem, images.status_isValid, images.status_isDeleted, images.image_shortDescription, images.image_longDescription, images.timestamp, images.fileSize, images.token, images.missingBlocks, images.serverSessionId FROM images WHERE missingBlocks != ?", - "" ); + "SELECT image.uuid, image.revision, image.title, image.path, image.createtime, image.updatetime, image.ownerid, user.login, image.operatingsystem, image.isvalid, image.isdeleted, image.description, image.filesize, image.missingblocks" + + " FROM image" + + " INNER JOIN user ON (image.ownerid = user.userid)" + + " WHERE missingBlocks != ''" ); } /** @@ -191,11 +175,34 @@ public class DbImage return MySQL .findUniqueOrNull( DbImage.class, - "SELECT images.UUID, images.image_version, images.image_name, images.image_path, images.image_createTime, images.image_updateTime, images.image_owner, images.content_operatingSystem, images.status_isValid, images.status_isDeleted, images.image_shortDescription, images.image_longDescription, images.fileSize, images.missingBlocks FROM images WHERE uuid = ?", + "SELECT image.uuid, image.revision, image.title, image.path, image.createtime, image.updatetime, image.ownerid, user.login, image.operatingsystem, image.isvalid, image.isdeleted, image.description, image.filesize, image.missingblocks" + + " FROM image" + + " INNER JOIN user ON (image.ownerid = user.userid)" + + " WHERE uuid = ?", uuid ); } /** + * Return all public images as ImageData list, which can be directly + * used by the thrift API. + * + * @param start + * @param limit + * @return + */ + public static List<ImageData> asImageDataList( int start, int limit ) + { + return MySQL + .findAll( + ImageData.class, + "SELECT image.uuid, image.revision, image.title, image.createtime, image.updatetime, user.login, image.operatingsystem, image.isvalid, image.isdeleted, image.description, image.filesize" + + " FROM image" + + " INNER JOIN user ON (image.ownerid = user.userid)" + + " ORDER BY uuid, revision" + + " LIMIT " + start + ", " + limit ); + } + + /** * Creates an instance of the thrift ImageData class of this DbImage object. * * @return The corresponding image data @@ -203,22 +210,22 @@ public class DbImage public ImageData getImageData() { String owner = "unknown"; - DbUser user = DbUser.forLogin( this.imageOwnerId ); - if (user != null) + DbUser user = DbUser.forLogin( this.ownerId ); + if ( user != null ) owner = user.getLogin(); - return new ImageData( this.uuid, this.imageVersion, this.imageName, this.imageCreateTime, - this.imageUpdateTime, owner, this.contentOperatingSystem, this.isValid, - this.isDeleted, this.shortDescription, this.longDescription, this.fileSize ); + return new ImageData( this.uuid, this.revision, this.title, this.createTime, + this.updateTime, owner, this.operatingSystem, this.isValid, + this.isDeleted, this.longDescription, this.fileSize ); } - + /** * Get absolute path of this image - * + * * @return absolute path */ public String getAbsolutePath() { - return Globals.getImageDir() + "/" + this.imagePath; + return Globals.getImageDir() + "/" + this.relativePath; } - + } |