Example usage for org.hibernate StatelessSession delete

List of usage examples for org.hibernate StatelessSession delete

Introduction

In this page you can find the example usage for org.hibernate StatelessSession delete.

Prototype

void delete(Object entity);

Source Link

Document

Delete a row.

Usage

From source file:com.romeikat.datamessie.core.base.dao.impl.AbstractEntityDao.java

License:Open Source License

/**
 * Deletes an existing entity. If the entity does not exist in the database, an exception is
 * thrown./*from w w  w .j a  v a 2 s  .  c o m*/
 *
 * @param statelessSession
 * @param entity
 */
@Override
public void delete(final StatelessSession statelessSession, final E entity) {
    statelessSession.delete(entity);
}

From source file:org.jahia.modules.external.id.ExternalProviderInitializerServiceImpl.java

License:Open Source License

@Override
public void delete(List<String> externalIds, String providerKey, boolean includeDescendants)
        throws RepositoryException {
    if (externalIds.isEmpty()) {
        return;//from  w ww .ja v a 2s. com
    }
    StatelessSession session = null;
    try {
        List<Integer> hashes = new LinkedList<Integer>();
        for (String externalId : externalIds) {
            int hash = externalId.hashCode();
            hashes.add(hash);
        }
        session = hibernateSessionFactory.openStatelessSession();
        session.beginTransaction();

        // delete all
        session.createQuery(
                "delete from UuidMapping where providerKey=:providerKey and externalIdHash in (:externalIds)")
                .setString("providerKey", providerKey).setParameterList("externalIds", hashes).executeUpdate();

        if (includeDescendants) {
            // delete descendants
            Query selectStmt = session
                    .createQuery(
                            "from UuidMapping where providerKey=:providerKey and externalId like :externalId")
                    .setString("providerKey", providerKey);
            for (String externalId : externalIds) {
                selectStmt.setString("externalId", externalId + "/%");
                List<?> descendants = selectStmt.list();

                for (Object mapping : descendants) {
                    UuidMapping m = (UuidMapping) mapping;
                    session.delete(m);
                    invalidateCache(m.getExternalIdHash(), providerKey);
                }
            }
        }

        session.getTransaction().commit();

        for (String externalId : externalIds) {
            int hash = externalId.hashCode();
            invalidateCache(hash, providerKey);
        }
    } catch (Exception e) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        throw new RepositoryException(e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:org.jahia.services.content.nodetypes.NodeTypesDBServiceImpl.java

License:Open Source License

public void saveCndFile(String filename, String content, Properties properties) throws RepositoryException {
    StatelessSession session = null;
    try {/*  ww  w.j a v a 2  s.  c  o  m*/
        session = getHibernateSessionFactory().openStatelessSession();
        session.beginTransaction();
        NodeTypesDBProvider nodeTypesDBProvider = (NodeTypesDBProvider) session
                .createQuery("from NodeTypesDBProvider where filename=:filename")
                .setString("filename", filename).setReadOnly(false).uniqueResult();
        if (nodeTypesDBProvider != null && content != null) {
            nodeTypesDBProvider.setCndFile(content);
            session.update(nodeTypesDBProvider);
        } else if (nodeTypesDBProvider != null) {
            session.delete(nodeTypesDBProvider);
        } else if (content != null) {
            nodeTypesDBProvider = new NodeTypesDBProvider();
            nodeTypesDBProvider.setFilename(filename);
            nodeTypesDBProvider.setCndFile(content);
            session.insert(nodeTypesDBProvider);
        }

        final StringWriter writer = new StringWriter();
        properties.store(writer, "");

        nodeTypesDBProvider = (NodeTypesDBProvider) session
                .createQuery("from NodeTypesDBProvider where filename=:filename")
                .setString("filename", DEFINITIONS_PROPERTIES).setReadOnly(false).uniqueResult();
        if (nodeTypesDBProvider != null) {
            nodeTypesDBProvider.setCndFile(writer.toString());
            session.update(nodeTypesDBProvider);
        } else {
            nodeTypesDBProvider = new NodeTypesDBProvider();
            nodeTypesDBProvider.setFilename(DEFINITIONS_PROPERTIES);
            nodeTypesDBProvider.setCndFile(writer.toString());
            session.insert(nodeTypesDBProvider);
        }

        session.getTransaction().commit();
    } catch (Exception e) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        throw new RepositoryException(e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:org.openspaces.persistency.hibernate.StatelessHibernateExternalDataSource.java

License:Open Source License

private void executeRemoveIfExists(StatelessSession session, BulkItem bulkItem) {
    Object entry = bulkItem.getItem();
    if (exists(bulkItem, session)) {
        if (logger.isTraceEnabled()) {
            logger.trace("[Exists REMOVE] Deleting Entry [" + entry + "]");
        }//from  w w  w. ja  v a  2 s .c om
        session.delete(entry);
    }
}

From source file:org.openspaces.persistency.hibernate.StatelessHibernateExternalDataSource.java

License:Open Source License

private void executeRemove(StatelessSession session, BulkItem bulkItem) {
    Object entry = bulkItem.getItem();
    if (logger.isTraceEnabled()) {
        logger.trace("[Optimistic REMOVE] Deleting Entry [" + entry + "]");
    }/*  ww  w .j a v  a2s.  c o m*/
    session.delete(entry);
}

From source file:org.openspaces.persistency.hibernate.StatelessHibernateSpaceSynchronizationEndpoint.java

License:Open Source License

private void executeRemoveIfExists(StatelessSession session, DataSyncOperation dataSyncOperation) {
    if (!dataSyncOperation.supportsDataAsObject())
        return;//ww w .java2  s . c  o m

    Object entry = dataSyncOperation.getDataAsObject();
    if (exists(dataSyncOperation, session)) {
        if (logger.isTraceEnabled()) {
            logger.trace("[Exists REMOVE] Deleting Entry [" + entry + "]");
        }
        session.delete(entry);
    }
}

From source file:org.openspaces.persistency.hibernate.StatelessHibernateSpaceSynchronizationEndpoint.java

License:Open Source License

private void executeRemove(StatelessSession session, DataSyncOperation dataSyncOperation) {
    if (!dataSyncOperation.supportsDataAsObject())
        return;//  w w  w . j av a2  s . co m

    Object entry = dataSyncOperation.getDataAsObject();
    if (logger.isTraceEnabled()) {
        logger.trace("[Optimistic REMOVE] Deleting Entry [" + entry + "]");
    }
    session.delete(entry);
}

From source file:vault.queryrouter.models.dao.JobQueueDAO.java

License:Apache License

public static void deleteFromJobQueue(StatelessSession session, int logID) {
    TenantUpdateJob query = (TenantUpdateJob) session.get(TenantUpdateJob.class, logID);
    session.delete(query);
}