use of org.magic.api.beans.MagicCardStock in project MtgDesktopCompanion by nicho92.
the class MongoDbDAO method listStocks.
@Override
public List<MagicCardStock> listStocks(MagicCard mc, MagicCollection col) throws SQLException {
ArrayList<MagicCardStock> ret = new ArrayList<>();
BasicDBObject filter = new BasicDBObject(dbCardIDField, IDGenerator.generate(mc));
filter.put("stockItem.magicCollection.name", col.getName());
logger.debug(filter);
db.getCollection(colStocks, BasicDBObject.class).find(filter).forEach((Consumer<BasicDBObject>) result -> ret.add(deserialize(result.get(dbStockField).toString(), MagicCardStock.class)));
return ret;
}
use of org.magic.api.beans.MagicCardStock in project MtgDesktopCompanion by nicho92.
the class MysqlDAO method deleteStock.
@Override
public void deleteStock(List<MagicCardStock> state) throws SQLException {
logger.debug("remove " + state.size() + " items in stock");
StringBuilder st = new StringBuilder();
st.append("delete from stocks where idstock IN (");
for (MagicCardStock sto : state) {
st.append(sto.getIdstock()).append(",");
}
st.append(")");
String sql = st.toString().replace(",)", ")");
try (Statement pst = con.createStatement()) {
pst.executeUpdate(sql);
}
}
use of org.magic.api.beans.MagicCardStock in project MtgDesktopCompanion by nicho92.
the class MysqlDAO method listStocks.
@Override
public List<MagicCardStock> listStocks(MagicCard mc, MagicCollection col) throws SQLException {
try (PreparedStatement pst = con.prepareStatement("select * from stocks where idmc=? and collection=?")) {
pst.setString(1, IDGenerator.generate(mc));
pst.setString(2, col.getName());
try (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(mc);
state.setMagicCollection(col);
state.setCondition(EnumCondition.valueOf(rs.getString("conditions")));
state.setFoil(rs.getBoolean("foil"));
state.setSigned(rs.getBoolean("signedcard"));
state.setLanguage(rs.getString("langage"));
state.setAltered(rs.getBoolean("altered"));
state.setQte(rs.getInt("qte"));
state.setPrice(rs.getDouble("price"));
colls.add(state);
}
logger.debug("load " + colls.size() + " item from stock for " + mc);
return colls;
}
}
}
use of org.magic.api.beans.MagicCardStock in project MtgDesktopCompanion by nicho92.
the class PostgresqlDAO method listStocks.
@Override
public List<MagicCardStock> listStocks(MagicCard mc, MagicCollection col) throws SQLException {
try (PreparedStatement pst = con.prepareStatement("select * from stocks where idmc=? and collection=?")) {
pst.setString(1, IDGenerator.generate(mc));
pst.setString(2, col.getName());
try (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(mc);
state.setMagicCollection(col);
state.setCondition(EnumCondition.valueOf(rs.getString("conditions")));
state.setFoil(rs.getBoolean("foil"));
state.setSigned(rs.getBoolean("signedcard"));
state.setLanguage(rs.getString("langage"));
state.setAltered(rs.getBoolean("altered"));
state.setQte(rs.getInt("qte"));
state.setPrice(rs.getDouble("price"));
colls.add(state);
}
logger.debug("load " + colls.size() + " item from stock for " + mc);
return colls;
}
}
}
use of org.magic.api.beans.MagicCardStock in project MtgDesktopCompanion by nicho92.
the class Apprentice2DeckExport method exportStock.
@Override
public void exportStock(List<MagicCardStock> stock, File f) throws IOException {
MagicDeck d = new MagicDeck();
d.setName(f.getName());
for (MagicCardStock mcs : stock) {
d.getMap().put(mcs.getMagicCard(), mcs.getQte());
}
export(d, f);
}
Aggregations