本文整理了Java中org.hibernate.query.Query.setLong
方法的一些代码示例,展示了Query.setLong
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setLong
方法的具体详情如下:
包路径:org.hibernate.query.Query
类名称:Query
方法名:setLong
[英]Bind a positional long-valued parameter.
[中]绑定位置长值参数。
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void shouldRetrieveSubSubEntityWithHQL() {
session = openSession();
try {
SubSubEntity loaded = (SubSubEntity) session.createQuery(
"select se from SubSubEntity se where se.id = :id" )
.setLong( "id", subSubEntityId )
.uniqueResult();
assertNotNull( loaded );
}
finally {
session.close();
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void shouldNotRetrieveSubSubSubEntityWithHQL() {
session = openSession();
try {
SubSubSubEntity loaded = (SubSubSubEntity) session.createQuery(
"select se from SubSubSubEntity se where se.id = :id" )
.setLong( "id", subSubEntityId )
.uniqueResult();
assertNull( loaded );
}
finally {
session.close();
}
}
代码示例来源:origin: hibernate/hibernate-orm
Session s = openSession();
s.beginTransaction();
s.createQuery( "from Animal a where abs(a.bodyWeight-:param) < 2.0" ).setLong( "param", 1 ).list();
s.createQuery( "from Animal a where abs(:param - a.bodyWeight) < 2.0" ).setLong( "param", 1 ).list();
if ( ( getDialect() instanceof HSQLDialect ) || ( getDialect() instanceof DB2Dialect ) ) {
s.createQuery( "from Animal where abs(cast(:x as long) - :y) < 2.0" ).setLong( "x", 1 ).setLong( "y", 1 ).list();
s.createQuery( "from Animal where abs(:x - cast(:y as long)) < 2.0" ).setLong( "x", 1 ).setLong( "y", 1 ).list();
s.createQuery( "from Animal where abs(cast(:x as long) - cast(:y as long)) < 2.0" ).setLong( "x", 1 ).setLong( "y", 1 ).list();
s.createQuery( "from Animal where abs(:x - :y) < 2.0" ).setLong( "x", 1 ).setLong( "y", 1 ).list();
s.createQuery( "from Animal where lower(upper(:foo)) like 'f%'" ).setString( "foo", "foo" ).list();
s.createQuery( "from Animal a where abs(abs(a.bodyWeight - 1.0 + :param) * abs(length('ffobar')-3)) = 3.0" ).setLong(
"param", 1
).list();
.setLong( "param", 1 ).list();
.setLong( "param", 1 ).list();
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testUpdateOnComponent() {
Session s = openSession();
Transaction t = s.beginTransaction();
Human human = new Human();
human.setName( new Name( "Stevee", 'X', "Ebersole" ) );
s.save( human );
s.flush();
t.commit();
String correctName = "Steve";
t = s.beginTransaction();
int count = s.createQuery( "update Human set name.first = :correction where id = :id" )
.setString( "correction", correctName )
.setLong( "id", human.getId().longValue() )
.executeUpdate();
assertEquals( "Incorrect update count", 1, count );
t.commit();
t = s.beginTransaction();
s.refresh( human );
assertEquals( "Update did not execute properly", correctName, human.getName().getFirst() );
s.createQuery( "delete Human" ).executeUpdate();
t.commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testUpdateOnDiscriminatorSubclass() {
TestData data = new TestData();
data.prepare();
Session s = openSession();
Transaction t = s.beginTransaction();
int count = s.createQuery( "update PettingZoo set name = name" ).executeUpdate();
assertEquals( "Incorrect discrim subclass update count", 1, count );
t.rollback();
t = s.beginTransaction();
count = s.createQuery( "update PettingZoo pz set pz.name = pz.name where pz.id = :id" )
.setLong( "id", data.pettingZoo.getId().longValue() )
.executeUpdate();
assertEquals( "Incorrect discrim subclass update count", 1, count );
t.rollback();
t = s.beginTransaction();
count = s.createQuery( "update Zoo as z set z.name = z.name" ).executeUpdate();
assertEquals( "Incorrect discrim subclass update count", 2, count );
t.rollback();
t = s.beginTransaction();
// TODO : not so sure this should be allowed. Seems to me that if they specify an alias,
// property-refs should be required to be qualified.
count = s.createQuery( "update Zoo as z set name = name where id = :id" )
.setLong( "id", data.zoo.getId().longValue() )
.executeUpdate();
assertEquals( "Incorrect discrim subclass update count", 1, count );
t.commit();
s.close();
data.cleanup();
}
代码示例来源:origin: hibernate/hibernate-orm
t = s.beginTransaction();
IntegerVersioned created = ( IntegerVersioned ) s.createQuery( "from IntegerVersioned where id <> :initialId" )
.setLong( "initialId", initialId.longValue() )
.uniqueResult();
t.commit();
代码示例来源:origin: hibernate/hibernate-orm
t = s.beginTransaction();
TimestampVersioned created = ( TimestampVersioned ) s.createQuery( "from TimestampVersioned where id <> :initialId" )
.setLong( "initialId", initialId.longValue() )
.uniqueResult();
t.commit();
代码示例来源:origin: hibernate/hibernate-orm
@Test
@RequiresDialectFeature(
value = DialectChecks.HasSelfReferentialForeignKeyBugCheck.class,
comment = "self referential FK bug"
)
public void testSimpleDeleteOnAnimal() {
TestData data = new TestData();
data.prepare();
Session s = openSession();
Transaction t = s.beginTransaction();
int count = s.createQuery( "delete from Animal as a where a.id = :id" )
.setLong( "id", data.polliwog.getId().longValue() )
.executeUpdate();
assertEquals( "Incorrect delete count", 1, count );
count = s.createQuery( "delete Animal where id = :id" )
.setLong( "id", data.catepillar.getId().longValue() )
.executeUpdate();
assertEquals( "incorrect delete count", 1, count );
if ( getDialect().supportsSubqueryOnMutatingTable() ) {
count = s.createQuery( "delete from User u where u not in (select u from User u)" ).executeUpdate();
assertEquals( 0, count );
}
count = s.createQuery( "delete Animal a" ).executeUpdate();
assertEquals( "Incorrect delete count", 4, count );
List list = s.createQuery( "select a from Animal as a" ).list();
assertTrue( "table not empty", list.isEmpty() );
t.commit();
s.close();
data.cleanup();
}
代码示例来源:origin: hibernate/hibernate-orm
.setLong( "last", lastContainerId.longValue() )
.list();
Container container = ( Container ) all.get( 0 );
代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter
@Override
@SuppressWarnings("deprecation")
public Query setLong(final String name, final long val) {
if (queryV2ForCompare != null) {
queryV2ForCompare.setLong(name, val);
}
query.setLong(name, val);
return this;
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
@Override
@SuppressWarnings("unchecked")
public DirectoryMapping findDirectoryMapping(long applicationId, long directoryId) throws DirectoryMappingNotFoundException {
final Optional<DirectoryMapping> maybeDirectoryMapping = session().getNamedQuery("findDirectoryMapping")
.setLong("applicationId", applicationId)
.setLong("directoryId", directoryId)
.uniqueResultOptional();
return maybeDirectoryMapping.orElseThrow(() -> new DirectoryMappingNotFoundException(applicationId, directoryId));
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
public void removeAllRelationships(long directoryId) {
session().getNamedQuery("removeAllRelationships")
.setLong("directoryId", directoryId)
.executeUpdate();
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
public void removeAll(long directoryId) {
// remove all relationships
membershipDao.removeAllRelationships(directoryId);
// remove all group attributes and groups
session().getNamedQuery("removeAllInternalGroupAttributesInDirectory")
.setLong("directoryId", directoryId)
.executeUpdate();
session().getNamedQuery("removeAllGroupsInDirectory")
.setLong("directoryId", directoryId)
.executeUpdate();
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
@Override
public void remove(final long directoryId, final String name) {
session().getNamedQuery("removeTokensByDirectoryAndName")
.setLong("directoryId", directoryId)
.setString("name", name)
.executeUpdate();
session().flush();
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
@Override
public boolean removeByDirectoryAndUsername(long directoryId, String username) {
final int numDeleted = session().getNamedQuery("removeExpirableUserTokensByUsernameAndDirectory")
.setString("username", username)
.setLong("directoryId", directoryId)
.executeUpdate();
return numDeleted > 0;
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
public BoundedCount countDirectMembersOfGroup(long directoryId, String groupName, int potentialMaxCount) {
final Number count = (Number) session().getNamedQuery("countMembersOfGroup")
.setLong("directoryId", directoryId)
.setString("lowerGroupName", toLowerCase(groupName))
.setParameter("membershipType", MembershipType.GROUP_USER)
.uniqueResult();
return BoundedCount.exactly(count.longValue());
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
public void removeUserMemberships(long directoryId, String username) {
session().getNamedQuery("removeAllEntityMemberships")
.setString("entityName", toLowerCase(username))
.setLong("directoryId", directoryId)
.setParameter("membershipType", MembershipType.GROUP_USER)
.executeUpdate();
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
@Override
public List<InternalApplicationDefaultGroupMembershipConfiguration> listAll(final Application application, ApplicationDirectoryMapping directoryMapping) throws DirectoryMappingNotFoundException {
final DirectoryMapping directoryMappingEntity = applicationDAO.findDirectoryMapping(application.getId(), directoryMapping.getDirectory().getId());
return session().getNamedQuery("listAllAutoAddGroupConfigurations")
.setLong("directoryMappingId", directoryMappingEntity.getId())
.list();
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
@Override
public void removeAll(final Application application, ApplicationDirectoryMapping directoryMapping) throws DirectoryMappingNotFoundException {
final DirectoryMapping directoryMappingEntity = applicationDAO.findDirectoryMapping(application.getId(), directoryMapping.getDirectory().getId());
session().getNamedQuery("removeAllDefaultGroupMembershipsForApplicationAndDirectory")
.setLong("directoryMappingId", directoryMappingEntity.getId())
.executeUpdate();
}
代码示例来源:origin: com.atlassian.crowd/crowd-persistence-hibernate5
@Override
public void remove(final Application application, ApplicationDirectoryMapping directoryMapping, String groupName) throws DirectoryMappingNotFoundException {
final DirectoryMapping directoryMappingEntity = applicationDAO.findDirectoryMapping(application.getId(), directoryMapping.getDirectory().getId());
session().getNamedQuery("removeDefaultGroupMembershipConfiguration")
.setLong("directoryMappingId", directoryMappingEntity.getId())
.setString("groupName", groupName)
.executeUpdate();
}
内容来源于网络,如有侵权,请联系作者删除!