Example usage for org.hibernate.type LongType INSTANCE

List of usage examples for org.hibernate.type LongType INSTANCE

Introduction

In this page you can find the example usage for org.hibernate.type LongType INSTANCE.

Prototype

LongType INSTANCE

To view the source code for org.hibernate.type LongType INSTANCE.

Click Source Link

Usage

From source file:org.jasig.ssp.util.hibernate.MultipleCountProjection.java

License:Apache License

public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    return new Type[] { LongType.INSTANCE };
}

From source file:org.kimios.kernel.reporting.impl.EntityInformationsReport.java

License:Open Source License

public String getData() throws ConfigException, DataSourceException {
    Vector<Cell> cells = new Vector<Cell>();
    Report report = new Report("EntityInformations");
    report.addColumn("Position");
    report.addColumn("AllVersionsVolume");
    report.addColumn("CurrentVersionsVolume");
    report.addColumn("EntitiesNumber");

    /* get informations about entity */
    String rqInformationsAboutEntity = "SELECT e.dm_entity_path as Position, e.dm_entity_type as EntityType ";
    rqInformationsAboutEntity += "FROM dm_entity e ";
    rqInformationsAboutEntity += "WHERE e.dm_entity_id=:dmEntityUid ";
    SQLQuery sqlInformationsAboutEntity = FactoryInstantiator.getInstance().getDtrFactory().getSession()
            .createSQLQuery(rqInformationsAboutEntity);
    sqlInformationsAboutEntity.addScalar("Position", StringType.INSTANCE);
    sqlInformationsAboutEntity.addScalar("EntityType", IntegerType.INSTANCE);
    sqlInformationsAboutEntity.setLong("dmEntityUid", dmEntity.getUid());

    List<Object[]> reports = sqlInformationsAboutEntity.list();
    for (Object[] r : reports) {
        cells.add(new Cell("Position", (String) r[0]));
    }//from   www .j  av a 2s.co  m

    /* get all versions volume */
    String rqAllVersionsVolume = "SELECT SUM(v.version_length) as AllVersionsVolume "
            + "FROM dm_entity e, document_version v " + "WHERE e.dm_entity_id=v.document_id "
            + "AND e.dm_entity_path LIKE :dmEntityPath";
    SQLQuery sqlAllVersionsVolume = FactoryInstantiator.getInstance().getDtrFactory().getSession()
            .createSQLQuery(rqAllVersionsVolume);
    sqlAllVersionsVolume.addScalar("AllVersionsVolume", LongType.INSTANCE);
    sqlAllVersionsVolume.setString("dmEntityPath", dmEntity.getPath() + "/%");
    Object allVersionsVolume = sqlAllVersionsVolume.list().get(0);
    if (allVersionsVolume == null) {
        allVersionsVolume = new Long(0);
    }
    cells.add(new Cell("AllVersionsVolume", allVersionsVolume));

    /* get current versions volume */

    String rqCurrentVersionsVolume = "SELECT SUM(v.version_length) as AllVersionsVolume "
            + "FROM document_version v, dm_entity e " + "WHERE v.document_id=e.dm_entity_id "
            + "AND e.dm_entity_path LIKE :dmEntityPath " + "AND v.creation_date IN ( "
            + "SELECT MAX(creation_date) as creationDate " + "FROM document_version v "
            + "GROUP BY document_id " + ")";
    SQLQuery sqlCurrentVersionsVolume = FactoryInstantiator.getInstance().getDtrFactory().getSession()
            .createSQLQuery(rqCurrentVersionsVolume);
    sqlCurrentVersionsVolume.addScalar("AllVersionsVolume", LongType.INSTANCE);
    sqlCurrentVersionsVolume.setString("dmEntityPath", dmEntity.getPath() + "/%");
    Object currentVersionsVolume = sqlCurrentVersionsVolume.list().get(0);
    if (currentVersionsVolume == null) {
        currentVersionsVolume = new Long(0);
    }
    cells.add(new Cell("CurrentVersionsVolume", currentVersionsVolume));

    /* get entities number */

    String rqEntitiesNumber = "SELECT COUNT(dm_entity_id) as EntitiesNumber " + "FROM dm_entity e "
            + "WHERE e.dm_entity_path LIKE :dmEntityPath ";
    SQLQuery sqlEntitiesNumber = getSession().createSQLQuery(rqEntitiesNumber);
    sqlEntitiesNumber.addScalar("EntitiesNumber", LongType.INSTANCE);
    sqlEntitiesNumber.setString("dmEntityPath", dmEntity.getPath() + "/%");
    cells.add(new Cell("EntitiesNumber", sqlEntitiesNumber.list().get(0)));

    report.addRow(new Row(cells));
    return report.toXML();
}

From source file:org.kimios.kernel.reporting.impl.UserActionsReport.java

License:Open Source License

public String getData() throws ConfigException, DataSourceException {
    if (order != null && order.length() == 0) {
        order = null;/*from  ww  w  . j  a  v a 2 s .  co  m*/
    }
    if (actionType != null && order != null && order.length() == 0) {
        actionType = null;
    }
    String tmpTable = null;
    try {
        Report temporaryReport = new Report("UserActions");
        temporaryReport.addColumn("Position");
        temporaryReport.addColumn("ActionType");
        temporaryReport.addColumn("ActionTypeParameters");
        temporaryReport.addColumn("Date");

        Calendar dtFrom = Calendar.getInstance();
        dtFrom.setTime(dateFrom);
        Calendar dtTo = Calendar.getInstance();
        dtTo.setTime(dateTo);
        dtFrom.set(Calendar.SECOND, 0);
        dtFrom.set(Calendar.MINUTE, 0);
        dtFrom.set(Calendar.HOUR, 0);
        dtTo.set(Calendar.SECOND, 59);
        dtTo.set(Calendar.MINUTE, 59);
        dtTo.set(Calendar.HOUR, 23);

        /* Workspace log */

        String rqWorkspaceLog = "SELECT w.action as ActionType, ";
        rqWorkspaceLog += "w.action_parameter as ActionTypeParameters, ";
        rqWorkspaceLog += "w.dm_entity_id as EntityUid, ";
        rqWorkspaceLog += "w.log_time as Date, ";
        rqWorkspaceLog += "e.dm_entity_name as EntityName ";
        rqWorkspaceLog += "FROM authentication_source a, entity_log w ";
        rqWorkspaceLog += "LEFT JOIN dm_entity e ";
        rqWorkspaceLog += "ON w.dm_entity_id = e.dm_entity_id ";
        rqWorkspaceLog += "WHERE a.source_name=w.user_source ";
        rqWorkspaceLog += "AND w.username=:userName ";
        rqWorkspaceLog += "AND w.user_source=:userSource ";
        rqWorkspaceLog += "AND w.log_time >= :dateFrom ";
        rqWorkspaceLog += "AND w.log_time <= :dateTo";

        SQLQuery sqlWorkspaceLog = FactoryInstantiator.getInstance().getDtrFactory().getSession()
                .createSQLQuery(rqWorkspaceLog);
        sqlWorkspaceLog.addScalar("ActionType", IntegerType.INSTANCE);
        sqlWorkspaceLog.addScalar("ActionTypeParameters", StringType.INSTANCE);
        sqlWorkspaceLog.addScalar("EntityUid", LongType.INSTANCE);
        sqlWorkspaceLog.addScalar("Date", StringType.INSTANCE);
        sqlWorkspaceLog.addScalar("EntityName", StringType.INSTANCE);
        sqlWorkspaceLog.setString("userName", user.getUid());
        sqlWorkspaceLog.setString("userSource", user.getAuthenticationSourceName());
        sqlWorkspaceLog.setDate("dateFrom", dtFrom.getTime());
        sqlWorkspaceLog.setDate("dateTo", dtTo.getTime());

        List<Object[]> reportWorkspaceLog = sqlWorkspaceLog.list();
        for (Object[] r : reportWorkspaceLog) {
            Vector<Cell> cells = new Vector<Cell>();
            cells.add(new Cell("ActionType", (Integer) r[0]));
            cells.add(new Cell("ActionTypeParameters", r[1] == null ? "" : (String) r[1]));
            cells.add(new Cell("Date", (String) r[3]));
            cells.add(new Cell("EntityName", r[4] == null ? "" : (String) r[4]));
            cells.add(new Cell("Position", new String("/")));
            temporaryReport.addRow(new Row(cells));
        }

        /* Folder log */

        String rqFolderLog = "SELECT f.action as ActionType, ";
        rqFolderLog += "f.action_parameter as ActionTypeParameters, ";
        rqFolderLog += "f.dm_entity_id as EntityUid, ";
        rqFolderLog += "f.log_time as Date, ";
        rqFolderLog += "e.dm_entity_name as EntityName, ";
        rqFolderLog += "entt.dm_entity_path as Position ";
        rqFolderLog += "FROM authentication_source a, entity_log f ";
        rqFolderLog += "LEFT JOIN dm_entity e ";
        rqFolderLog += "ON f.dm_entity_id = e.dm_entity_id ";
        rqFolderLog += "LEFT JOIN dm_entity entt ";
        rqFolderLog += "ON f.dm_entity_id = entt.dm_entity_id ";
        rqFolderLog += "WHERE a.source_name=f.user_source ";
        rqFolderLog += "AND f.username=:userName ";
        rqFolderLog += "AND f.user_source=:userSource ";
        rqFolderLog += "AND f.log_time >= :dateFrom ";
        rqFolderLog += "AND f.log_time <= :dateTo ";

        SQLQuery sqlFolderLog = FactoryInstantiator.getInstance().getDtrFactory().getSession()
                .createSQLQuery(rqFolderLog);
        sqlFolderLog.addScalar("ActionType", IntegerType.INSTANCE);
        sqlFolderLog.addScalar("ActionTypeParameters", StringType.INSTANCE);
        sqlFolderLog.addScalar("EntityUid", LongType.INSTANCE);
        sqlFolderLog.addScalar("Date", StringType.INSTANCE);
        sqlFolderLog.addScalar("EntityName", StringType.INSTANCE);
        sqlFolderLog.addScalar("Position", StringType.INSTANCE);
        sqlFolderLog.setString("userName", user.getUid());
        sqlFolderLog.setString("userSource", user.getAuthenticationSourceName());
        sqlFolderLog.setDate("dateFrom", dtFrom.getTime());
        sqlFolderLog.setDate("dateTo", dtTo.getTime());

        List<Object[]> reportFolderLog = sqlFolderLog.list();
        for (Object[] r : reportFolderLog) {
            Vector<Cell> cells = new Vector<Cell>();
            cells.add(new Cell("ActionType", (Integer) r[0]));
            cells.add(new Cell("ActionTypeParameters", r[1] == null ? "" : (String) r[1]));
            cells.add(new Cell("Date", (String) r[3]));
            cells.add(new Cell("EntityName", r[4] == null ? "" : (String) r[4]));
            cells.add(new Cell("Position", r[5] == null ? "" : (String) r[5]));
            temporaryReport.addRow(new Row(cells));
        }

        /* Document log */

        String rqDocumentLog = "SELECT d.action as ActionType, ";
        rqDocumentLog += "d.action_parameter as ActionTypeParameters, ";
        rqDocumentLog += "d.dm_entity_id as EntityUid, ";
        rqDocumentLog += "d.log_time as Date, ";
        rqDocumentLog += "entt.dm_entity_name as EntityName, ";
        rqDocumentLog += "entt.dm_entity_path as Position ";
        rqDocumentLog += "FROM authentication_source a, entity_log d ";
        rqDocumentLog += "LEFT JOIN dm_entity entt ";
        rqDocumentLog += "ON d.dm_entity_id = entt.dm_entity_id ";
        rqDocumentLog += "WHERE a.source_name=d.user_source ";
        rqDocumentLog += "AND d.username=:userName ";
        rqDocumentLog += "AND d.user_source=:userSource ";
        rqDocumentLog += "AND d.log_time >= :dateFrom ";
        rqDocumentLog += "AND d.log_time <= :dateTo";

        SQLQuery sqlDocumentLog = FactoryInstantiator.getInstance().getDtrFactory().getSession()
                .createSQLQuery(rqDocumentLog);
        sqlDocumentLog.addScalar("ActionType", IntegerType.INSTANCE);
        sqlDocumentLog.addScalar("ActionTypeParameters", StringType.INSTANCE);
        sqlDocumentLog.addScalar("EntityUid", LongType.INSTANCE);
        sqlDocumentLog.addScalar("Date", StringType.INSTANCE);
        sqlDocumentLog.addScalar("EntityName", StringType.INSTANCE);
        sqlDocumentLog.addScalar("Position", StringType.INSTANCE);
        sqlDocumentLog.setString("userName", user.getUid());
        sqlDocumentLog.setString("userSource", user.getAuthenticationSourceName());
        sqlDocumentLog.setDate("dateFrom", dtFrom.getTime());
        sqlDocumentLog.setDate("dateTo", dtTo.getTime());

        List<Object[]> reportDocumentLog = sqlDocumentLog.list();
        for (Object[] r : reportDocumentLog) {
            Vector<Cell> cells = new Vector<Cell>();
            cells.add(new Cell("ActionType", (Integer) r[0]));
            cells.add(new Cell("ActionTypeParameters", r[1] == null ? "" : (String) r[1]));
            cells.add(new Cell("Date", (String) r[3]));
            cells.add(new Cell("EntityName", r[4] == null ? "" : (String) r[4]));
            cells.add(new Cell("Position", r[5] == null ? "" : (String) r[5]));
            temporaryReport.addRow(new Row(cells));
        }

        /* Create temporary table */

        tmpTable = "tmp_" + sessionUid.substring(0, 8) + "_" + new Date().getTime();
        String rqCreateTable = "CREATE TABLE " + tmpTable + " ( ";
        rqCreateTable += "ReportActionType character varying(2), ";
        rqCreateTable += "ReportActionTypeParameters character varying(255), ";
        rqCreateTable += "ReportEntityName character varying(255), ";
        rqCreateTable += "ReportDate character varying(255), ";
        rqCreateTable += "ReportPosition character varying(255) )";

        SQLQuery sqlCreateTable = FactoryInstantiator.getInstance().getDtrFactory().getSession()
                .createSQLQuery(rqCreateTable);
        sqlCreateTable.executeUpdate();

        for (Row row : temporaryReport.getBody().getRows()) {
            String action = String.valueOf(row.getValue("ActionType"));
            String parameters = String.valueOf(row.getValue("ActionTypeParameters"));
            String entityName = String.valueOf(row.getValue("EntityName"));
            String date = String.valueOf(row.getValue("Date"));
            String position = String.valueOf(row.getValue("Position"));
            String rqInsertTable = "INSERT INTO " + tmpTable + " ( ";
            rqInsertTable += "ReportActionType, ReportActionTypeParameters, ReportEntityName, ReportDate, ReportPosition ";
            rqInsertTable += " ) VALUES (:actionType,:parameters,:entityName,:date,:position)";
            SQLQuery sqlInsertTable = getSession().createSQLQuery(rqInsertTable);
            sqlInsertTable.setString("actionType", action);
            sqlInsertTable.setString("parameters", parameters);
            sqlInsertTable.setString("entityName", entityName);
            sqlInsertTable.setString("date", date);
            sqlInsertTable.setString("position", position);
            sqlInsertTable.executeUpdate();
        }

        /* Report */

        String rq = "SELECT ReportActionType, ReportActionTypeParameters, ReportEntityName, ReportDate, ReportPosition ";
        rq += "FROM " + tmpTable + " ";
        rq += (actionType != null ? " WHERE ReportActionType=:actionType " : " ");
        rq += " ORDER BY " + (order == null ? "ReportDate" : order) + " " + (asc ? "ASC" : "DESC");

        SQLQuery sql = FactoryInstantiator.getInstance().getDtrFactory().getSession().createSQLQuery(rq);
        sql.addScalar("ReportActionType", StringType.INSTANCE);
        sql.addScalar("ReportActionTypeParameters", StringType.INSTANCE);
        sql.addScalar("ReportEntityName", StringType.INSTANCE);
        sql.addScalar("ReportDate", StringType.INSTANCE);
        sql.addScalar("ReportPosition", StringType.INSTANCE);
        if (actionType != null) {
            sql.setString("actionType", actionType);
        }

        Report report = new Report("UserActions");
        report.addColumn("Position");
        report.addColumn("EntityName");
        report.addColumn("ActionType");
        report.addColumn("ActionTypeParameters");
        report.addColumn("Date");

        List<Object[]> reports = sql.list();
        for (Object[] r : reports) {
            Vector<Cell> cells = new Vector<Cell>();
            cells.add(new Cell("ActionType", (String) r[0]));
            cells.add(new Cell("ActionTypeParameters", (String) r[1]));
            cells.add(new Cell("EntityName", (String) r[2]));
            cells.add(new Cell("Date", (String) r[3]));

            String pos = ((String) r[4]);
            int index = pos.lastIndexOf('/');
            if (index != -1 && !"/".equals(pos)) {
                pos = pos.substring(0, index);
            }
            cells.add(new Cell("Position", pos));
            report.addRow(new Row(cells));
        }
        return report.toXML();
    } catch (HibernateException he) {
        he.printStackTrace();
        throw he;
    } finally {
        /* Drop temporary table */
        FactoryInstantiator.getInstance().getDtrFactory().getSession().createSQLQuery("DROP TABLE " + tmpTable)
                .executeUpdate();
    }
}

From source file:org.kimios.kernel.security.factory.HDMEntitySecurityFactory.java

License:Open Source License

public <T extends DMEntityImpl> List<T> authorizedEntities(List<T> e, String userName, String userSource,
        Vector<String> hashs, Vector<String> noAccessHash) throws ConfigException, DataSourceException {
    try {//from   w w w .  j  a v  a2  s  .  c o m

        Vector<String> paths = new Vector<String>();
        for (T it : e) {
            paths.add(it.getPath());
        }

        String rightQuery = "select distinct dm.dm_entity_id, dm.dm_entity_path from dm_entity dm left join dm_entity_acl acl on "
                + "(dm.dm_entity_id = acl.dm_entity_id) where " + " dm.dm_entity_path in (:paths) and "
                + " (acl.rule_hash in (:hash) or (dm.dm_entity_owner = :userName and dm.dm_entity_owner_source = :userSource))"
                + " and dm.dm_entity_id not in (select no.dm_entity_id from dm_entity_acl no inner join dm_entity dmid "
                + "on (dmid.dm_entity_id = no.dm_entity_id) "
                + "where dmid.dm_entity_path in (:paths) and no.rule_hash in (:noAccessHash))";

        List<Long> idsList = getSession().createSQLQuery(rightQuery)
                .addScalar("dm_entity_id", LongType.INSTANCE).setParameterList("paths", paths)
                .setParameterList("hash", hashs).setString("userName", userName)
                .setString("userSource", userSource).setParameterList("noAccessHash", noAccessHash).list();

        if (idsList == null || idsList.size() == 0) {
            return new ArrayList<T>();
        }
        return getSession().createQuery("from DMEntityImpl where id in (:idList)")
                .setParameterList("idList", idsList).list();
    } catch (HibernateException ex) {
        throw new DataSourceException(ex);
    }
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultMaxFileSizeInSubDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father");
            sb.append(" JOIN quota AS child");
            sb.append(" ON child.domain_parent_id = father.domain_id");
            sb.append(" AND child.quota_type = :domainType ");
            sb.append(" AND father.domain_parent_id = :domainId ");
            sb.append(" AND father.default_max_file_size_override = false");
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }// w  w  w .  j a  v  a 2  s  .c  o  m
            sb.append(" AND child.default_max_file_size_override = false");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("child_id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            if (containerType != null) {
                query.setString("containerType", containerType.name());
            }
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("child_ids :" + res);
            return res;
        }
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultMaxFileSizeInTopDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT id FROM quota ");
            sb.append(" WHERE quota_type = :domainType");
            sb.append(" AND container_type = :containerType");
            sb.append(" AND max_file_size_override = false");
            sb.append(" AND domain_parent_id = :domainId ");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            query.setString("containerType", containerType.name());
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("ids :" + res);
            return res;
        }//from  ww w . ja v  a 2 s.  c om
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforMaxFileSizeInSubDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father");
            sb.append(" JOIN quota AS child");
            sb.append(" ON child.domain_parent_id = father.domain_id");
            sb.append(" AND child.quota_type = :domainType ");
            sb.append(" AND father.domain_parent_id = :domainId ");
            sb.append(" AND father.max_file_size_override = false");
            if (containerType != null) {
                sb.append(" AND father.container_type = :containerType");
            }//from w  w w. j  a va 2  s .  c  o m
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }
            sb.append(" AND child.max_file_size_override = false");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("child_id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            if (containerType != null) {
                query.setString("containerType", containerType.name());
            }
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("child_ids :" + res);
            return res;
        }
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultAccountQuotaInTopDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT id FROM quota ");
            sb.append(" WHERE quota_type = :domainType");
            sb.append(" AND container_type = :containerType");
            sb.append(" AND account_quota_override = false");
            sb.append(" AND domain_parent_id = :domainId ");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            query.setString("containerType", containerType.name());
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("ids :" + res);
            return res;
        }//from w w  w. j  av a  2s  .c  o  m
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultAccountQuotaInSubDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father");
            sb.append(" JOIN quota AS child");
            sb.append(" ON child.domain_parent_id = father.domain_id");
            sb.append(" AND child.quota_type = :domainType ");
            sb.append(" AND father.domain_parent_id = :domainId ");
            sb.append(" AND father.default_account_quota_override = false");
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }//from ww  w.j a  v a  2  s . c o m
            sb.append(" AND child.account_quota_override = false");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("child_id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            if (containerType != null) {
                query.setString("containerType", containerType.name());
            }
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("child_ids :" + res);
            return res;
        }
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforAccountQuotaInSubDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father");
            sb.append(" JOIN quota AS child");
            sb.append(" ON child.domain_parent_id = father.domain_id");
            sb.append(" AND child.quota_type = :domainType ");
            sb.append(" AND father.domain_parent_id = :domainId ");
            sb.append(" AND father.default_account_quota_override = false");
            if (containerType != null) {
                sb.append(" AND father.container_type = :containerType");
            }//  w w  w  .  j a v  a2  s .  co  m
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }
            sb.append(" AND child.account_quota_override = false");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("child_id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            if (containerType != null) {
                query.setString("containerType", containerType.name());
            }
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("child_ids :" + res);
            return res;
        }
    };
    return getHibernateTemplate().execute(action);
}