List of usage examples for org.hibernate Query setTimestamp
@Deprecated @SuppressWarnings("unchecked") default Query<R> setTimestamp(String name, Date value)
From source file:org.xwiki.store.filesystem.internal.migration.R910100XWIKI14871DataMigration.java
License:Open Source License
private void storeDeletedAttachment(File directory, long id, Session session) throws ParserConfigurationException, SAXException, IOException { this.logger.info("Storing attachment metadata [{}] in the database", directory); // Find document reference File documentDirectory = directory.getParentFile().getParentFile().getParentFile(); DocumentReference documentReference = getDocumentReference(documentDirectory); if (getXWikiContext().getWikiReference().equals(documentReference.getWikiReference())) { // Parse ~DELETED_ATTACH_METADATA.xml File file = new File(directory, "~DELETED_ATTACH_METADATA.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(file); String filename = getElementText(doc, "filename", null); String deleter = getElementText(doc, "deleter", null); Date deleteDate = new Date(Long.valueOf(getElementText(doc, "datedeleted", null))); long docId = new XWikiDocument(documentReference).getId(); // We need to make sure the deleted attachment is not already in the database with a different id (left // there by the attachment porter script for example) Query selectQuery = session .createQuery("SELECT id FROM DeletedAttachment WHERE docId=? AND filename=? AND date=?"); selectQuery.setLong(0, docId);//from ww w. j ava2 s. c om selectQuery.setString(1, filename); selectQuery.setTimestamp(2, new java.sql.Timestamp(deleteDate.getTime())); Long databaseId = (Long) selectQuery.uniqueResult(); if (databaseId == null) { // Try without the milliseconds since most versions of MySQL don't support them selectQuery.setTimestamp(2, new java.sql.Timestamp(deleteDate.toInstant().getEpochSecond() * 1000)); databaseId = (Long) selectQuery.uniqueResult(); } DeletedAttachment dbAttachment; if (databaseId != null) { // Update the database metadata (probably left there by the attachment porter script) dbAttachment = new DeletedAttachment(docId, this.serializer.serialize(documentReference), filename, FileSystemStoreUtils.HINT, deleter, deleteDate, null, databaseId); session.update(dbAttachment); } else { // Insert new deleted attachment metadata in the DB dbAttachment = new DeletedAttachment(docId, this.serializer.serialize(documentReference), filename, FileSystemStoreUtils.HINT, deleter, deleteDate, null); databaseId = (Long) session.save(dbAttachment); } // Refactor file storage to be based on database id instead of date File newDirectory = new File(directory.getParentFile(), encode(dbAttachment.getFilename() + "-id" + databaseId)); FileUtils.moveDirectory(directory, newDirectory); } }
From source file:org.zanata.dao.ActivityDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public Activity findActivity(long personId, EntityType contextType, long contextId, ActivityType activityType, Date approxTime) {/*from w ww . j a v a 2 s . c o m*/ Query query = getSession().createQuery("FROM Activity a WHERE a.actor.id = :personId " + "AND a.contextId = :contextId " + "AND a.activityType = :activityType " + "AND a.contextType = :contextType " + "AND :approxTime = a.approxTime"); query.setParameter("personId", personId); query.setParameter("contextId", contextId); query.setParameter("activityType", activityType); query.setParameter("contextType", contextType); query.setTimestamp("approxTime", approxTime); query.setCacheable(true); query.setComment("activityDAO.findActivity"); return (Activity) query.uniqueResult(); }
From source file:org.zanata.dao.ProjectIterationDAO.java
License:Open Source License
public List<HAccount> getContributors(String projectSlug, String versionSlug, DateRange dataRange) { String query = "select account from HAccount account where account.id in " + "(select tft.translator.account.id from HTextFlowTarget tft " + "where tft.textFlow.document.projectIteration.slug = :versionSlug " + "and tft.textFlow.document.projectIteration.project.slug =:projectSlug and tft.lastChanged between :fromDate and :toDate) " + "or account.id in (select tft.reviewer.account.id from HTextFlowTarget tft " + "where tft.textFlow.document.projectIteration.slug = :versionSlug " + "and tft.textFlow.document.projectIteration.project.slug =:projectSlug and tft.lastChanged between :fromDate and :toDate) " + "or account.id in (select tfth.translator.account.id from HTextFlowTargetHistory tfth " + "where tfth.textFlowTarget.textFlow.document.projectIteration.slug = :versionSlug " + "and tfth.textFlowTarget.textFlow.document.projectIteration.project.slug =:projectSlug and tfth.lastChanged between :fromDate and :toDate) " + "or account.id in (select tfth.reviewer.account.id from HTextFlowTargetHistory tfth " + "where tfth.textFlowTarget.textFlow.document.projectIteration.slug = :versionSlug " + "and tfth.textFlowTarget.textFlow.document.projectIteration.project.slug =:projectSlug and tfth.lastChanged between :fromDate and :toDate) group by account.username "; Query q = getSession().createQuery(query); q.setParameter("versionSlug", versionSlug); q.setParameter("projectSlug", projectSlug); q.setTimestamp("fromDate", dataRange.getFromDate().toDate()); q.setTimestamp("toDate", dataRange.getToDate().toDate()); q.setCacheable(true).setComment("ProjectIterationDAO.getContributors"); return q.list(); }
From source file:org.zanata.dao.TextFlowTargetHistoryDAO.java
License:Open Source License
private Query buildContributionStatisticQuery(boolean translations, Long versionId, Long personId, Date fromDate, Date toDate, boolean automatedEntry) { String lastModifiedColumn = translations ? "translated_by_id" : "reviewed_by_id"; StringBuilder queryString = new StringBuilder(); queryString.append("select sum(wordCount), state, localeId from ") .append("(select wordCount, id, state, localeId from ").append("(select h.state, tft.id, h.") .append(lastModifiedColumn).append(", tf.wordCount, locale.localeId ") .append("from HTextFlowTargetHistory h ") .append("JOIN HTextFlowTarget tft ON tft.id = h.target_id ") .append("JOIN HLocale locale ON locale.id = tft.locale ") .append("JOIN HTextFlow tf ON tf.id = tft.tf_id ") .append("JOIN HDocument doc ON doc.id = tf.document_Id ") .append("where doc.project_iteration_id =:versionId ").append("and h.state in (:states) ") .append("and h.").append(lastModifiedColumn).append(" =:personId ") .append("and h.lastChanged between :fromDate and :toDate ") .append("and h.automatedEntry =:automatedEntry ").append("and tft.").append(lastModifiedColumn) .append(" <> h.").append(lastModifiedColumn).append(" ").append("and h.lastChanged = ") .append("(select max(lastChanged) from HTextFlowTargetHistory where h.target_id = target_id) ") .append("union all ").append("select tft.state, tft.id, tft.").append(lastModifiedColumn) .append(", tf.wordCount, locale.localeId ").append("from HTextFlowTarget tft ") .append("JOIN HLocale locale ON locale.id = tft.locale ") .append("JOIN HTextFlow tf ON tf.id = tft.tf_id ") .append("JOIN HDocument doc ON doc.id = tf.document_Id ") .append("where doc.project_iteration_id =:versionId ").append("and tft.state in (:states) ") .append("and tft.automatedEntry =:automatedEntry ").append("and tft.").append(lastModifiedColumn) .append(" =:personId ").append("and tft.lastChanged between :fromDate and :toDate ") .append(") as target_history_union ") .append("group by state, id, localeId, wordCount) as target_history_group ") .append("group by state, localeId"); Query query = getSession().createSQLQuery(queryString.toString()); query.setParameter("versionId", versionId); query.setParameter("personId", personId); if (translations) { query.setParameterList("states", getContentStateOrdinal(ContentState.TRANSLATED_STATES, ContentState.DRAFT_STATES)); } else {/*from ww w. j a v a2 s . co m*/ query.setParameterList("states", getContentStateOrdinal(ContentState.REVIEWED_STATES)); } query.setBoolean("automatedEntry", automatedEntry); query.setTimestamp("fromDate", fromDate); query.setTimestamp("toDate", toDate); return query; }
From source file:ru.codemine.ccms.dao.TaskDAOImpl.java
License:Open Source License
@Override public List<Task> gedOverdue() { Query query = getSession().createQuery("FROM Task t WHERE t.deadline < :now AND t.status != :statusClosed"); query.setTimestamp("now", DateTime.now().toDate()); query.setParameter("statusClosed", Task.Status.CLOSED); return query.list(); }
From source file:ru.codemine.ccms.dao.TaskDAOImpl.java
License:Open Source License
@Override public List<Task> getOverdueByCreator(Employee creator) { Query query = getSession().createQuery( "FROM Task t WHERE t.deadline < :now AND t.creator.id = :id AND t.status != :statusClosed"); query.setTimestamp("now", DateTime.now().toDate()); query.setInteger("id", creator.getId()); query.setParameter("statusClosed", Task.Status.CLOSED); return query.list(); }
From source file:ru.codemine.ccms.dao.TaskDAOImpl.java
License:Open Source License
@Override public List<Task> getOverdueByPerformer(Employee performer) { Query query = getSession().createQuery( "FROM Task t WHERE t.deadline < :now AND :performer IN ELEMENTS(t.performers) AND t.status != :statusClosed"); query.setTimestamp("now", DateTime.now().toDate()); query.setParameter("performer", performer); query.setParameter("statusClosed", Task.Status.CLOSED); return query.list(); }
From source file:sos.ftphistory.db.JadeFilesDBLayer.java
License:Apache License
private void setWhere(Query query) { if (filter.getCreatedFrom() != null && !filter.getCreatedFrom().equals("")) { query.setTimestamp("createdFrom", filter.getCreatedFrom()); }//from w w w . java 2 s.co m if (filter.getCreatedTo() != null && !filter.getCreatedTo().equals("")) { query.setTimestamp("createdTo", filter.getCreatedTo()); } if (filter.getSourceDir() != null && !filter.getSourceDir().equals("")) { query.setText("sourceDir", filter.getSourceDir()); } if (filter.getSourceFilename() != null && !filter.getSourceFilename().equals("")) { query.setText("sourceFilename", filter.getSourceFilename()); } if (filter.getSourceHost() != null && !filter.getSourceHost().equals("")) { query.setText("sourceHost", filter.getSourceHost()); } if (filter.getSourceHostIp() != null && !filter.getSourceHostIp().equals("")) { query.setText("sourceHostIp", filter.getSourceHostIp()); } if (filter.getSourceUser() != null && !filter.getSourceUser().equals("")) { query.setText("sourceUser", filter.getSourceUser()); } }
From source file:sos.ftphistory.db.JadeHistorySelector.java
License:Apache License
public List<JadeFilesDBItem> getFilesFromTo() throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy hh:mm"); createdFrom = formatter.parse("07.09.2011 00:00"); createdTo = formatter.parse("07.09.2011 00:00"); Session session = getSession();//from w w w . j av a 2 s.c o m Transaction transaction = session.beginTransaction(); Query query = session .createQuery(" from JadeFilesDBItem where created >= :createdFrom and created <= :createdTo"); query.setTimestamp("createdFrom", createdFrom); query.setTimestamp("createdTo", createdTo); List<JadeFilesDBItem> resultset = query.list(); transaction.commit(); return resultset; }
From source file:sos.ftphistory.db.JadeHistorySelector.java
License:Apache License
public List<JadeFilesHistoryDBItem> getFilesHistoryFromTo() throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy hh:mm"); createdFrom = formatter.parse("07.09.2011 00:00"); createdTo = formatter.parse("07.09.2011 00:00"); Session session = getSession();/*from ww w .ja va 2 s . c om*/ Transaction transaction = session.beginTransaction(); Query query = session .createQuery(" from JadeFilesDBItem where created >= :createdFrom and created <= :createdTo"); query.setTimestamp("createdFrom", createdFrom); query.setTimestamp("createdTo", createdTo); List<JadeFilesHistoryDBItem> resultset = query.list(); transaction.commit(); return resultset; }