List of usage examples for org.hibernate LockMode UPGRADE
LockMode UPGRADE
To view the source code for org.hibernate LockMode UPGRADE.
Click Source Link
From source file:org.squale.jraf.provider.persistence.hibernate.BlobHelper.java
License:Open Source License
public final static void writeByte2BLOB(ISession session, Object bo, String property, byte[] bytes) throws JrafPersistenceException { // recuperation de la session hibernate Session hSession = ((SessionImpl) session).getSession(); try {/*from w w w . j av a2s . co m*/ // ecriture du BLOB vide createEmptyBlob(hSession, bo, property); // refresh de l'objet hSession.refresh(bo, LockMode.UPGRADE); // recuperation du BLOB BLOB oracleBLOB = (BLOB) PropertyUtils.getProperty(bo, property); // ouverture du stream d'ecriture sur le BLOB OutputStream blobOutputStream = oracleBLOB.getBinaryOutputStream(); blobOutputStream.write(bytes, 0, bytes.length); blobOutputStream.flush(); blobOutputStream.close(); } catch (Exception e) { log.error("Probleme lors de l'ecriture des donnees dans le BLOB", e); throw new JrafPersistenceException("Probleme lors de l'ecriture des donnees dans le BLOB", e); } }
From source file:org.squale.jraf.provider.persistence.hibernate.BlobHelper.java
License:Open Source License
/** * Ecriture d'un fichier dans un BLOB//from www . j a v a 2s . com * @param session session de persistance * @param bo business object * @param property propriete * @param file fichier * @throws JrafPersistenceException */ public final static void writeFile2BLOB(ISession session, Object bo, String property, File file) throws JrafPersistenceException { // recuperation de la session hibernate Session hSession = ((SessionImpl) session).getSession(); long fSize = file.length(); byte[] buffer = null; try { // ecriture du BLOB vide createEmptyBlob(hSession, bo, property); // refresh de l'objet hSession.refresh(bo, LockMode.UPGRADE); // recuperation du BLOB BLOB oracleBLOB = (BLOB) PropertyUtils.getProperty(bo, property); // ouverture du stream d'ecriture sur le BLOB OutputStream blobOutputStream = oracleBLOB.getBinaryOutputStream(); InputStream sampleFileStream = new FileInputStream(file); // cas tres gros fichier if (fSize > Integer.MAX_VALUE) { buffer = new byte[Integer.MAX_VALUE]; } else { buffer = new byte[(int) file.length()]; } int nread = 0; while ((nread = sampleFileStream.read(buffer)) != -1) blobOutputStream.write(buffer, 0, nread); sampleFileStream.close(); blobOutputStream.flush(); blobOutputStream.close(); } catch (Exception e) { log.error("Probleme lors de l'ecriture des donnees dans le BLOB", e); throw new JrafPersistenceException("Probleme lors de l'ecriture des donnees dans le BLOB", e); } }
From source file:org.wintersleep.repository.RepositoryImpl.java
License:Apache License
public T loadById(ID id, boolean lock) { T entity;// w w w. j a va 2s. co m if (lock) entity = getPersistentClass().cast(getSession().load(getPersistentClass(), id, LockMode.UPGRADE)); else entity = getPersistentClass().cast(getSession().load(getPersistentClass(), id)); return entity; }
From source file:org.yes.cart.payment.persistence.service.impl.PaymentModuleGenericDAOImpl.java
License:Apache License
/** * {@inheritDoc}/*from w ww.j a v a 2 s .c om*/ */ @SuppressWarnings(UNCHECKED) public T findById(final PK id, final boolean lock) { T entity; if (lock) { entity = (T) sessionFactory.getCurrentSession().get(getPersistentClass(), id, LockMode.UPGRADE); } else { entity = (T) sessionFactory.getCurrentSession().get(getPersistentClass(), id); } return entity; }
From source file:pl.umk.mat.zawodyweb.database.hibernate.AbstractHibernateDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public T getById(ID id, boolean lock) { if (lock) {/*from w w w. j a v a 2s. c o m*/ return (T) getSession().get(getPersistentClass(), id, LockMode.UPGRADE); } else { return getById(id); } }