Skip to content
Snippets Groups Projects
Verified Commit 471c49cb authored by Timm Fitschen's avatar Timm Fitschen
Browse files

EHN: versioning phase 3

parent 89aaaa05
No related branches found
No related tags found
No related merge requests found
...@@ -217,12 +217,9 @@ public class DatabaseUtils { ...@@ -217,12 +217,9 @@ public class DatabaseUtils {
ret.datatype = bytes2UTF8(rs.getBytes("Datatype")); ret.datatype = bytes2UTF8(rs.getBytes("Datatype"));
ret.collection = bytes2UTF8(rs.getBytes("Collection")); ret.collection = bytes2UTF8(rs.getBytes("Collection"));
final String path = bytes2UTF8(rs.getBytes("FilePath")); ret.filePath = bytes2UTF8(rs.getBytes("FilePath"));
if (!rs.wasNull()) { ret.fileSize = rs.getLong("FileSize");
ret.filePath = path; ret.fileHash = bytes2UTF8(rs.getBytes("FileHash"));
ret.fileSize = rs.getLong("FileSize");
ret.fileHash = bytes2UTF8(rs.getBytes("FileHash"));
}
ret.version = bytes2UTF8(rs.getBytes("Version")); ret.version = bytes2UTF8(rs.getBytes("Version"));
ret.versionSeconds = rs.getLong("VersionSeconds"); ret.versionSeconds = rs.getLong("VersionSeconds");
......
...@@ -41,14 +41,30 @@ public class MySQLUpdateSparseEntity extends MySQLTransaction implements UpdateS ...@@ -41,14 +41,30 @@ public class MySQLUpdateSparseEntity extends MySQLTransaction implements UpdateS
} }
public static final String STMT_UPDATE_ENTITY = "call updateEntity(?,?,?,?,?,?,?)"; public static final String STMT_UPDATE_ENTITY = "call updateEntity(?,?,?,?,?,?,?)";
public static final String STMT_UPDATE_FILE_PROPS = public static final String STMT_UPDATE_FILE_PROPS = "call setFileProperties(?,?,?,?)";
"INSERT INTO files (hash, size, path, file_id) VALUES (unhex(?),?,?,?) ON DUPLICATE KEY UPDATE hash=unhex(?), size=?, path=?;";
@Override @Override
public void execute(final SparseEntity spe) throws TransactionException { public void execute(final SparseEntity spe) throws TransactionException {
try { try {
final PreparedStatement updateEntityStmt = prepareStatement(STMT_UPDATE_ENTITY); // file properties;
final PreparedStatement updateFilePropsStmt = prepareStatement(STMT_UPDATE_FILE_PROPS);
updateFilePropsStmt.setInt(1, spe.id);
if (spe.filePath != null) {
updateFilePropsStmt.setString(2, spe.filePath);
updateFilePropsStmt.setLong(3, spe.fileSize);
if (spe.fileHash != null) {
updateFilePropsStmt.setString(4, spe.fileHash);
} else {
updateFilePropsStmt.setNull(4, Types.VARCHAR);
}
} else {
updateFilePropsStmt.setNull(2, Types.VARCHAR);
updateFilePropsStmt.setNull(3, Types.BIGINT);
updateFilePropsStmt.setNull(4, Types.VARCHAR);
}
updateFilePropsStmt.execute();
final PreparedStatement updateEntityStmt = prepareStatement(STMT_UPDATE_ENTITY);
// very sparse entity // very sparse entity
updateEntityStmt.setInt(1, spe.id); updateEntityStmt.setInt(1, spe.id);
updateEntityStmt.setString(2, spe.name); updateEntityStmt.setString(2, spe.name);
...@@ -67,26 +83,6 @@ public class MySQLUpdateSparseEntity extends MySQLTransaction implements UpdateS ...@@ -67,26 +83,6 @@ public class MySQLUpdateSparseEntity extends MySQLTransaction implements UpdateS
spe.version = DatabaseUtils.bytes2UTF8(rs.getBytes("Version")); spe.version = DatabaseUtils.bytes2UTF8(rs.getBytes("Version"));
} }
// file properties;
if (spe.filePath != null) {
final PreparedStatement updateFilePropsStmt = prepareStatement(STMT_UPDATE_FILE_PROPS);
if (spe.fileHash != null) {
updateFilePropsStmt.setString(1, spe.fileHash);
updateFilePropsStmt.setString(5, spe.fileHash);
} else {
updateFilePropsStmt.setNull(1, Types.VARCHAR);
updateFilePropsStmt.setNull(5, Types.VARCHAR);
}
updateFilePropsStmt.setLong(2, spe.fileSize);
updateFilePropsStmt.setLong(6, spe.fileSize);
updateFilePropsStmt.setString(3, spe.filePath);
updateFilePropsStmt.setString(7, spe.filePath);
updateFilePropsStmt.setInt(4, spe.id);
updateFilePropsStmt.execute();
}
} catch (final SQLIntegrityConstraintViolationException e) { } catch (final SQLIntegrityConstraintViolationException e) {
throw new IntegrityException(e); throw new IntegrityException(e);
} catch (final SQLException e) { } catch (final SQLException e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment