List of usage examples for org.hibernate QueryTimeoutException getSQLException
public SQLException getSQLException()
From source file:org.openbravo.materialmgmt.VariantAutomaticGenerationProcess.java
License:Open Source License
@Override public void execute(ProcessBundle bundle) throws Exception { OBError msg = new OBError(); msg.setType("Success"); msg.setTitle(OBMessageUtils.messageBD("Success")); try {// w w w .ja v a 2s .com // retrieve standard params final String recordID = (String) bundle.getParams().get("M_Product_ID"); Product product = OBDal.getInstance().get(Product.class, recordID); runChecks(product); int totalMaxLength = product.getSearchKey().length(); long variantNumber = 1; Map<String, ProductCharacteristicAux> prChUseCode = new HashMap<String, ProductCharacteristicAux>(); OBCriteria<ProductCharacteristic> prChCrit = OBDal.getInstance() .createCriteria(ProductCharacteristic.class); prChCrit.add(Restrictions.eq(ProductCharacteristic.PROPERTY_PRODUCT, product)); prChCrit.add(Restrictions.eq(ProductCharacteristic.PROPERTY_VARIANT, true)); prChCrit.addOrderBy(ProductCharacteristic.PROPERTY_SEQUENCENUMBER, true); List<String> prChs = new ArrayList<String>(); for (ProductCharacteristic pc : prChCrit.list()) { prChs.add(pc.getId()); } int chNumber = prChs.size(); String[] currentValues = new String[chNumber]; int i = 0; for (ProductCharacteristic prCh : prChCrit.list()) { OBCriteria<ProductCharacteristicConf> prChConfCrit = OBDal.getInstance() .createCriteria(ProductCharacteristicConf.class); prChConfCrit.add(Restrictions.eq(ProductCharacteristicConf.PROPERTY_CHARACTERISTICOFPRODUCT, prCh)); List<String> prChConfs = new ArrayList<String>(); for (ProductCharacteristicConf pcc : prChConfCrit.list()) { prChConfs.add(pcc.getId()); } long valuesCount = prChConfs.size(); boolean useCode = true; int maxLength = 0; for (String id : prChConfs) { ProductCharacteristicConf prChConf = OBDal.getInstance().get(ProductCharacteristicConf.class, id); if (StringUtils.isBlank(prChConf.getCode())) { useCode = false; break; } if (prChConf.getCode().length() > maxLength) { maxLength = prChConf.getCode().length(); } } variantNumber = variantNumber * valuesCount; if (useCode) { totalMaxLength += maxLength; } ProductCharacteristicAux prChAux = new ProductCharacteristicAux(useCode, prChConfs); currentValues[i] = prChAux.getNextValue(); prChUseCode.put(prCh.getId(), prChAux); i++; } totalMaxLength += Long.toString(variantNumber).length(); boolean useCodes = totalMaxLength <= searchKeyLength; boolean hasNext = true; int productNo = 0; int k = 0; Long start = System.currentTimeMillis(); boolean multilingualDocs = OBDal.getInstance().get(Client.class, bundle.getContext().getClient()) .isMultilingualDocuments(); do { k = k + 1; // Create variant product product = OBDal.getInstance().get(Product.class, recordID); Product variant = (Product) DalUtil.copy(product); if (multilingualDocs) { variant.set(Product.PROPERTY_PRODUCTTRLLIST, null); } if (product.getImage() != null) { Image newPrImage = (Image) DalUtil.copy(product.getImage(), false); OBDal.getInstance().save(newPrImage); variant.setImage(newPrImage); } variant.setGenericProduct(product); variant.setProductAccountsList(Collections.<ProductAccounts>emptyList()); variant.setGeneric(false); for (ProductCharacteristic prCh : variant.getProductCharacteristicList()) { prCh.setProductCharacteristicConfList(Collections.<ProductCharacteristicConf>emptyList()); } String searchKey = product.getSearchKey(); for (i = 0; i < chNumber; i++) { ProductCharacteristicConf prChConf = OBDal.getInstance().get(ProductCharacteristicConf.class, currentValues[i]); ProductCharacteristicAux prChConfAux = prChUseCode.get(prChs.get(i)); if (useCodes && prChConfAux.isUseCode()) { searchKey += prChConf.getCode(); } } for (int j = 0; j < (Long.toString(variantNumber).length() - Integer.toString(productNo).length()); j++) { searchKey += "0"; } searchKey += productNo; variant.setSearchKey(searchKey); OBDal.getInstance().save(variant); String strChDesc = ""; for (i = 0; i < chNumber; i++) { ProductCharacteristicConf prChConf = OBDal.getInstance().get(ProductCharacteristicConf.class, currentValues[i]); ProductCharacteristicValue newPrChValue = OBProvider.getInstance() .get(ProductCharacteristicValue.class); newPrChValue.setCharacteristic(prChConf.getCharacteristicOfProduct().getCharacteristic()); newPrChValue.setCharacteristicValue(prChConf.getCharacteristicValue()); newPrChValue.setProduct(variant); newPrChValue.setOrganization(product.getOrganization()); if (StringUtils.isNotBlank(strChDesc)) { strChDesc += ", "; } strChDesc += prChConf.getCharacteristicOfProduct().getCharacteristic().getName() + ":"; strChDesc += " " + prChConf.getCharacteristicValue().getName(); OBDal.getInstance().save(newPrChValue); if (prChConf.getCharacteristicOfProduct().isDefinesPrice() && prChConf.getNetUnitPrice() != null) { setPrice(variant, prChConf.getNetUnitPrice(), prChConf.getCharacteristicOfProduct().getPriceListType()); } if (prChConf.getCharacteristicOfProduct().isDefinesImage() && prChConf.getImage() != null) { Image newImage = (Image) DalUtil.copy(prChConf.getImage(), false); OBDal.getInstance().save(newImage); variant.setImage(newImage); } } variant.setCharacteristicDescription(strChDesc); OBDal.getInstance().save(variant); for (i = 0; i < chNumber; i++) { ProductCharacteristicAux prChConfAux = prChUseCode.get(prChs.get(i)); currentValues[i] = prChConfAux.getNextValue(); if (!prChConfAux.isIteratorReset()) { break; } else if (i + 1 == chNumber) { hasNext = false; } } productNo++; // Creates variants from 1 to 1000 and shows time spent on it. if (k == 1000) { OBDal.getInstance().flush(); OBDal.getInstance().getSession().clear(); log4j.debug("Variants loop: " + productNo + " : " + ((System.currentTimeMillis()) - (start))); k = 0; start = System.currentTimeMillis(); } } while (hasNext); OBDal.getInstance().flush(); OBDal.getInstance().getSession().clear(); String message = OBMessageUtils.messageBD("variantsCreated"); Map<String, String> map = new HashMap<String, String>(); map.put("variantNo", Long.toString(productNo)); msg.setMessage(OBMessageUtils.parseTranslation(message, map)); bundle.setResult(msg); // Postgres wraps the exception into a GenericJDBCException } catch (GenericJDBCException ge) { log4j.error("Exception processing variant generation", ge); msg.setType("Error"); msg.setTitle( OBMessageUtils.messageBD(bundle.getConnection(), "Error", bundle.getContext().getLanguage())); msg.setMessage(ge.getSQLException().getMessage()); bundle.setResult(msg); OBDal.getInstance().rollbackAndClose(); // Oracle wraps the exception into a QueryTimeoutException } catch (QueryTimeoutException qte) { log4j.error("Exception processing variant generation", qte); msg.setType("Error"); msg.setTitle( OBMessageUtils.messageBD(bundle.getConnection(), "Error", bundle.getContext().getLanguage())); msg.setMessage(qte.getSQLException().getMessage().split("\n")[0]); bundle.setResult(msg); OBDal.getInstance().rollbackAndClose(); } catch (final Exception e) { log4j.error("Exception processing variant generation", e); msg.setType("Error"); msg.setTitle( OBMessageUtils.messageBD(bundle.getConnection(), "Error", bundle.getContext().getLanguage())); msg.setMessage(FIN_Utility.getExceptionMessage(e)); bundle.setResult(msg); OBDal.getInstance().rollbackAndClose(); } }
From source file:org.openbravo.materialmgmt.VariantChDescUpdateProcess.java
License:Open Source License
@Override public void doExecute(ProcessBundle bundle) throws Exception { OBError msg = new OBError(); msg.setType("Success"); msg.setTitle(OBMessageUtils.messageBD("Success")); try {//from ww w . j a v a 2 s. c o m // retrieve standard params String strProductId = (String) bundle.getParams().get("mProductId"); String strChValueId = (String) bundle.getParams().get("mChValueId"); update(strProductId, strChValueId); bundle.setResult(msg); // Postgres wraps the exception into a GenericJDBCException } catch (GenericJDBCException ge) { log4j.error("Exception processing variant generation", ge); msg.setType("Error"); msg.setTitle( OBMessageUtils.messageBD(bundle.getConnection(), "Error", bundle.getContext().getLanguage())); msg.setMessage(ge.getSQLException().getMessage()); bundle.setResult(msg); OBDal.getInstance().rollbackAndClose(); // Oracle wraps the exception into a QueryTimeoutException } catch (QueryTimeoutException qte) { log4j.error("Exception processing variant generation", qte); msg.setType("Error"); msg.setTitle( OBMessageUtils.messageBD(bundle.getConnection(), "Error", bundle.getContext().getLanguage())); msg.setMessage(qte.getSQLException().getMessage().split("\n")[0]); bundle.setResult(msg); OBDal.getInstance().rollbackAndClose(); } catch (final Exception e) { log4j.error("Exception processing variant generation", e); msg.setType("Error"); msg.setTitle( OBMessageUtils.messageBD(bundle.getConnection(), "Error", bundle.getContext().getLanguage())); msg.setMessage(FIN_Utility.getExceptionMessage(e)); bundle.setResult(msg); OBDal.getInstance().rollbackAndClose(); } }