List of usage examples for org.hibernate SQLQuery addScalar
SQLQuery<T> addScalar(String columnAlias, Type type);
From source file:org.jcvi.ometa.hibernate.dao.ProjectDAO.java
License:Open Source License
/** Return a list of all projects. */ public List<String> getSecuredProjectNames(Session session) throws DAOException { List<String> returnVal = new ArrayList<String>(); try {//from w ww. jav a 2 s . co m SQLQuery query = session.createSQLQuery(SECURED_PROJECTS_SQL_QUERY); query.addScalar(RTN_PROJECT_NAME, Hibernate.STRING); returnVal.addAll(query.list()); } catch (Exception ex) { throw new DAOException(ex); } return returnVal; }
From source file:org.jcvi.ometa.hibernate.dao.SecurityDAO.java
License:Open Source License
/** * Common code for both project and sample, to get data by list-of-identifiers. * @throws Exception if anything requested is left out, iff failureResponse == throw ex. *///from www. j a va2 s . c om private List<Long> getListOfAuthorizedById(List<Long> ids, String username, ResponseToFailedAuthorization failureResponse, AccessLevel accessLevel, Session session, String securedIdsQuery, String openAndSecuredIdsQuery, String securedParamListName, String openParamListName, String returnVarName) throws Exception { ids = uniquifyIds(ids); String queryStr = null; if (accessLevel == AccessLevel.View) { queryStr = openAndSecuredIdsQuery.replace(PROJ_GRP_SUBST_STR, VIEW_PROJECT_GROUP_FIELD); } else { queryStr = securedIdsQuery.replace(PROJ_GRP_SUBST_STR, EDIT_PROJECT_GROUP_FIELD); } SQLQuery query = session.createSQLQuery(queryStr); query.addScalar(returnVarName, Hibernate.STRING); if (accessLevel == AccessLevel.View) { query.setParameterList(openParamListName, ids); } query.setParameterList(securedParamListName, ids); String queryUsername = username == null ? UNLOGGED_IN_USER : username; query.setParameter(USERNAME_PARAM, queryUsername); logger.debug(query.getQueryString()); List<Long> rtnVal = query.list(); if (failureResponse == ResponseToFailedAuthorization.ThrowException && rtnVal.size() < ids.size()) { String idStr = joinIdList(ids); String message = makeUserReadableMessage(username, idStr); logger.error(message); throw new ForbiddenResourceException(message); } return rtnVal; }
From source file:org.jcvi.ometa.hibernate.dao.SecurityDAO.java
License:Open Source License
/** * Common code for both project and sample, to get data by list-of-names. * @throws Exception if anything requested is left out, iff failureResponse == throw ex. *//*from ww w . j a v a 2s . c om*/ private List<String> getListOfAuthorizedByName(List<String> names, String username, ResponseToFailedAuthorization failureResponse, AccessLevel accessLevel, Session session, String securedQuery, String openAndSecuredQuery, String returnVarName, String securedParamListName, String openParamListName) throws Exception { // Need to avoid sending same name multiple times. names = uniquifyNames(names); String queryStr = null; if (accessLevel == AccessLevel.View) { queryStr = openAndSecuredQuery.replace(PROJ_GRP_SUBST_STR, VIEW_PROJECT_GROUP_FIELD); } else { queryStr = securedQuery.replace(PROJ_GRP_SUBST_STR, EDIT_PROJECT_GROUP_FIELD); } SQLQuery query = session.createSQLQuery(queryStr); query.addScalar(returnVarName, Hibernate.STRING); query.setParameterList(securedParamListName, names); if (accessLevel == AccessLevel.View) { query.setParameterList(openParamListName, names); } String queryUsername = username == null ? UNLOGGED_IN_USER : username; query.setParameter(USERNAME_PARAM, queryUsername); List<String> rtnVal = query.list(); if (failureResponse == ResponseToFailedAuthorization.ThrowException && rtnVal.size() < names.size()) { String nameStr = joinNameList(names); String message = makeUserReadableMessage(username, nameStr); logger.error(message); throw new ForbiddenResourceException(message); } return rtnVal; }
From source file:org.jessma.dao.hbn.HibernateFacade.java
License:Apache License
/** * /*from ww w. j a v a2s . c om*/ * ?SQLScalars? * * @param firstResult : * @param maxResults : * @param sql : SQL ? * @param scalars : ?? * @param params : ? * @return : * */ protected <T> List<T> sqlQuery2(int firstResult, int maxResults, String sql, KV<String, Type>[] scalars, Object... params) { SQLQuery sqlQuery = getSession().createSQLQuery(sql); for (int i = 0; i < params.length; i++) sqlQuery.setParameter(i, params[i]); if (scalars != null) { for (KV<String, Type> scalar : scalars) { String key = scalar.getKey(); Type value = scalar.getValue(); if (value != null) sqlQuery.addScalar(key, value); else sqlQuery.addScalar(key); } } if (firstResult > 0) sqlQuery.setFirstResult(firstResult); if (maxResults > 0) sqlQuery.setMaxResults(maxResults); return sqlQuery.list(); }
From source file:org.kimios.kernel.reporting.impl.DocumentHitsReport.java
License:Open Source License
public String getData() throws ConfigException, DataSourceException { if (order != null && order.length() == 0) { order = null;/*www . ja v a 2s .c o m*/ } try { 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); String rq = "SELECT e.dm_entity_name as DocumentName, count(*) as HitsCount, e.dm_entity_path as Position " + "FROM document d, entity_log dl, dm_entity e " + "WHERE d.id=dl.dm_entity_id " + "AND d.id=e.dm_entity_id " + "AND dl.dm_entity_type=3 " + "AND dl.action IN ( " + ActionType.READ + "," + ActionType.UPDATE + "," + ActionType.CREATE + ") " + "AND dl.log_time >= :dateFrom " + "AND dl.log_time <= :dateTo " + "GROUP BY e.dm_entity_name,e.dm_entity_path,e.dm_entity_id " + "ORDER BY " + (order == null ? "HitsCount" : order) + " " + (asc ? "ASC" : "DESC"); SQLQuery sql = FactoryInstantiator.getInstance().getDtrFactory().getSession().createSQLQuery(rq); sql.addScalar("DocumentName", StringType.INSTANCE); sql.addScalar("HitsCount", IntegerType.INSTANCE); sql.addScalar("Position", StringType.INSTANCE); sql.setDate("dateFrom", dtFrom.getTime()); sql.setDate("dateTo", dtTo.getTime()); List<Object[]> lReports = sql.list(); Report report = new Report("DocumentHits"); report.addColumn("Position"); report.addColumn("DocumentName"); report.addColumn("HitsCount"); for (Object[] r : lReports) { Vector<Cell> cells = new Vector<Cell>(); cells.add(new Cell("Position", (String) ((String) r[2]).substring(0, ((String) r[2]).lastIndexOf('/')))); cells.add(new Cell("DocumentName", (String) r[0])); cells.add(new Cell("HitsCount", (Integer) r[1])); report.addRow(new Row(cells)); } return report.toXML(); } catch (HibernateException he) { he.printStackTrace(); throw he; } }
From source file:org.kimios.kernel.reporting.impl.DocumentTransactionsReport.java
License:Open Source License
public String getData() throws ConfigException, DataSourceException { if (order != null && order.length() == 0) { order = null;/* ww w.j a v a 2 s. c o m*/ } try { String rq = "SELECT " + "e.dm_entity_name as DocumentName, " + "t.transfer_mode as TransferMode, t.username as UserName, " + "t.user_source as UserSource, t.last_activity_date as LastActivityDate, " + "e.dm_entity_path as Position, t.id as TransactionUid " + "FROM dm_entity e, document d, document_version v, data_transaction t " + "WHERE d.id=v.document_id AND v.id=t.document_version_id AND d.id=e.dm_entity_id " + "ORDER BY " + (order == null ? "LastActivityDate" : order) + " " + (asc ? "ASC" : "DESC"); SQLQuery sql = FactoryInstantiator.getInstance().getDtrFactory().getSession().createSQLQuery(rq); sql.addScalar("DocumentName", StringType.INSTANCE); sql.addScalar("TransferMode", IntegerType.INSTANCE); sql.addScalar("UserName", StringType.INSTANCE); sql.addScalar("LastActivityDate", StringType.INSTANCE); sql.addScalar("Position", StringType.INSTANCE); sql.addScalar("TransactionUid", StringType.INSTANCE); List<Object[]> lReports = sql.list(); Report report = new Report("DocumentTransactions"); report.addColumn("TransactionUid"); report.addColumn("Position"); report.addColumn("DocumentName"); report.addColumn("TransferMode"); report.addColumn("UserName"); report.addColumn("LastActivityDate"); for (Object[] r : lReports) { Vector<Cell> cells = new Vector<Cell>(); cells.add(new Cell("DocumentName", (String) r[0])); cells.add(new Cell("TransferMode", (String) ((Integer) r[1] == 1 ? "Upload" : (Integer) r[1] == 2 ? "Download" : "Unknown?"))); cells.add(new Cell("UserName", (String) r[2])); cells.add(new Cell("LastActivityDate", (String) r[3])); cells.add(new Cell("Position", (String) ((String) r[4]).substring(0, ((String) r[4]).lastIndexOf('/')))); cells.add(new Cell("TransactionUid", (Long) r[5])); report.addRow(new Row(cells)); } return report.toXML(); } catch (HibernateException he) { he.printStackTrace(); throw he; } }
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])); }// w w w. java 2 s . c om /* 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 w w w. j av a2s. c om } 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.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 . j a v a2s . 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 w w w .j a va 2 s .c om*/ }; return getHibernateTemplate().execute(action); }