use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MongoDbDAO method listCardsFromCollection.
@Override
public List<MagicCard> listCardsFromCollection(MagicCollection collection, MagicEdition me) throws SQLException {
logger.debug("getCardsFromCollection " + collection + " " + me);
BasicDBObject query = new BasicDBObject();
List<MagicCard> ret = new ArrayList<>();
List<BasicDBObject> obj = new ArrayList<>();
obj.add(new BasicDBObject(dbColIDField, collection.getName()));
if (me != null) {
obj.add(new BasicDBObject(dbEditionField, me.getId().toUpperCase()));
query.put("$and", obj);
}
db.getCollection(colCards, BasicDBObject.class).find(query).forEach((Consumer<BasicDBObject>) result -> ret.add(deserialize(result.get("card").toString(), MagicCard.class)));
return ret;
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MongoDbDAO method listCollectionFromCards.
@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
List<MagicCollection> ret = new ArrayList<>();
BasicDBObject query = new BasicDBObject();
query.put(dbIDField, IDGenerator.generate(mc));
db.getCollection(colCards, BasicDBObject.class).distinct(dbColIDField, query, String.class).forEach((Consumer<String>) result -> {
try {
logger.trace("found " + mc + " in " + result);
ret.add(getCollection(result));
} catch (SQLException e) {
logger.error("Error", e);
}
});
return ret;
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MysqlDAO method listCollectionFromCards.
@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
if (mc.getEditions().isEmpty())
throw new SQLException("No edition defined");
try (PreparedStatement pst = con.prepareStatement("SELECT collection FROM cards WHERE id=? and edition=?")) {
String id = IDGenerator.generate(mc);
pst.setString(1, id);
pst.setString(2, mc.getEditions().get(0).getId());
logger.trace("SELECT collection FROM cards WHERE id=" + id + " and edition=" + mc.getEditions().get(0).getId());
try (ResultSet rs = pst.executeQuery()) {
List<MagicCollection> cols = new ArrayList<>();
while (rs.next()) {
MagicCollection col = new MagicCollection();
col.setName(rs.getString("collection"));
cols.add(col);
}
return cols;
}
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MysqlDAO method listStocks.
public List<MagicCardStock> listStocks() throws SQLException {
try (PreparedStatement pst = con.prepareStatement("select * from stocks");
ResultSet rs = pst.executeQuery()) {
List<MagicCardStock> colls = new ArrayList<>();
while (rs.next()) {
MagicCardStock state = new MagicCardStock();
state.setComment(rs.getString("comments"));
state.setIdstock(rs.getInt("idstock"));
state.setMagicCard((MagicCard) rs.getObject(cardFieldName));
state.setMagicCollection(new MagicCollection(rs.getString("collection")));
try {
state.setCondition(EnumCondition.valueOf(rs.getString("conditions")));
} catch (Exception e) {
state.setCondition(null);
}
state.setFoil(rs.getBoolean("foil"));
state.setSigned(rs.getBoolean("signedcard"));
state.setLanguage(rs.getString("langage"));
state.setQte(rs.getInt("qte"));
state.setAltered(rs.getBoolean("altered"));
state.setPrice(rs.getDouble("price"));
colls.add(state);
}
logger.debug("load " + colls.size() + " item(s) from stock");
return colls;
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MysqlDAO method getCollections.
@Override
public List<MagicCollection> getCollections() throws SQLException {
try (PreparedStatement pst = con.prepareStatement("select * from collections")) {
try (ResultSet rs = pst.executeQuery()) {
List<MagicCollection> colls = new ArrayList<>();
while (rs.next()) {
MagicCollection mc = new MagicCollection();
mc.setName(rs.getString(1));
colls.add(mc);
}
return colls;
}
}
}
Aggregations