org.springframework.orm.hibernate4.HibernateTemplate Java Examples

The following examples show how to use org.springframework.orm.hibernate4.HibernateTemplate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GradebookExternalAssessmentServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * @see org.sakaiproject.service.gradebook.shared.GradebookService#removeExternalAssessment(java.lang.String, java.lang.String)
 */
@Override
public void removeExternalAssessment(final String gradebookUid,
		final String externalId) throws GradebookNotFoundException, AssessmentNotFoundException {
	// Get the external assignment
	final GradebookAssignment asn = getExternalAssignment(gradebookUid, externalId);
	if (asn == null) {
		throw new AssessmentNotFoundException("There is no external assessment id=" + externalId + " in gradebook uid=" + gradebookUid);
	}

	// We need to go through Spring's HibernateTemplate to do
	// any deletions at present. See the comments to deleteGradebook
	// for the details.
	final HibernateTemplate hibTempl = getHibernateTemplate();

	hibTempl.execute((HibernateCallback<?>) session -> {
		int numDeleted = session.createQuery("delete GradingEvent where gradableObject=:go").setParameter("go", asn).executeUpdate();
		log.debug("Deleted {} records from gb_grading_event_t", numDeleted);

		numDeleted = session.createQuery("delete AssignmentGradeRecord where gradableObject=:go").setParameter("go", asn)
				.executeUpdate();
		log.info("Deleted {} externally defined scores", numDeleted);

		numDeleted = session.createQuery("delete Comment where gradableObject=:go").setParameter("go", asn).executeUpdate();
		log.info("Deleted {} externally defined comments", numDeleted);
		return null;
	});

	// Delete the assessment.
	hibTempl.delete(asn);

	log.info("External assessment removed from gradebookUid={}, externalId={} by userUid={}", gradebookUid, externalId, getUserUid());
}
 
Example #2
Source File: GradebookExternalAssessmentServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * @see org.sakaiproject.service.gradebook.shared.GradebookService#removeExternalAssessment(java.lang.String, java.lang.String)
 */
@Override
public void removeExternalAssessment(final String gradebookUid,
		final String externalId) throws GradebookNotFoundException, AssessmentNotFoundException {
	// Get the external assignment
	final GradebookAssignment asn = getExternalAssignment(gradebookUid, externalId);
	if (asn == null) {
		throw new AssessmentNotFoundException("There is no external assessment id=" + externalId + " in gradebook uid=" + gradebookUid);
	}

	// We need to go through Spring's HibernateTemplate to do
	// any deletions at present. See the comments to deleteGradebook
	// for the details.
	final HibernateTemplate hibTempl = getHibernateTemplate();

	hibTempl.execute((HibernateCallback<?>) session -> {
		int numDeleted = session.createQuery("delete GradingEvent where gradableObject=:go").setParameter("go", asn).executeUpdate();
		log.debug("Deleted {} records from gb_grading_event_t", numDeleted);

		numDeleted = session.createQuery("delete AssignmentGradeRecord where gradableObject=:go").setParameter("go", asn)
				.executeUpdate();
		log.info("Deleted {} externally defined scores", numDeleted);

		numDeleted = session.createQuery("delete Comment where gradableObject=:go").setParameter("go", asn).executeUpdate();
		log.info("Deleted {} externally defined comments", numDeleted);
		return null;
	});

	// Delete the assessment.
	hibTempl.delete(asn);

	log.info("External assessment removed from gradebookUid={}, externalId={} by userUid={}", gradebookUid, externalId, getUserUid());
}
 
Example #3
Source File: GradebookFrameworkServiceImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public void deleteGradebook(final String uid) throws GradebookNotFoundException {
       if (log.isDebugEnabled()) {
		log.debug("Deleting gradebook uid={} by userUid={}", uid, getUserUid());
	}
       final Long gradebookId = getGradebook(uid).getId();

       // Worse of both worlds code ahead. We've been quick-marched
       // into Hibernate 3 sessions, but we're also having to use classic query
       // parsing -- which keeps us from being able to use either Hibernate's new-style
       // bulk delete queries or Hibernate's old-style session.delete method.
       // Instead, we're stuck with going through the Spring template for each
       // deletion one at a time.
       final HibernateTemplate hibTempl = getHibernateTemplate();
       // int numberDeleted = hibTempl.bulkUpdate("delete GradingEvent as ge where ge.gradableObject.gradebook.id=?", gradebookId);
       // log.warn("GradingEvent numberDeleted=" + numberDeleted);

       List toBeDeleted;
       int numberDeleted;

       toBeDeleted = hibTempl.findByNamedParam("from GradingEvent as ge where ge.gradableObject.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       if (log.isDebugEnabled()) {
		log.debug("Deleted {} grading events", numberDeleted);
	}

       toBeDeleted = hibTempl.findByNamedParam("from AbstractGradeRecord as gr where gr.gradableObject.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       if (log.isDebugEnabled()) {
		log.debug("Deleted {} grade records", numberDeleted);
	}

       toBeDeleted = hibTempl.findByNamedParam("from GradableObject as go where go.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       log.debug("Deleted {} gradable objects", numberDeleted);

       toBeDeleted = hibTempl.findByNamedParam("from Category as cg where cg.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       log.debug("Deleted {} gradable categories", numberDeleted);

       final Gradebook gradebook = hibTempl.load(Gradebook.class, gradebookId);
       gradebook.setSelectedGradeMapping(null);

       toBeDeleted = hibTempl.findByNamedParam("from GradeMapping as gm where gm.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       if (log.isDebugEnabled()) {
		log.debug("Deleted {} grade mappings", numberDeleted);
	}

       hibTempl.delete(gradebook);
       hibTempl.flush();
       hibTempl.clear();
}
 
Example #4
Source File: GenericRepositoryImpl.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
public HibernateTemplate getHibernateTemplate() {
	return hibernateTemplate;
}
 
Example #5
Source File: GreetingServiceConfig.java    From blog with Apache License 2.0 4 votes vote down vote up
@Bean
public HibernateTemplate createHibernateTemplate(
		SessionFactory sessionFactory) {
	return new HibernateTemplate(sessionFactory);
}
 
Example #6
Source File: GreetingServiceConfig.java    From blog with Apache License 2.0 4 votes vote down vote up
@Bean
public HibernateTemplate createHibernateTemplate(
		SessionFactory sessionFactory) {
	return new HibernateTemplate(sessionFactory);
}
 
Example #7
Source File: GradebookFrameworkServiceImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public void deleteGradebook(final String uid) throws GradebookNotFoundException {
       if (log.isDebugEnabled()) {
		log.debug("Deleting gradebook uid={} by userUid={}", uid, getUserUid());
	}
       final Long gradebookId = getGradebook(uid).getId();

       // Worse of both worlds code ahead. We've been quick-marched
       // into Hibernate 3 sessions, but we're also having to use classic query
       // parsing -- which keeps us from being able to use either Hibernate's new-style
       // bulk delete queries or Hibernate's old-style session.delete method.
       // Instead, we're stuck with going through the Spring template for each
       // deletion one at a time.
       final HibernateTemplate hibTempl = getHibernateTemplate();
       // int numberDeleted = hibTempl.bulkUpdate("delete GradingEvent as ge where ge.gradableObject.gradebook.id=?", gradebookId);
       // log.warn("GradingEvent numberDeleted=" + numberDeleted);

       List toBeDeleted;
       int numberDeleted;

       toBeDeleted = hibTempl.findByNamedParam("from GradingEvent as ge where ge.gradableObject.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       if (log.isDebugEnabled()) {
		log.debug("Deleted {} grading events", numberDeleted);
	}

       toBeDeleted = hibTempl.findByNamedParam("from AbstractGradeRecord as gr where gr.gradableObject.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       if (log.isDebugEnabled()) {
		log.debug("Deleted {} grade records", numberDeleted);
	}

       toBeDeleted = hibTempl.findByNamedParam("from GradableObject as go where go.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       log.debug("Deleted {} gradable objects", numberDeleted);

       toBeDeleted = hibTempl.findByNamedParam("from Category as cg where cg.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       log.debug("Deleted {} gradable categories", numberDeleted);

       final Gradebook gradebook = hibTempl.load(Gradebook.class, gradebookId);
       gradebook.setSelectedGradeMapping(null);

       toBeDeleted = hibTempl.findByNamedParam("from GradeMapping as gm where gm.gradebook.id = :gradebookid", "gradebookid", gradebookId);
       numberDeleted = toBeDeleted.size();
       hibTempl.deleteAll(toBeDeleted);
       if (log.isDebugEnabled()) {
		log.debug("Deleted {} grade mappings", numberDeleted);
	}

       hibTempl.delete(gradebook);
       hibTempl.flush();
       hibTempl.clear();
}
 
Example #8
Source File: SimplePageToolDaoImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public HibernateTemplate getDaoHibernateTemplate() {
return getHibernateTemplate();
   }
 
Example #9
Source File: SimplePageToolDaoImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public HibernateTemplate getDaoHibernateTemplate() {
return getHibernateTemplate();
   }
 
Example #10
Source File: HibernateDaoSupport.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a HibernateTemplate for the given SessionFactory.
 * Only invoked if populating the DAO with a SessionFactory reference!
 * <p>Can be overridden in subclasses to provide a HibernateTemplate instance
 * with different configuration, or a custom HibernateTemplate subclass.
 * @param sessionFactory the Hibernate SessionFactory to create a HibernateTemplate for
 * @return the new HibernateTemplate instance
 * @see #setSessionFactory
 */
protected HibernateTemplate createHibernateTemplate(SessionFactory sessionFactory) {
	return new HibernateTemplate(sessionFactory);
}
 
Example #11
Source File: HibernateDaoSupport.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Return the HibernateTemplate for this DAO,
 * pre-initialized with the SessionFactory or set explicitly.
 * <p><b>Note: The returned HibernateTemplate is a shared instance.</b>
 * You may introspect its configuration, but not modify the configuration
 * (other than from within an {@link #initDao} implementation).
 * Consider creating a custom HibernateTemplate instance via
 * {@code new HibernateTemplate(getSessionFactory())}, in which case
 * you're allowed to customize the settings on the resulting instance.
 */
public final HibernateTemplate getHibernateTemplate() {
  return this.hibernateTemplate;
}
 
Example #12
Source File: HibernateDaoSupport.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Set the HibernateTemplate for this DAO explicitly,
 * as an alternative to specifying a SessionFactory.
 * @see #setSessionFactory
 */
public final void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
	this.hibernateTemplate = hibernateTemplate;
}
 
Example #13
Source File: HibernateDaoSupport.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create a HibernateTemplate for the given SessionFactory.
 * Only invoked if populating the DAO with a SessionFactory reference!
 * <p>Can be overridden in subclasses to provide a HibernateTemplate instance
 * with different configuration, or a custom HibernateTemplate subclass.
 * @param sessionFactory the Hibernate SessionFactory to create a HibernateTemplate for
 * @return the new HibernateTemplate instance
 * @see #setSessionFactory
 */
protected HibernateTemplate createHibernateTemplate(SessionFactory sessionFactory) {
	return new HibernateTemplate(sessionFactory);
}
 
Example #14
Source File: HibernateDaoSupport.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the HibernateTemplate for this DAO,
 * pre-initialized with the SessionFactory or set explicitly.
 * <p><b>Note: The returned HibernateTemplate is a shared instance.</b>
 * You may introspect its configuration, but not modify the configuration
 * (other than from within an {@link #initDao} implementation).
 * Consider creating a custom HibernateTemplate instance via
 * {@code new HibernateTemplate(getSessionFactory())}, in which case
 * you're allowed to customize the settings on the resulting instance.
 */
public final HibernateTemplate getHibernateTemplate() {
  return this.hibernateTemplate;
}
 
Example #15
Source File: HibernateDaoSupport.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the HibernateTemplate for this DAO explicitly,
 * as an alternative to specifying a SessionFactory.
 * @see #setSessionFactory
 */
public final void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
	this.hibernateTemplate = hibernateTemplate;
}
 
Example #16
Source File: SimplePageToolDao.java    From sakai with Educational Community License v2.0 votes vote down vote up
public HibernateTemplate getDaoHibernateTemplate(); 
Example #17
Source File: SimplePageToolDao.java    From sakai with Educational Community License v2.0 votes vote down vote up
public HibernateTemplate getDaoHibernateTemplate();