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;
}
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);
}
}
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;
}
}
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;
}
}
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());
}
}
Aggregations