Improving collection DAO.

This commit is contained in:
marcins78@gmail.com
2012-12-16 18:54:16 +00:00
parent 70978820bf
commit b5d6741e4d

View File

@@ -32,16 +32,7 @@ public class DbCollectionDAO implements CollectionDAO {
while (rs.next()) { while (rs.next()) {
int playerId = rs.getInt(1); int playerId = rs.getInt(1);
Blob blob = rs.getBlob(2); Blob blob = rs.getBlob(2);
try { playerCollections.put(playerId, extractCollectionAndClose(blob));
InputStream inputStream = blob.getBinaryStream();
try {
playerCollections.put(playerId, _collectionSerializer.deserializeCollection(inputStream));
} finally {
inputStream.close();
}
} finally {
blob.free();
}
} }
return playerCollections; return playerCollections;
} finally { } finally {
@@ -66,16 +57,7 @@ public class DbCollectionDAO implements CollectionDAO {
try { try {
if (rs.next()) { if (rs.next()) {
Blob blob = rs.getBlob(1); Blob blob = rs.getBlob(1);
try { return extractCollectionAndClose(blob);
InputStream inputStream = blob.getBinaryStream();
try {
return _collectionSerializer.deserializeCollection(inputStream);
} finally {
inputStream.close();
}
} finally {
blob.free();
}
} else { } else {
return null; return null;
} }
@@ -90,6 +72,19 @@ public class DbCollectionDAO implements CollectionDAO {
} }
} }
private CardCollection extractCollectionAndClose(Blob blob) throws SQLException, IOException {
try {
InputStream inputStream = blob.getBinaryStream();
try {
return _collectionSerializer.deserializeCollection(inputStream);
} finally {
inputStream.close();
}
} finally {
blob.free();
}
}
public void setPlayerCollection(int playerId, String type, CardCollection collection) throws SQLException, IOException { public void setPlayerCollection(int playerId, String type, CardCollection collection) throws SQLException, IOException {
CardCollection oldCollection = getPlayerCollection(playerId, type); CardCollection oldCollection = getPlayerCollection(playerId, type);