本文整理了Java中org.hibernate.Query.setString
方法的一些代码示例,展示了Query.setString
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setString
方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:setString
[英]Bind a positional String-valued parameter.
[中]绑定位置字符串值参数。
代码示例来源:origin: gocd/gocd
private Agent fetchAgentByUuid(final String uuid) {
return (Agent) getHibernateTemplate().execute(session -> {
Query query = session.createQuery("from Agent where uuid = :uuid");
query.setString("uuid", uuid);
return query.uniqueResult();
});
}
}
代码示例来源:origin: gocd/gocd
Modification findModificationWithRevision(Session session, long materialId, String revision) {
Modification modification;
String key = cacheKeyForModificationWithRevision(materialId, revision);
modification = (Modification) goCache.get(key);
if (modification == null) {
synchronized (key) {
modification = (Modification) goCache.get(key);
if (modification == null) {
Query query = session.createQuery("FROM Modification WHERE materialId = ? and revision = ? ORDER BY id DESC");
query.setLong(0, materialId);
query.setString(1, revision);
modification = (Modification) query.uniqueResult();
goCache.put(key, modification);
}
}
}
return modification;
}
代码示例来源:origin: hibernate/hibernate-orm
Query q = s.createQuery("from Simple s where s.name=?");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s where s.name=:name");
q.setCacheable(true);
q.setString("name", "Simple 1");
assertTrue( q.list().size()==1 );
simple = (Simple) q.list().get(0);
q.setString("name", "Simple 2");
assertTrue( q.list().size()==0 );
assertTrue( q.list().size()==0 );
q = s.createQuery("from Simple s where s.name=:name");
q.setString("name", "Simple 2");
q.setCacheable(true);
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s where s.name=?");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==0 );
assertTrue( q.list().size()==0 );
代码示例来源:origin: openmrs/openmrs-core
log.debug("name: " + name);
Query query = sessionFactory.getCurrentSession().createQuery(hql.toString());
query.setParameter("DAEMON_USER_UUID", Daemon.getDaemonUserUuid());
for (Map.Entry<String, String> e : namesMap.entrySet()) {
query.setString(e.getKey(), e.getValue());
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test2ndLevelSubClass() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
A320b a = new A320b();
a.setJavaEmbeddedVersion( "Elephant" );
a.setNbrOfSeats( 300 );
s.persist( a );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Query q = s.createQuery( "from " + A320.class.getName() + " as a where a.javaEmbeddedVersion = :version" );
q.setString( "version", "Elephant" );
List a320s = q.list();
assertNotNull( a320s );
assertEquals( 1, a320s.size() );
tx.commit();
s.close();
}
代码示例来源:origin: org.openmobster.core/security
public Group read(String name) throws IDMException
{
Session session = null;
Transaction tx = null;
try
{
Group group = null;
session = this.hibernateManager.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
String query = "from Group where name=?";
group = (Group)session.createQuery(query).setString(0, name).setCacheable(true).uniqueResult();
tx.commit();
return group;
}
catch(Exception e)
{
log.error(this, e);
if(tx != null)
{
tx.rollback();
}
throw new IDMException(e);
}
}
代码示例来源:origin: org.ow2.bonita/bonita-core
@SuppressWarnings("unchecked")
public ActivityFullInstance<ActivityBody> getActivityRecord(
ProcessInstanceUUID instanceUUID, String activityId, String iterationId) {
Query query = getSession().getNamedQuery("findActivityInstance");
query.setCacheable(true);
query.setString("instanceUUID", instanceUUID.toString());
query.setString("activityId", activityId);
query.setString("iterationId", iterationId);
query.setMaxResults(1);
return (ActivityFullInstance<ActivityBody>) query.uniqueResult();
}
代码示例来源:origin: org.ow2.bonita/bonita-core
@SuppressWarnings("unchecked")
public Set<ActivityFullInstance<TaskInstance>> getUserTasks(String userId, TaskState taskState) {
Query query = getSession().getNamedQuery("getUserTasksWithState");
query.setCacheable(true);
query.setString("userId", userId);
query.setParameter("state", taskState, taskStateUserType);
Set<ActivityFullInstance<TaskInstance>> result = new HashSet<ActivityFullInstance<TaskInstance>>();
result.addAll(query.list());
return result;
}
代码示例来源:origin: hibernate/hibernate-orm
Query q = s.createQuery("from Simple s where s.name=?");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s where s.name=:name");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString("name", "Simple 1");
assertTrue( q.list().size()==1 );
simple = (Simple) q.list().get(0);
q.setString("name", "Simple 2");
assertTrue( q.list().size()==0 );
assertTrue( q.list().size()==0 );
q = s.createQuery("from Simple s where s.name=?");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==0 );
assertTrue( q.list().size()==0 );
代码示例来源:origin: openmrs/openmrs-core
@Override
public PersonAddress getPersonAddressByUuid(String uuid) {
return (PersonAddress) sessionFactory.getCurrentSession().createQuery("from PersonAddress p where p.uuid = :uuid")
.setString("uuid", uuid).uniqueResult();
}
代码示例来源:origin: hibernate/hibernate-orm
s = openSession();
tx = s.beginTransaction();
Query q = s.createQuery( "from Being h where h.identity = :name1 or h.identity = :name2" );
q.setString("name1", "marc");
q.setString("name2", "steve");
final List result = q.list();
assertEquals( 2, result.size() );
s.delete( result.get(0) );
代码示例来源:origin: sakaiproject/sakai
protected GradebookAssignment getAssignmentWithoutStats(final String gradebookUid, final Long assignmentId) throws HibernateException {
return (GradebookAssignment) getSessionFactory().getCurrentSession()
.createQuery("from GradebookAssignment as asn where asn.id = :assignmentid and asn.gradebook.uid = :gradebookuid and asn.removed is false")
.setLong("assignmentid", assignmentId)
.setString("gradebookuid", gradebookUid)
.uniqueResult();
}
代码示例来源:origin: org.openmobster.core/security
identity = (Identity)session.createQuery(query).setString(0, principal).setCacheable(true).uniqueResult();
代码示例来源:origin: org.ow2.bonita/bonita-core
public PackageFullDefinition getPackage(String packageId, String version) {
final Query query = getSession().getNamedQuery("getPackageFromIdAndVersion");
query.setCacheable(true);
query.setString("packageId", packageId);
query.setString("version", version);
query.setMaxResults(1);
return (PackageFullDefinition) query.uniqueResult();
}
代码示例来源:origin: org.ow2.bonita/bonita-core
@SuppressWarnings("unchecked")
public Set<PackageDependency> getPackageDependencies(String className) {
final Query query = getSession().getNamedQuery("getPackageDependencies");
query.setCacheable(true);
query.setString("className", className);
final List<PackageDependency> results = query.list();
if (results != null) {
return new HashSet<PackageDependency>(results);
}
return null;
}
代码示例来源:origin: hibernate/hibernate-orm
Query q = s.createQuery("from Simple s where s.name=?");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s where s.name=:name");
q.setCacheable(true);
q.setString("name", "Simple 1");
assertTrue( q.list().size()==1 );
simple = (Simple) q.list().get(0);
q.setString("name", "Simple 2");
assertTrue( q.list().size()==0 );
assertTrue( q.list().size()==0 );
q = s.createQuery("from Simple s where s.name=:name");
q.setString("name", "Simple 2");
q.setCacheable(true);
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s where s.name=?");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==0 );
assertTrue( q.list().size()==0 );
代码示例来源:origin: openmrs/openmrs-core
/**
* @see org.openmrs.PatientDAO#getAllergyByUuid(String)
*/
@Override
public Allergy getAllergyByUuid(String uuid) {
return (Allergy) sessionFactory.getCurrentSession().createQuery("from Allergy a where a.uuid = :uuid")
.setString("uuid", uuid).uniqueResult();
}
代码示例来源:origin: hibernate/hibernate-orm
Session s = openSession();
s.beginTransaction();
for ( Object entity : s.createQuery( "from Assignable" ).list() ) {
s.delete( entity );
for ( Object entity : s.createQuery( "from Category" ).list() ) {
s.delete( entity );
Query basicParam = s.createSQLQuery( "select {category.*} from category {category} where {category}.name = 'Best'" )
.addEntity( "category", Category.class );
List list = basicParam.list();
assertEquals(1, list.size());
unnamedParam.setString(0, "Good");
unnamedParam.setString(1, "Best");
list = unnamedParam.list();
assertEquals(2, list.size());
namedParam.setString("firstCat", "Better");
namedParam.setString("secondCat", "Best");
list = namedParam.list();
assertEquals(2, list.size());
s.getTransaction().commit();
代码示例来源:origin: sakaiproject/sakai
private Comment getInternalComment(final String gradebookUid, final Long assignmentId, final String studentUid) {
return (Comment) getHibernateTemplate().execute(session -> session
.createQuery("from Comment as c where c.studentId = :studentId and c.gradableObject.gradebook.uid = :gradebookUid and c.gradableObject.id = :assignmentId and gradableObject.removed is false")
.setString("studentId", studentUid)
.setString("gradebookUid", gradebookUid)
.setLong("assignmentId", assignmentId)
.uniqueResult());
}
代码示例来源:origin: org.openmobster.core/security
device = (Device)session.createQuery(query).setString(0, identifier).setCacheable(true).uniqueResult();
内容来源于网络,如有侵权,请联系作者删除!