Guest User

Untitled

a guest
Jul 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. public void syncProduct(final ProductInfoExt prod) throws BasicException {
  2. Transaction t = new Transaction(s) {
  3. public Object transact() throws BasicException {
  4. // Sync the Product in a transaction
  5.  
  6. // Try to update
  7. if (new PreparedSentence(
  8. s,
  9. "UPDATE PRODUCTS SET REFERENCE = ?, CODE = ?, NAME = ?, PRICEBUY = ?, PRICESELL = ?, CATEGORY = ?, TAXCAT = ?, IMAGE = ? WHERE ID = ?",
  10. SerializerWriteParams.INSTANCE).exec(new DataParams() {
  11. public void writeValues() throws BasicException {
  12. setString(1, prod.getReference());
  13. setString(2, prod.getCode());
  14. setString(3, prod.getName());
  15. // setBoolean(x, p.isCom());
  16. // setBoolean(x, p.isScale());
  17. setDouble(4, prod.getPriceBuy());
  18. setDouble(5, prod.getPriceSell());
  19. setString(6, prod.getCategoryID());
  20. setString(7, prod.getTaxCategoryID());
  21. setBytes(8, ImageUtils.writeImage(prod.getImage()));
  22. // setDouble(x, 0.0);
  23. // setDouble(x, 0.0);
  24. setString(9, prod.getID());
  25. }
  26. }) == 0) {
  27. // If not updated, try to insert
  28. new PreparedSentence(
  29. s,
  30. "INSERT INTO PRODUCTS (ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, CATEGORY, TAXCAT, IMAGE, STOCKCOST, STOCKVOLUME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  31. SerializerWriteParams.INSTANCE)
  32. .exec(new DataParams() {
  33. public void writeValues() throws BasicException {
  34. setString(1, prod.getID());
  35. setString(2, prod.getReference());
  36. setString(3, prod.getCode());
  37. setString(4, prod.getName());
  38. setBoolean(5, prod.isCom());
  39. setBoolean(6, prod.isScale());
  40. setDouble(7, prod.getPriceBuy());
  41. setDouble(8, prod.getPriceSell());
  42. setString(9, prod.getCategoryID());
  43. setString(10, prod.getTaxCategoryID());
  44. setBytes(11, ImageUtils.writeImage(prod
  45. .getImage()));
  46. setDouble(12, 0.0);
  47. setDouble(13, 0.0);
  48. }
  49. });
  50. }
  51. /* Insert in catalog */
  52. new StaticSentence(
  53. s,
  54. /*
  55. * leyonce - Insert into the product catalog if the
  56. * products aren't already there
  57. */
  58. "INSERT INTO PRODUCTS_CAT(PRODUCT,CATORDER) SELECT ?,NULL WHERE NOT EXISTS (SELECT (?,NULL) FROM PRODUCTS_CAT) ",
  59. SerializerWriteString.INSTANCE).exec(prod.getID());
  60. return null;
  61. }
  62. };
  63. t.execute();
  64. }
Add Comment
Please, Sign In to add comment