Search in sources :

Example 21 with MagicCollection

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;
}
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) MagicCard(org.magic.api.beans.MagicCard) ArrayList(java.util.ArrayList)

Example 22 with MagicCollection

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;
}
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) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) MagicCollection(org.magic.api.beans.MagicCollection)

Example 23 with MagicCollection

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

Example 24 with MagicCollection

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

Example 25 with MagicCollection

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

Aggregations

MagicCollection (org.magic.api.beans.MagicCollection)32 ArrayList (java.util.ArrayList)20 MagicCard (org.magic.api.beans.MagicCard)15 SQLException (java.sql.SQLException)14 MagicEdition (org.magic.api.beans.MagicEdition)13 PreparedStatement (java.sql.PreparedStatement)12 ResultSet (java.sql.ResultSet)12 IOException (java.io.IOException)9 MagicCardStock (org.magic.api.beans.MagicCardStock)8 File (java.io.File)7 List (java.util.List)6 BorderLayout (java.awt.BorderLayout)4 Map (java.util.Map)4 JButton (javax.swing.JButton)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 BasicDBObject (com.mongodb.BasicDBObject)3 DeleteResult (com.mongodb.client.result.DeleteResult)3 Point (java.awt.Point)3