summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/db/mappers/DbImageBlock.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/db/mappers/DbImageBlock.java')
-rw-r--r--src/main/java/org/openslx/imagemaster/db/mappers/DbImageBlock.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/mappers/DbImageBlock.java b/src/main/java/org/openslx/imagemaster/db/mappers/DbImageBlock.java
index 7986d87..155f522 100644
--- a/src/main/java/org/openslx/imagemaster/db/mappers/DbImageBlock.java
+++ b/src/main/java/org/openslx/imagemaster/db/mappers/DbImageBlock.java
@@ -1,6 +1,9 @@
package org.openslx.imagemaster.db.mappers;
+import java.nio.ByteBuffer;
+import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
@@ -109,4 +112,68 @@ public class DbImageBlock
}
}
+ public static List<Boolean> getMissingStatusList( String imageVersionId ) throws SQLException
+ {
+ try ( MysqlConnection connection = Database.getConnection() ) {
+ MysqlStatement stmt = connection.prepareStatement( "SELECT startbyte, ismissing FROM imageblock"
+ + " WHERE imageversionid = :imageversionid ORDER BY startbyte ASC" );
+ stmt.setString( "imageversionid", imageVersionId );
+ ResultSet rs = stmt.executeQuery();
+ List<Boolean> list = new ArrayList<>();
+ long expectedOffset = 0;
+ while ( rs.next() ) {
+ long currentOffset = rs.getLong( "startbyte" );
+ if ( currentOffset < expectedOffset )
+ continue;
+ while ( currentOffset > expectedOffset ) {
+ list.add( Boolean.TRUE );
+ expectedOffset += FileChunk.CHUNK_SIZE;
+ }
+ if ( currentOffset == expectedOffset ) {
+ list.add( rs.getBoolean( "ismissing" ) );
+ expectedOffset += FileChunk.CHUNK_SIZE;
+ }
+ }
+ return list;
+ } catch ( SQLException e ) {
+ LOGGER.error( "Query failed in DbImageBlock.getBlockStatuses()", e );
+ throw e;
+ }
+ }
+
+ public static List<ByteBuffer> getBlockHashes( String imageVersionId ) throws SQLException
+ {
+ try ( MysqlConnection connection = Database.getConnection() ) {
+ return getBlockHashes( connection, imageVersionId );
+ } catch ( SQLException e ) {
+ LOGGER.error( "Query failed in DbImageBlock.getBlockHashes()", e );
+ throw e;
+ }
+ }
+
+ private static List<ByteBuffer> getBlockHashes( MysqlConnection connection, String imageVersionId )
+ throws SQLException
+ {
+ MysqlStatement stmt = connection.prepareStatement( "SELECT startbyte, blocksha1 FROM imageblock"
+ + " WHERE imageversionid = :imageversionid ORDER BY startbyte ASC" );
+ stmt.setString( "imageversionid", imageVersionId );
+ ResultSet rs = stmt.executeQuery();
+ List<ByteBuffer> list = new ArrayList<>();
+ long expectedOffset = 0;
+ while ( rs.next() ) {
+ long currentOffset = rs.getLong( "startbyte" );
+ if ( currentOffset < expectedOffset )
+ continue;
+ while ( currentOffset > expectedOffset ) {
+ list.add( null );
+ expectedOffset += FileChunk.CHUNK_SIZE;
+ }
+ if ( currentOffset == expectedOffset ) {
+ list.add( ByteBuffer.wrap( rs.getBytes( "blocksha1" ) ) );
+ expectedOffset += FileChunk.CHUNK_SIZE;
+ }
+ }
+ return list;
+ }
+
}