Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void syncProduct(final ProductInfoExt prod) throws BasicException {
- Transaction t = new Transaction(s) {
- public Object transact() throws BasicException {
- // Sync the Product in a transaction
- // Try to update
- if (new PreparedSentence(
- s,
- "UPDATE PRODUCTS SET REFERENCE = ?, CODE = ?, NAME = ?, PRICEBUY = ?, PRICESELL = ?, CATEGORY = ?, TAXCAT = ?, IMAGE = ? WHERE ID = ?",
- SerializerWriteParams.INSTANCE).exec(new DataParams() {
- public void writeValues() throws BasicException {
- setString(1, prod.getReference());
- setString(2, prod.getCode());
- setString(3, prod.getName());
- // setBoolean(x, p.isCom());
- // setBoolean(x, p.isScale());
- setDouble(4, prod.getPriceBuy());
- setDouble(5, prod.getPriceSell());
- setString(6, prod.getCategoryID());
- setString(7, prod.getTaxCategoryID());
- setBytes(8, ImageUtils.writeImage(prod.getImage()));
- // setDouble(x, 0.0);
- // setDouble(x, 0.0);
- setString(9, prod.getID());
- }
- }) == 0) {
- // If not updated, try to insert
- new PreparedSentence(
- s,
- "INSERT INTO PRODUCTS (ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, CATEGORY, TAXCAT, IMAGE, STOCKCOST, STOCKVOLUME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- SerializerWriteParams.INSTANCE)
- .exec(new DataParams() {
- public void writeValues() throws BasicException {
- setString(1, prod.getID());
- setString(2, prod.getReference());
- setString(3, prod.getCode());
- setString(4, prod.getName());
- setBoolean(5, prod.isCom());
- setBoolean(6, prod.isScale());
- setDouble(7, prod.getPriceBuy());
- setDouble(8, prod.getPriceSell());
- setString(9, prod.getCategoryID());
- setString(10, prod.getTaxCategoryID());
- setBytes(11, ImageUtils.writeImage(prod
- .getImage()));
- setDouble(12, 0.0);
- setDouble(13, 0.0);
- }
- });
- }
- /* Insert in catalog */
- new StaticSentence(
- s,
- /*
- * leyonce - Insert into the product catalog if the
- * products aren't already there
- */
- "INSERT INTO PRODUCTS_CAT(PRODUCT,CATORDER) SELECT ?,NULL WHERE NOT EXISTS (SELECT (?,NULL) FROM PRODUCTS_CAT) ",
- SerializerWriteString.INSTANCE).exec(prod.getID());
- return null;
- }
- };
- t.execute();
- }
Add Comment
Please, Sign In to add comment