Search in sources :

Example 26 with MagicCardStock

use of org.magic.api.beans.MagicCardStock in project MtgDesktopCompanion by nicho92.

the class FileDAO method listStocks.

@Override
public List<MagicCardStock> listStocks(MagicCard mc, MagicCollection col) throws SQLException {
    List<MagicCardStock> st = new ArrayList<>();
    File f = new File(directory, STOCKDIR);
    for (File fstock : FileUtils.listFiles(f, new WildcardFileFilter("*" + IDGenerator.generate(mc)), TrueFileFilter.INSTANCE)) {
        try {
            MagicCardStock s = read(MagicCardStock.class, fstock);
            if (s.getMagicCollection().getName().equals(col.getName()))
                st.add(s);
        } catch (Exception e) {
            throw new SQLException(e);
        }
    }
    return st;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) SQLException(java.sql.SQLException) IOException(java.io.IOException) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 27 with MagicCardStock

use of org.magic.api.beans.MagicCardStock in project MtgDesktopCompanion by nicho92.

the class HsqlDAO 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 28 with MagicCardStock

use of org.magic.api.beans.MagicCardStock in project MtgDesktopCompanion by nicho92.

the class HsqlDAO 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(cardField));
            state.setMagicCollection(new MagicCollection(rs.getString("collection")));
            state.setCondition(EnumCondition.valueOf(rs.getString("conditions")));
            state.setFoil(rs.getBoolean("foil"));
            state.setSigned(rs.getBoolean("signedcard"));
            state.setLanguage(rs.getString("langage"));
            state.setQte(rs.getInt("qte"));
            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) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 29 with MagicCardStock

use of org.magic.api.beans.MagicCardStock 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 30 with MagicCardStock

use of org.magic.api.beans.MagicCardStock in project MtgDesktopCompanion by nicho92.

the class DAOProviderTests method testProviders.

public void testProviders(MTGDao p) {
    try {
        p.init();
        System.out.println("******************TESTING " + p);
        System.out.println("STATUT " + p.getStatut());
        System.out.println("LOCATION " + p.getDBLocation());
        System.out.println("SIZE " + p.getDBSize() / 1024 / 1024);
        System.out.println("TYPE " + p.getType());
        System.out.println("VERS " + p.getVersion());
        System.out.println("******************SAVING");
        p.saveCollection(col);
        p.saveCard(mc, col);
        System.out.println("******************LISTING");
        System.out.println("list  " + p.listCards());
        System.out.println("count " + p.getCardsCount(col, ed));
        System.out.println(p.listCardsFromCollection(col));
        System.out.println(p.listCardsFromCollection(col, ed));
        System.out.println(p.listCardsFromCollection(col, null));
        System.out.println(p.getEditionsIDFromCollection(col));
        System.out.println("global" + p.getCardsCountGlobal(col));
        System.out.println("cols: " + p.getCollections());
        System.out.println("test: " + p.getCollection("TEST"));
        System.out.println("cols: " + p.listCollectionFromCards(mc));
        System.out.println("******************ALERTS");
        MagicCardAlert alert = new MagicCardAlert();
        alert.setCard(mc);
        alert.setPrice(10.0);
        p.saveAlert(alert);
        alert.setPrice(15.0);
        p.updateAlert(alert);
        System.out.println(p.listAlerts());
        System.out.println(p.hasAlert(mc));
        System.out.println("******************STOCKS");
        MagicCardStock stock = new MagicCardStock();
        stock.setMagicCard(mc);
        stock.setComment("TEST");
        stock.setQte(1);
        stock.setCondition(EnumCondition.MINT);
        stock.setLanguage("French");
        stock.setMagicCollection(col);
        p.saveOrUpdateStock(stock);
        stock.setFoil(true);
        p.saveOrUpdateStock(stock);
        for (MagicCardStock st : p.listStocks()) {
            System.out.println(st.getIdstock() + " " + st.getMagicCard() + " " + st.getMagicCollection() + " " + st.isFoil());
        }
        System.out.println("Get stocks " + p.listStocks(mc, col));
        List<MagicCardStock> stocks = new ArrayList<>();
        stocks.add(stock);
        System.out.println("******************BACKUP");
        try {
            p.backup(new File("d:/"));
        } catch (Exception e) {
            System.err.println(e);
        }
        System.out.println("******************DELETE");
        p.deleteStock(stocks);
        // p.removeEdition(ed, col);
        p.removeCard(mc, col);
        p.removeCollection(col);
        p.deleteAlert(alert);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) MagicCardAlert(org.magic.api.beans.MagicCardAlert) File(java.io.File) 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