Example usage for org.hibernate SQLQuery setString

List of usage examples for org.hibernate SQLQuery setString

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setString.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setString(int position, String val) 

Source Link

Document

Bind a positional String-valued parameter.

Usage

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");
            }//from  w  w  w. ja v  a 2  s .  co  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.  j  av  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");
            }// ww  w  .j a v  a  2  s  . c  om
            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  .ja v  a 2s.  co  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 av 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  av  a 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.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.GenericQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultQuotaInSubDomains(AbstractDomain domain, Long quota, 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_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 va  2s.  co m
            sb.append(" AND child.default_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.GenericQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforQuotaInSubDomains(AbstractDomain domain, Long quota, 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.quota_override = false");
            if (containerType != null) {
                sb.append(" AND father.container_type = :containerType");
            }/*from  w  ww .  j av a 2s  .co m*/
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }
            sb.append(" AND child.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.mousephenotype.dcc.utils.persistence.HibernateManager.java

License:Apache License

public <T> List<T> nativeQuery(String query, Class<T> clazz,
        com.google.common.collect.Table<String, Class, Object> parameters) {
    this.refreshSession();
    Transaction transaction = null;/*w  w w  .  j  a v  a  2s .  c o  m*/
    List<T> result = null;
    try {
        transaction = session.beginTransaction();
        SQLQuery sqlQuery = session.createSQLQuery(query).addEntity(clazz);
        if (parameters != null) {
            for (com.google.common.collect.Table.Cell<String, Class, Object> entry : parameters.cellSet()) {
                if (entry.getColumnKey().equals(String.class)) {
                    sqlQuery.setString(entry.getRowKey(), (String) entry.getValue());
                    continue;
                }
                if (entry.getColumnKey().equals(Long.class)) {
                    sqlQuery.setLong(entry.getRowKey(), (Long) entry.getValue());
                    continue;
                }
                if (entry.getColumnKey().equals(BigInteger.class)) {
                    sqlQuery.setBigInteger(entry.getRowKey(), (BigInteger) entry.getValue());
                    continue;
                }
                logger.error("Type {} not registered", entry.getValue().getClass());
            }
        }

        result = sqlQuery.list();
        transaction.commit();
    } catch (RuntimeException ex) {
        if (transaction != null) {
            logger.error("rolling back transaction {}", ex);
            transaction.rollback();
        }
    }
    return result;
}

From source file:org.mousephenotype.dcc.utils.persistence.HibernateManager.java

License:Apache License

public List nativeQuery(String query, Map<String, org.hibernate.type.Type> scalars,
        com.google.common.collect.Table<String, Class, Object> parameters) {

    this.refreshSession();
    Transaction transaction = null;/*  w w  w.  j av a2  s .c  om*/
    List result = null;
    try {
        transaction = session.beginTransaction();
        SQLQuery sqlQuery = session.createSQLQuery(query);
        if (scalars != null) {
            for (Map.Entry<String, org.hibernate.type.Type> entry : scalars.entrySet()) {
                sqlQuery.addScalar(entry.getKey(), entry.getValue());
            }
        }
        if (parameters != null) {
            for (com.google.common.collect.Table.Cell<String, Class, Object> entry : parameters.cellSet()) {
                if (entry.getColumnKey().equals(String.class)) {
                    sqlQuery.setString(entry.getRowKey(), (String) entry.getValue());
                    continue;
                }
                if (entry.getColumnKey().equals(Long.class)) {
                    sqlQuery.setLong(entry.getRowKey(), (Long) entry.getValue());
                    continue;
                }
                if (entry.getColumnKey().equals(BigInteger.class)) {
                    sqlQuery.setBigInteger(entry.getRowKey(), (BigInteger) entry.getValue());
                    continue;
                }
                logger.error("Type {} not registered", entry.getValue().getClass());
            }
        }

        result = sqlQuery.list();
        transaction.commit();
    } catch (RuntimeException ex) {
        if (transaction != null) {
            logger.error("rolling back transaction {}", ex);
            transaction.rollback();
        }
    }
    return result;
}