Example usage for org.hibernate LockMode READ

List of usage examples for org.hibernate LockMode READ

Introduction

In this page you can find the example usage for org.hibernate LockMode READ.

Prototype

LockMode READ

To view the source code for org.hibernate LockMode READ.

Click Source Link

Document

A shared lock.

Usage

From source file:com.ephesoft.dcma.da.common.EphesoftSQLServerDialect.java

License:Open Source License

/**
 * This method appends lock hint./*from w w  w . j  av  a  2  s.  c  om*/
 * 
 * @param mode LockMode 
 * @param tableName {@link String}
 * @return {@link String}
 */
public String appendLockHint(LockMode mode, String tableName) {
    if (mode.greaterThan(LockMode.READ)) {
        // does this need holdlock also? : return tableName + " with (updlock, rowlock, holdlock)";
        return tableName + " with (updlock, rowlock)";
    } else {
        return tableName + " with (READCOMMITTED)";
    }
}

From source file:com.ephesoft.dcma.workflow.dialect.EphesoftSQLServerDialect.java

License:Open Source License

/**
 * To append Lock Hint.//from  ww w  .j  a v  a2  s .  c o m
 * 
 * @param mode LockMode
 * @param tableName String
 */
public String appendLockHint(LockMode mode, String tableName) {
    String lockHint;
    if (mode.greaterThan(LockMode.READ)) {
        // does this need holdlock also? : return tableName + " with (updlock, rowlock, holdlock)";
        lockHint = tableName + " with (updlock, rowlock)";
    } else {
        lockHint = tableName + " with (nolock)";
    }
    return lockHint;
}

From source file:com.github.jmnarloch.hstreams.internal.SQLQueryDelegateTest.java

License:Apache License

@Test
public void testAddEntity3() throws Exception {

    // given//w ww  .ja  va2s.  c o  m
    final String alias = "alias";
    final String entity = "entity";
    final LockMode lockMode = LockMode.READ;

    // then
    verifyMethodCall(q -> q.addEntity(alias, entity, lockMode));
}

From source file:com.github.jmnarloch.hstreams.internal.SQLQueryDelegateTest.java

License:Apache License

@Test
public void testAddEntity5() throws Exception {

    // given//from   www .  j  av  a  2s . co  m
    final String alias = "alias";
    final Class<Object> entityType = Object.class;
    final LockMode lockMode = LockMode.READ;

    // then
    verifyMethodCall(q -> q.addEntity(alias, entityType, lockMode));
}

From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java

License:Apache License

/**
 * Initializes a Criteria Query.//from w w  w  .ja v  a  2 s.co  m
 * Mandatory Attributes:<ul>
 * <li><b>name</b>: The unqualified class name driving the criteria query.</li>
 * </ul>
 * Optional Attributes:<ul>
 * <li><b>prefix</b>: The package name of the class driving the criteria query. If null, no package is assumed.</li>
 * <li><b>maxSize</b>: The maximum number of rows to return from the database.</li>
 * <li><b>fetchSize</b>: The number of rows to fetch when rows are requested. Usually not useful for AA4H.</li>
 * <li><b>cacheEnabled</b>: Enables or disables caching for the queried objects.</li>
 * <li><b>cacheMode</b>: The cache options for the queried objects.</li>
 * <li><b>flushMode</b>: The session flush options.</li>
 * <li><b>fetchMode</b>: The collection fetch options for the query.</li>
 * <li><b>lockMode</b>: The row lock options for the queried rows.</li>
 * <li><b>timeOut</b>: The query timeout option.</li>
 * <li><b>rowCountOnly</b>: Returns a count of the query rows only.</li>
 * </ul>
 * @param attrs The attributes of the processed node.
 * @return An appended or new CriteriaSpecification
 * @throws SAXException
 */
protected CriteriaSpecification processCriteria(Attributes attrs) throws SAXException {
    if (inDetached) {
        return criteriaStack.peek();
    }
    String name = attrs.getValue("name");
    String prefix = attrs.getValue("prefix");
    if (prefix != null) {
        className = prefix + "." + name;
    } else {
        className = name;
    }
    String maxSize = attrs.getValue("maxSize");
    String fetchSize = attrs.getValue("fetchSize");
    String firstResult = attrs.getValue("firstResult");
    String cacheEnabled = attrs.getValue("cacheEnabled");
    String cacheMode = attrs.getValue("cacheMode");
    String flushMode = attrs.getValue("flushMode");
    String fetchMode = attrs.getValue("fetchMode");
    String lockMode = attrs.getValue("lockMode");
    String timeOut = attrs.getValue("timeOut");
    String rowCountOnly = attrs.getValue("rowCountOnly");
    Criteria newCriteria = null;
    try {
        if (criteriaStack.size() == 0) {
            newCriteria = session.createCriteria(className);
        } else {
            newCriteria = ((Criteria) criteriaStack.peek()).createCriteria(className);
        }
        criteriaStack.push(newCriteria);
        if ("true".equalsIgnoreCase(rowCountOnly)) {
            newCriteria.setProjection(Projections.projectionList().add(Projections.rowCount())

            );
            setRowCountOnly(true);
        }
        if (maxSize != null && isRowCountOnly() == false) {
            newCriteria.setMaxResults(Integer.parseInt(maxSize));
        }
        if (fetchSize != null && isRowCountOnly() == false) {
            newCriteria.setFetchSize(Integer.parseInt(fetchSize));
        }
        if (firstResult != null && isRowCountOnly() == false) {
            newCriteria.setFirstResult(Integer.parseInt(firstResult));
        }
        if (timeOut != null) {
            newCriteria.setTimeout(Integer.parseInt(timeOut));
        }

        if ("true".equalsIgnoreCase(cacheEnabled)) {
            newCriteria.setCacheable(true);
        } else if ("false".equalsIgnoreCase(cacheEnabled)) {
            newCriteria.setCacheable(false);
        }
        if (fetchMode != null && fetchMode.length() > 0) {
            if ("JOIN".equalsIgnoreCase(fetchMode)) {
                newCriteria.setFetchMode(name, FetchMode.JOIN);
            } else if ("SELECT".equalsIgnoreCase(fetchMode)) {
                newCriteria.setFetchMode(name, FetchMode.SELECT);
            } else {
                newCriteria.setFetchMode(name, FetchMode.DEFAULT);
            }
        } else {
            newCriteria.setFetchMode(name, FetchMode.DEFAULT);
        }
        if (cacheMode != null && cacheMode.length() > 0) {
            if ("GET".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.GET);
            } else if ("IGNORE".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.IGNORE);
            } else if ("NORMAL".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.NORMAL);
            } else if ("PUT".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.PUT);
            } else if ("REFRESH".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.REFRESH);
            } else {
                newCriteria.setCacheMode(CacheMode.NORMAL);
            }
        }
        if (lockMode != null && lockMode.length() > 0) {
            if ("NONE".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.NONE);
            } else if ("READ".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.READ);
            } else if ("UPGRADE".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.UPGRADE);
            } else if ("UPGRADE_NOWAIT".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.UPGRADE_NOWAIT);
            } else if ("WRITE".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.WRITE);
            } else {
                throw new SAXException("lockMode[" + lockMode + "] Not Recognized");
            }
        }
        if (flushMode != null && flushMode.length() > 0) {
            if ("ALWAYS".equalsIgnoreCase(flushMode)) {
                newCriteria.setFlushMode(FlushMode.ALWAYS);
            } else if ("AUTO".equalsIgnoreCase(flushMode)) {
                newCriteria.setFlushMode(FlushMode.AUTO);
            } else if ("COMMIT".equalsIgnoreCase(flushMode)) {
                newCriteria.setFlushMode(FlushMode.COMMIT);
            } else if ("NEVER".equalsIgnoreCase(flushMode)) {
                // NEVER is deprecated, so we won't throw an exception but we'll ignore it.
            } else {
                throw new SAXException("flushMode[" + flushMode + "] Not Recognized");
            }
        }
        return newCriteria;

    } catch (Exception e) {
        throw new SAXException("Unable to configure class " + className, e);
    }
}

From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl.java

License:Open Source License

protected void lockReadFolder(RepoFolder folder) {
    HibernateTemplate template = getHibernateTemplate();
    Session session = template.getSessionFactory().getCurrentSession();
    LockMode folderLockMode = session.getCurrentLockMode(folder);
    if (LockMode.READ.equals(folderLockMode)) {
        String currentURI = folder.getURI();

        //refresh and lock the parent
        template.refresh(folder, LockMode.UPGRADE);

        //check whether the parent URI has changed
        if (!currentURI.equals(folder.getURI())) {
            throw new JSException("jsexception.folder.moved", new Object[] { currentURI, folder.getURI() });
        }//www.  j a v  a  2s  . c  o  m
    }
}

From source file:de.fhg.fokus.hss.action.IfcDeleteAction.java

License:Open Source License

public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse reponse) throws Exception {

    LOGGER.debug("entering");

    ActionForward forward = null;/*from ww w  .j a va2  s  .co m*/
    IfcForm form = (IfcForm) actionForm;
    LOGGER.debug(form);

    try {
        Integer primaryKey = form.getPrimaryKey();

        HibernateUtil.beginTransaction();
        Ifc ifc = (Ifc) HibernateUtil.getCurrentSession().load(Ifc.class, primaryKey, LockMode.READ);
        HibernateUtil.getCurrentSession().delete(ifc);
        HibernateUtil.commitTransaction();

        forward = mapping.findForward(FORWARD_SUCCESS);
    } catch (ConstraintViolationException e) {
        LOGGER.debug(this, e);

        ActionMessages actionMessages = new ActionMessages();
        actionMessages.add(Globals.MESSAGE_KEY, new ActionMessage("error.constraint"));
        saveMessages(request, actionMessages);
        forward = mapping.findForward(FORWARD_FAILURE);
    } finally {
        HibernateUtil.closeSession();
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(forward);
        LOGGER.debug("exiting");
    }
    return forward;
}

From source file:de.fhg.fokus.hss.action.ImpiSubmitAction.java

License:Open Source License

public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse reponse) throws Exception {

    LOGGER.debug("entering");

    ImpiForm form = (ImpiForm) actionForm;
    LOGGER.debug(form);/*from  w ww.j  a va2 s . c  o m*/

    ActionMessages actionMessages = null;
    ActionForward forward = null;

    Impi impi = null;
    ImpiBO impiBO = new ImpiBO();
    try {
        Integer primaryKey = form.getPrimaryKey();
        HibernateUtil.beginTransaction();
        // if pk id = -1 create a new impi and concat them to current imsu
        if (primaryKey.intValue() == -1) {
            // check for existing impi with the same impi string
            if (((Integer) HibernateUtil.getCurrentSession().createQuery(
                    "select count(impi) from de.fhg.fokus.hss.model.Impi as impi where impi.impiString = ?")
                    .setString(0, form.getImpiString()).uniqueResult()).intValue() == 0) {

                impi = new Impi();

                // store assigned imsu if exists
                if (form.getImsuId() != null) {
                    Integer assignedSubscriptionId = new Integer(form.getImsuId());
                    impi.setImsu((Imsu) HibernateUtil.getCurrentSession().load(Imsu.class,
                            assignedSubscriptionId, LockMode.READ));
                }
            } else {
                actionMessages = new ActionMessages();
                actionMessages.add(Globals.MESSAGE_KEY, new ActionMessage("impi.error.duplicated"));
                saveMessages(request, actionMessages);
                forward = mapping.findForward(FORWARD_FAILURE);
            }
        } else {
            impi = impiBO.load(primaryKey);
        }

        // on errors dont store anything, forward to error page.
        if (forward == null) {
            copyValues(form, impi);
            impiBO.saveOrUpdate(impi);
            forward = mapping.findForward(FORWARD_SUCCESS);
            forward = new ActionForward(forward.getPath() + "?impiId=" + impi.getImpiId(), true);
        }

        HibernateUtil.commitTransaction();
    } finally {
        HibernateUtil.closeSession();
    }

    LOGGER.debug("exiting");

    return forward;
}

From source file:de.fhg.fokus.hss.action.TriggerPointShowAction.java

License:Open Source License

public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse reponse) throws Exception {

    LOGGER.debug("entering");
    TriggerPointForm form = (TriggerPointForm) actionForm;
    LOGGER.debug(form);//from   w ww.jav a 2 s  .co m

    if (form.getPrimaryKey().intValue() != -1) {
        try {
            HibernateUtil.beginTransaction();
            //    Load the Trigger Point
            Trigpt trigpt = (Trigpt) HibernateUtil.getCurrentSession().load(Trigpt.class, form.getPrimaryKey(),
                    LockMode.READ);

            // Save current Trigger Point Values
            form.setTrigPtName(trigpt.getName());
            form.setTrigPtId(String.valueOf(trigpt.getTrigptId().intValue()));
            form.setCnf(trigpt.getCnf());

            // Save all SPT's
            form.setSpts(getSpts(trigpt));
            HibernateUtil.commitTransaction();
        } finally {
            HibernateUtil.closeSession();
        }
    }

    LOGGER.debug("exiting");
    return mapping.findForward(FORWARD_SUCCESS);
}

From source file:de.fhg.fokus.hss.action.TriggerPointShowXMLAction.java

License:Open Source License

public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse reponse) throws Exception {

    LOGGER.debug("entering");
    ActionForward forward = null;/*from ww w .j  a  va 2  s. co  m*/
    TriggerPointForm form = (TriggerPointForm) actionForm;
    LOGGER.debug(form);

    TriggerPoint triggerPoint = null;
    try {
        HibernateUtil.beginTransaction();
        // Load the Trigger Point
        Trigpt trigpt = (Trigpt) HibernateUtil.getCurrentSession().load(Trigpt.class, form.getPrimaryKey(),
                LockMode.READ);
        triggerPoint = CxUserProfil.getTriggerPoint(trigpt);
        HibernateUtil.commitTransaction();
    } finally {
        HibernateUtil.closeSession();
    }

    if (triggerPoint != null) {
        StringWriter sw = new StringWriter();
        try {
            triggerPoint.marshal(sw);
            forward = mapping.findForward(FORWARD_SUCCESS);
        } catch (Exception e) {
            LOGGER.warn(this, e);
            ActionMessages actionMessages = new ActionMessages();
            actionMessages.add(Globals.MESSAGE_KEY, new ActionMessage("triggerPoint.error.xml"));
            saveMessages(request, actionMessages);
            forward = mapping.findForward(FORWARD_FAILURE);
        }

        String xml = sw.getBuffer().toString();
        request.setAttribute("triggerPointXML", xml);
    } else {
        ActionMessages actionMessages = new ActionMessages();
        actionMessages.add(Globals.MESSAGE_KEY, new ActionMessage("triggerPoint.error.xml"));
        saveMessages(request, actionMessages);
        forward = mapping.findForward(FORWARD_FAILURE);
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(forward);
        LOGGER.debug("exiting");
    }

    return forward;
}