summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/db/DbImage.java
diff options
context:
space:
mode:
authorNils Schwabe2014-07-29 15:56:57 +0200
committerNils Schwabe2014-07-29 15:56:57 +0200
commit9c73fdd6812c3c179de0552a0fc568cb380023a0 (patch)
tree2f7de4f18a3c3d966d8fb3a6e508bb187082f923 /src/main/java/org/openslx/imagemaster/db/DbImage.java
parentMove scheduling interval to config and some more todos (diff)
downloadmasterserver-9c73fdd6812c3c179de0552a0fc568cb380023a0.tar.gz
masterserver-9c73fdd6812c3c179de0552a0fc568cb380023a0.tar.xz
masterserver-9c73fdd6812c3c179de0552a0fc568cb380023a0.zip
Change some classes / methods to fit camelCase
Remove some ridiculous stuff
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/db/DbImage.java')
-rw-r--r--src/main/java/org/openslx/imagemaster/db/DbImage.java52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/DbImage.java b/src/main/java/org/openslx/imagemaster/db/DbImage.java
index 099738f..6c64d06 100644
--- a/src/main/java/org/openslx/imagemaster/db/DbImage.java
+++ b/src/main/java/org/openslx/imagemaster/db/DbImage.java
@@ -52,12 +52,12 @@ public class DbImage
this.serverSessionId = null;
}
- public DbImage(String UUID, int imageVersion, String imageName, String imagePath,
+ public DbImage(String uuid, int imageVersion, String imageName, String imagePath,
Timestamp imageCreateTime, Timestamp imageUpdateTime, String imageOwner, String contentOperatingSystem,
boolean isValid, boolean isDeleted, String shortDescription, String longDescription,
Timestamp timestamp, long fileSize, String token, String missingBlocksList, String serverSessionId)
{
- this.uuid = UUID;
+ this.uuid = uuid;
this.imageVersion = imageVersion;
this.imageName = imageName;
this.imagePath = imagePath;
@@ -93,7 +93,7 @@ public class DbImage
*/
public static boolean exists( String uuid )
{
- return getImageByUUID( uuid ) != null;
+ return getImageByUuid( uuid ) != null;
}
/**
@@ -102,11 +102,11 @@ public class DbImage
* @param imageData The metadata of the image
* @param ts The timestamp of inserting
* @param token The token that is able to upload this image
- * @param missingBlocks The blocks that are missing for this image
+ * @param amountBlocks The blocks that are missing for this image
* @param serverSessionId The server that is uploading this image
* @return Affected rows
*/
- public static int insert( ImageData imageData, long ts, String token, int missingBlocks, String serverSessionId, String filepath )
+ public static int insert( ImageData imageData, long ts, String token, int amountBlocks, String serverSessionId, String filepath )
{
Date createTime = new Date( imageData.imageCreateTime );
Date updateTime = new Date( imageData.imageUpdateTime );
@@ -114,7 +114,7 @@ public class DbImage
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
String missingBlocksList = "";
- for ( int i = 0; i < missingBlocks; i++ ) {
+ for ( int i = 0; i < amountBlocks; i++ ) {
missingBlocksList = missingBlocksList + String.valueOf( i ) + ";";
}
@@ -129,11 +129,16 @@ public class DbImage
token, missingBlocksList, serverSessionId );
}
- public String getUUID()
+ public String getUuid()
{
return this.uuid;
}
+ /**
+ * Updates the missing blocks of an uploading image.
+ * @param missingBlocks
+ * @return
+ */
public int updateMissingBlocks( List<Integer> missingBlocks )
{
String missingBlocksList = "";
@@ -145,11 +150,35 @@ public class DbImage
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 );
+ }
+
+ /**
+ * Marks an image as _deleted_ in the database.
+ * @return
+ */
public int delete()
{
- return MySQL.update( "DELETE FROM images WHERE images.UUID=?", uuid );
+ return MySQL.update( "UPDATE images SET images.isDeleted=? WHERE images.UUID=?", true, uuid );
}
+ /**
+ * Returns all images from database where blocks are still missing.
+ * @return
+ */
public static List<DbImage> getUploadingImages()
{
return MySQL
@@ -159,7 +188,12 @@ public class DbImage
"" );
}
- public static DbImage getImageByUUID( String uuid )
+ /**
+ * Returns the image that is corrsponding to a specified uuid.
+ * @param uuid
+ * @return
+ */
+ public static DbImage getImageByUuid( String uuid )
{
return MySQL
.findUniqueOrNull(