List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:de.decidr.model.commands.workflowmodel.DeployWorkflowModelCommand.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from www . ja va 2 s. c o m public void transactionAllowed(TransactionStartedEvent evt) throws TransactionException { DeploymentResult result = null; /* * Find the existing deployed workflow model. */ WorkflowModel workflowModel = fetchWorkflowModel(evt.getSession()); Query q = evt.getSession().createQuery("from DeployedWorkflowModel where (version = :version)" + "and (originalWorkflowModel = :original)"); q.setLong("version", workflowModel.getVersion()); q.setEntity("original", workflowModel); q.setMaxResults(1); DeployedWorkflowModel existing = (DeployedWorkflowModel) q.uniqueResult(); if (existing == null) { /* * There is no current deployed version of our workflow model, so we * have to deploy it now. */ Deployer deployer = new Deployer(); // Fill deployedWorkflowModel with data DeployedWorkflowModel dwfm = new DeployedWorkflowModel(); dwfm.setOriginalWorkflowModel(workflowModel); dwfm.setTenant(workflowModel.getTenant()); dwfm.setName(workflowModel.getName()); dwfm.setDescription(workflowModel.getDescription()); dwfm.setDwdl(new byte[0]); dwfm.setVersion(workflowModel.getVersion()); // XXX remove deprecated wsdl and soap template from database schema // ~dh dwfm.setWsdl(new byte[0]); dwfm.setSoapTemplate(new byte[0]); dwfm.setDeployDate(DecidrGlobals.getTime().getTime()); evt.getSession().save(dwfm); // Update DWDL TWorkflow dwdl = XmlTools.unmarshalJaxbEntity(workflowModel.getDwdl(), TWorkflow.class); dwdl.setId(workflowModel.getId()); dwdl.setTargetNamespace(StringConventions.getWorkflowTargetNamespace(workflowModel.getId())); dwfm.setDwdl(XmlTools.marshalJaxbEntityIntoByteArray(new ObjectFactory().createWorkflow(dwdl))); /* * Get some potential deployment targets (servers) */ String hqlString = "from ServerLoadView where serverType = :type)"; Query q2 = evt.getSession().createQuery(hqlString).setString("type", ServerTypeEnum.Ode.toString()); List<ServerLoadView> serverStatistics = q2.list(); // deploy it try { result = deployer.deploy(dwdl, workflowModel.getTenant().getName(), serverStatistics, new StandardDeploymentStrategy()); // get servers on which it has been deployed List<Long> serverIds = result.getServers(); Set<WorkflowModelIsDeployedOnServer> isDeployedRelations = new HashSet<WorkflowModelIsDeployedOnServer>(); for (Long sid : serverIds) { WorkflowModelIsDeployedOnServer entry = new WorkflowModelIsDeployedOnServer(); entry.setDeployedWorkflowModel(dwfm); entry.setServer((Server) evt.getSession().get(Server.class, sid)); entry.setId(new WorkflowModelIsDeployedOnServerId(dwfm.getId(), sid)); evt.getSession().save(entry); isDeployedRelations.add(entry); } dwfm.setDeployDate(DecidrGlobals.getTime().getTime()); dwfm.setSoapTemplate(new byte[0]); dwfm.setWorkflowModelIsDeployedOnServers(isDeployedRelations); } catch (Exception e) { throw new TransactionException(e); } // write changes to DB evt.getSession().update(dwfm); } }
From source file:de.decidr.model.commands.workflowmodel.GetWorkflowAdministratorsCommand.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*from w w w. j a v a 2 s. c om*/ public void transactionAllowed(TransactionStartedEvent evt) throws TransactionException { workflowAdmins = new ArrayList<User>(); WorkflowModel model = fetchWorkflowModel(evt.getSession()); Query q = evt.getSession().createQuery("select rel.user from UserAdministratesWorkflowModel rel " + "join fetch rel.user.userProfile " + "where rel.workflowModel = :model"); q.setEntity("model", model); workflowAdmins.addAll(q.list()); for (User admin : workflowAdmins) { // Make sure that Hibernate loads the profile if the user has one. admin.getUserProfile(); } }
From source file:de.evjnw.jlk.work.impl.BenutzerDaoImpl.java
License:Apache License
/** * @see de.evjnw.jlk.work.dao.BenutzerDao#liste() *///from w ww. j a v a 2 s.c o m @SuppressWarnings("unchecked") public List<Favoriten> listeFavoriten(Benutzer benutzer) { Session session = factory.getCurrentSession(); Query q = session.createQuery("FROM Favoriten f where f.benutzer = :b"); q.setEntity("b", benutzer); return q.list(); }
From source file:de.evjnw.jlk.work.impl.SucheDaoImpl.java
License:Apache License
@SuppressWarnings("unchecked") public List<Suche> liste(Benutzer b) { Session session = factory.getCurrentSession(); Query q = session.createQuery("from Suche where Benutzer= :b)"); q.setEntity("b", b); return q.list(); }
From source file:de.innovationgate.webgate.api.jdbc.filehandling.CS41FileAttachmentHandler.java
License:Open Source License
protected void deleteFileData(EntityContainingFiles filesEntity, FileAttachmentEntity meta) throws WGAPIException { if (_handling.getParent().isSaveIsolationActive() == true && (meta == null || meta.getId() == null)) { return;//w w w .jav a2 s . c om } Query query = _handling.getParent().getSession().createQuery( "delete " + _entityDescriptor.getHQLFileDataEntity(meta) + " cfp where cfp.meta = :meta"); query.setEntity("meta", meta); query.executeUpdate(); }
From source file:de.innovationgate.webgate.api.jdbc.WGDatabaseImpl.java
License:Open Source License
private Long upgradeFileStorage(Logger log) throws WGAPIException { _ugradeFileStorageRunning = true;//from w w w . jav a 2s.com try { if (_csVersion.getVersion() < 5.0 || _csVersion.getPatchLevel() < 4) { log.error("This task needs a content store of version 5.0 patch level 4 or higher"); return 0L; } CS5P4FileHandling fileHandling = ((CS5P4FileHandling) _fileHandling); long freedMemory = 0; while (true) { String metaHql = "from ContentFileMeta as meta where meta.checksumSha512 is null"; Iterator oldMetas = getSession().createQuery(metaHql).iterate(); try { int counter = 0; if (!oldMetas.hasNext()) { break; } while (oldMetas.hasNext() && counter < 100) { ContentFileMeta meta = (ContentFileMeta) oldMetas.next(); getSession().setReadOnly(meta, false); LockRequest lockRequest = getSession() .buildLockRequest(new LockOptions(LockMode.PESSIMISTIC_WRITE)); lockRequest.lock(meta); try { // Just-for-sure check if this is really not yet migrated getSession().refresh(meta); if (meta.getChecksumSha512() != null) { rollbackHibernateTransaction(false); continue; } log.info("Database: " + getDb().getDbReference() + ": Upgrading storage of file '" + meta.getName() + "' from document '" + meta.getParentcontent().getTitle() + "' (" + meta.getParentcontent().getStructentry().getKey() + "." + meta.getParentcontent().getLanguage().getName() + "." + meta.getParentcontent().getVersion() + ")"); // Select file parts String hqlQuery = "select cfp from ContentFilePart as cfp where cfp.meta=:metaEntity order by cfp.partnr asc"; Query query = getSession().createQuery(hqlQuery); query.setParameter("metaEntity", meta); // Migrate file parts to filecontents parts InputStream in = new HibernateQueryInputStream(fileHandling.getParent().getSession(), query, 0, isOptimizedFileHandlingDisableQueryPaging()); try { fileHandling.storeFileContents(meta, new CS5P4ContentFileDescriptor(), in); } finally { in.close(); } // Delete file parts Query deletionQuery = getSession() .createQuery("delete ContentFilePart cfp where cfp.meta = :meta"); deletionQuery.setEntity("meta", meta); deletionQuery.executeUpdate(); // Commit so we can read the file afterwards commitHibernateTransaction(); /* // Annotate the file WGDocumentImpl doc = createDocumentImpl(meta.getParentcontent()); TemporaryFile tempFile = new TemporaryFile(meta.getName(), doc.getFileData(meta.getName()), WGFactory.getTempDir()); try { WGFileMetaData md = new WGFileMetaData(new WGDocument.FakeMetaDataContext(), meta.getName(), meta.getSize(), meta.getCreated(), meta.getLastmodified(), meta.getChecksum(), meta.getChecksumSha512(), fileHandling.loadMdExtensionData(doc, meta)); _db.annotateMetadata(tempFile.getFile(), md, null); fileHandling.storeMdExtensionData(doc, md, meta); if (isSaveIsolationActive()) { getSession().update(meta); // This will not be able to store binary extension data, which however cannot be present before upgrading the file storage } } finally { tempFile.delete(); } commitHibernateTransaction(); */ } catch (Throwable e) { log.error("Exception upgrading file", e); rollbackHibernateTransaction(false); } counter++; } log.info("Clearing session cache"); refresh(); log.info("Running file storage maintenance to remove duplicate file data"); freedMemory += dailyMaintenance(log); } finally { Hibernate.close(oldMetas); } } log.info("Database: " + getDb().getDbReference() + ": Upgrading file storage freed " + WGUtils.DECIMALFORMAT_STANDARD.format(freedMemory / 1024 / 1024) + " MB of file storage memory."); return freedMemory; } finally { _ugradeFileStorageRunning = false; } }
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.LectureDAO.java
License:Open Source License
@Override public int getSumOfPoints(Lecture lecture) { Session session = getSession();// w ww .j a v a 2 s . co m Query query = session.createQuery( "select sum(submission.points.points) from Submission submission inner join submission.task as task inner join task.taskGroup as taskgroup inner join taskgroup.lecture as lecture where lecture.id=:LECTURE and submission.points.pointStatus=" + PointStatus.ABGENOMMEN.ordinal()); query.setEntity("LECTURE", lecture); Object result = query.uniqueResult(); if (result == null) { return 0; } else { return ((Long) result).intValue(); } }
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.LectureDAO.java
License:Open Source License
@Override public int getStudentsCount(Lecture lecture) { Session session = getSession();/*from w w w . j a v a 2 s. co m*/ Query query = session.createQuery( "select count(*) from Participation participation inner join participation.lecture as lecture where lecture.id=:LECTURE and participation.role='NORMAL'"); query.setEntity("LECTURE", lecture); Object result = query.uniqueResult(); if (result == null) { return 0; } else { return ((Long) result).intValue(); } }
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.SimilarityDAO.java
License:Open Source License
@Override public int getMaxSimilarity(SimilarityTest similarityTest, Submission submission) { Session session = getSession();/*from w w w . j a v a 2 s . c om*/ Query query = session.createQuery( "select max(similarity.percentage) from Similarity similarity inner join similarity.similarityTest as similaritytest where similarity.submissionOne=:SUBMISSION and similaritytest.similarityTestId=:SIMID group by similarity.submissionOne"); query.setEntity("SIMID", similarityTest); query.setEntity("SUBMISSION", submission); Object result = query.uniqueResult(); if (result == null) { return 0; } else { return (Integer) result; } }
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.SimilarityTestDAO.java
License:Open Source License
@Override public void resetSimilarityTest(SimilarityTest similarityTest) { Session session = getSession();/* ww w . j a v a 2 s.c o m*/ Transaction tx = session.beginTransaction(); Query query = session .createQuery("delete from Similarity similarity where similarity.similarityTest=:SIMTEST"); query.setEntity("SIMTEST", similarityTest); query.executeUpdate(); tx.commit(); }