Search in sources :

Example 6 with MagicCardStock

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;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) Document(org.bson.Document) Arrays(java.util.Arrays) MagicCollection(org.magic.api.beans.MagicCollection) MongoCollection(com.mongodb.client.MongoCollection) MagicCardAlert(org.magic.api.beans.MagicCardAlert) Aggregates(com.mongodb.client.model.Aggregates) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) MongoDatabase(com.mongodb.client.MongoDatabase) MagicCardStock(org.magic.api.beans.MagicCardStock) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson) STATUT(org.magic.api.interfaces.MTGCardsProvider.STATUT) Filters(com.mongodb.client.model.Filters) SQLException(java.sql.SQLException) MongoClientOptions(com.mongodb.MongoClientOptions) UpdateResult(com.mongodb.client.result.UpdateResult) Gson(com.google.gson.Gson) Map(java.util.Map) AbstractMagicDAO(org.magic.api.interfaces.abstracts.AbstractMagicDAO) CodecRegistries.fromRegistries(org.bson.codecs.configuration.CodecRegistries.fromRegistries) ServerAddress(com.mongodb.ServerAddress) PojoCodecProvider(org.bson.codecs.pojo.PojoCodecProvider) Accumulators(com.mongodb.client.model.Accumulators) MagicNews(org.magic.api.beans.MagicNews) CodecRegistries.fromProviders(org.bson.codecs.configuration.CodecRegistries.fromProviders) BasicDBObject(com.mongodb.BasicDBObject) IOException(java.io.IOException) File(java.io.File) Consumer(java.util.function.Consumer) List(java.util.List) MagicEdition(org.magic.api.beans.MagicEdition) TreeMap(java.util.TreeMap) IDGenerator(org.magic.tools.IDGenerator) MongoClient(com.mongodb.MongoClient) MagicCard(org.magic.api.beans.MagicCard) DeleteResult(com.mongodb.client.result.DeleteResult) BasicDBObject(com.mongodb.BasicDBObject) ArrayList(java.util.ArrayList) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 7 with MagicCardStock

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);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 8 with MagicCardStock

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;
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 9 with MagicCardStock

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;
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 10 with MagicCardStock

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);
}
Also used : MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Aggregations

MagicCardStock (org.magic.api.beans.MagicCardStock)38 ArrayList (java.util.ArrayList)17 MagicDeck (org.magic.api.beans.MagicDeck)14 PreparedStatement (java.sql.PreparedStatement)9 MagicCard (org.magic.api.beans.MagicCard)9 ResultSet (java.sql.ResultSet)6 MagicCollection (org.magic.api.beans.MagicCollection)6 File (java.io.File)5 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 Statement (java.sql.Statement)3 Gson (com.google.gson.Gson)2 FileReader (java.io.FileReader)2 Article (org.api.mkm.modele.Article)2 Document (org.bson.Document)2 Bson (org.bson.conversions.Bson)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1