本文整理了Java中org.hibernate.classic.Session
类的一些代码示例,展示了Session
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session
类的具体详情如下:
包路径:org.hibernate.classic.Session
类名称:Session
[英]An extension of the Session API, including all deprecated methods from Hibernate2. This interface is provided to allow easier migration of existing applications. New code should use org.hibernate.Session.
[中]会话API的扩展,包括Hibernate2中所有不推荐的方法。提供此接口是为了更方便地迁移现有应用程序。新代码应该使用org。冬眠一场
代码示例来源:origin: gocd/gocd
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
sessionFactory.getCurrentSession().save(metadata);
}
});
代码示例来源:origin: gocd/gocd
@Override
public boolean deleteUsers(List<String> userNames) {
return (Boolean) transactionTemplate.execute((TransactionCallback) status -> {
String queryString = "delete from User where name in (:userNames)";
Query query = sessionFactory.getCurrentSession().createQuery(queryString);
query.setParameterList("userNames", userNames);
query.executeUpdate();
return Boolean.TRUE;
});
}
代码示例来源:origin: gocd/gocd
@Override
public Object doInTransaction(TransactionStatus transactionStatus) {
return sessionFactory.getCurrentSession()
.createCriteria(PipelineState.class)
.add(Restrictions.eq("pipelineName", pipelineName))
.setCacheable(false).uniqueResult();
}
});
代码示例来源:origin: gocd/gocd
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
clearLockedPipelineStateCache(pipelineName);
}
});
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
for (AfterCompletionCallback callback : afterCompletionCallbacks) {
callback.execute(status);
}
}
});
final String cacheKey = pipelineLockStateCacheKey(pipelineName);
PipelineState fromCache = pipelineStateFor(pipelineName);
PipelineState toBeSaved = null;
if (fromCache == null) {
toBeSaved = new PipelineState(pipelineName);
} else {
toBeSaved = (PipelineState) sessionFactory.getCurrentSession().load(PipelineState.class, fromCache.getId());
}
toBeSaved.unlock();
sessionFactory.getCurrentSession().saveOrUpdate(toBeSaved);
}
});
代码示例来源:origin: denimgroup/threadfix
@Override
public long getNumberWithoutChannelVulns(Integer scanId) {
return (Long) sessionFactory.getCurrentSession()
.createCriteria(Finding.class)
.add(isNull("channelVulnerability"))
.add(eq("scan.id", scanId))
.setProjection(rowCount())
.uniqueResult();
}
代码示例来源:origin: gocd/gocd
@Override
public Object doInTransaction(TransactionStatus status) {
PropertyProjection pipelineName = Projections.property("pipelineName");
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PipelineState.class).setProjection(pipelineName).add(
Restrictions.eq("locked", true));
criteria.setCacheable(false);
List<String> list = criteria.list();
return list;
}
});
代码示例来源:origin: org.motechproject.mobile/motech-mobile-omp
public int countIVRCallSessionsCreatedBetweenDates(Date start, Date end) {
return (Integer)sessionFactory
.getCurrentSession()
.createCriteria(IVRCallSession.class)
.setProjection(Projections.rowCount())
.add(Restrictions.ge("created", start))
.add(Restrictions.le("created", end))
.list()
.get(0);
}
代码示例来源:origin: gocd/gocd
public EnvironmentVariables load(final Long entityId, final EnvironmentVariableType type) {
List<EnvironmentVariable> result = (List<EnvironmentVariable>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(EnvironmentVariable.class).add(Restrictions.eq("entityId", entityId)).add(
Restrictions.eq("entityType", type.toString())).addOrder(Order.asc("id"));
criteria.setCacheable(true);
return criteria.list();
});
return new EnvironmentVariables(result);
}
代码示例来源:origin: gocd/gocd
public Users findNotificationSubscribingUsers() {
return (Users) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class);
criteria.setCacheable(true);
criteria.add(Restrictions.isNotEmpty("notificationFilters"));
criteria.add(Restrictions.eq("enabled", true));
return new Users(criteria.list());
});
}
代码示例来源:origin: org.motechproject.mobile/motech-mobile-omp
public int countIVRCallsCreatedBetweenDatesWithStatus(Date start, Date end, IVRCallStatus status) {
return (Integer)sessionFactory
.getCurrentSession()
.createCriteria(IVRCall.class)
.setProjection(Projections.rowCount())
.add(Restrictions.ge("created", start))
.add(Restrictions.le("created", end))
.add(Restrictions.eq("status", status))
.list()
.get(0);
}
代码示例来源:origin: org.motechproject.mobile/motech-mobile-omp
public int countIVRCallsWithStatus(IVRCallStatus status) {
return (Integer)sessionFactory
.getCurrentSession()
.createCriteria(IVRCall.class)
.setProjection(Projections.rowCount())
.add(Restrictions.eq("status", status))
.list()
.get(0);
}
代码示例来源:origin: denimgroup/threadfix
private void hideSeverityGlobal(int intValue) {
GenericSeverity severity = (GenericSeverity) sessionFactory.getCurrentSession()
.createCriteria(GenericSeverity.class)
.add(eq("intValue", intValue))
.uniqueResult();
sessionFactory.getCurrentSession().createQuery(
"update Vulnerability vulnerability set hidden = true where vulnerability.genericSeverity = :severity")
.setParameter("severity", severity)
.executeUpdate();
}
代码示例来源:origin: gocd/gocd
@Override
public List<Plugin> getAllPlugins() {
return (List<Plugin>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Query query = sessionFactory.getCurrentSession().createQuery("FROM " + Plugin.class.getSimpleName());
query.setCacheable(true);
return query.list();
});
}
代码示例来源:origin: denimgroup/threadfix
@Override
public void deleteMap(ScanCloseVulnerabilityMap map) {
sessionFactory.getCurrentSession().save(new DeletedCloseMap(map));
sessionFactory.getCurrentSession().delete(map);
}
代码示例来源:origin: denimgroup/threadfix
@Override
@SuppressWarnings("unchecked")
public List<Survey> retrieveAll() {
return sessionFactory.getCurrentSession()
.createQuery("from Survey survey order by survey.name").list();
}
代码示例来源:origin: com.lohika.alp/alp-reporter
/**
* Create TestClass by classname.
*
* @param className the class name
* @return the test class
*/
protected TestClass getTestClass(String className) {
Session session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
List<TestClass> list = session.createCriteria(TestClass.class)
.add(Expression.eq("name", className)).list();
tx.commit();
if (list.size() == 0)
return null;
else
return list.get(0);
} finally {
session.close();
}
}
代码示例来源:origin: gocd/gocd
public User load(final long id) {
return (User) transactionTemplate.execute((TransactionCallback) transactionStatus -> sessionFactory.getCurrentSession().get(User.class, id));
}
代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-deskmanager
@Override
public void addUserToGroup(long userId, long groupId, Role role) throws GeomajasSecurityException {
User user = (User) factory.getCurrentSession().load(User.class, userId);
Territory group = (Territory) factory.getCurrentSession().load(Territory.class, groupId);
if (user != null && group != null) {
user.addToGroupInRole(group, role);
}
}
代码示例来源:origin: gocd/gocd
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
sessionFactory.getCurrentSession().createQuery("DELETE FROM VersionInfo").executeUpdate();
}
});
代码示例来源:origin: org.motechproject/motech-server-core
public void update(Object obj) {
sessionFactory.getCurrentSession().update(obj);
}
内容来源于网络,如有侵权,请联系作者删除!