本文整理汇总了Java中org.hibernate.Query.setString方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setString方法的具体用法?Java Query.setString怎么用?Java Query.setString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Query
的用法示例。
在下文中一共展示了Query.setString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.hibernate.Query; //导入方法依赖的package包/类
@Override
public SchoolBean get(String code, int area) {
if (code == null) {
return null;
}
String hql = "FROM SchoolBean WHERE code = :code AND area = :area";
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery(hql);
query.setString("code", code);
query.setInteger("area", area);
List list = query.list();
if (list != null && !list.isEmpty()) {
return (SchoolBean) list.get(0);
}
return null;
}
示例2: updateValueOfKey
import org.hibernate.Query; //导入方法依赖的package包/类
@Override
public boolean updateValueOfKey(Constant constant) {
Session session = HibernateUtils.getSession();
Transaction tx = session.beginTransaction();
boolean isUpdate = false;
try {
Query query = session.createQuery("update Constant c set c.value =? where c.id = ?");
query.setString(0,constant.getValue());
query.setInteger(1, constant.getId());
int temp = query.executeUpdate();
tx.commit();
if (temp>0) {
isUpdate = true;
}
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession();
}
return isUpdate;
}
示例3: updateByHql
import org.hibernate.Query; //导入方法依赖的package包/类
public void updateByHql(String hql, Object[] vals) {
Session session = hibernateTemplate.getSessionFactory().openSession();
org.hibernate.Transaction tx = session.beginTransaction();
Query query = session.createQuery(hql);
if(vals != null) {
for(int i=0;i<vals.length;i++) {
if(vals[i] instanceof Integer) {
query.setInteger(i, (Integer)vals[i]);
} else {
query.setString(i, vals[i].toString());
}
}
}
query.executeUpdate();
try {
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}
session.close();
}
示例4: findPeopleFromStaff
import org.hibernate.Query; //导入方法依赖的package包/类
protected void findPeopleFromStaff(SearchContext context) throws Exception {
String q = "select s from Staff s where ";
for (int idx = 0; idx < context.getQueryTokens().size(); idx++) {
if (idx > 0) q += " and ";
q += "(lower(s.firstName) like :t" + idx + " || '%' " +
"or lower(s.firstName) like '% ' || :t" + idx + " || '%' " +
"or lower(s.middleName) like :t" + idx + " || '%' " +
"or lower(s.middleName) like '% ' || :t" + idx + " || '%' " +
"or lower(s.lastName) like :t" + idx + " || '%' " +
"or lower(s.lastName) like '% ' || :t" + idx + " || '%' " +
"or lower(s.email) like :t" + idx + " || '%')";
}
q += " order by s.lastName, s.firstName, s.middleName";
Query hq = StaffDAO.getInstance().getSession().createQuery(q);
for (int idx = 0; idx < context.getQueryTokens().size(); idx++)
hq.setString("t" + idx, context.getQueryTokens().get(idx));
if (context.getLimit() > 0)
hq.setMaxResults(context.getLimit());
for (Staff staff: (List<Staff>)hq.setCacheable(true).list()) {
context.addPerson(new PersonInterface(translate(staff.getExternalUniqueId(), Source.Staff),
staff.getFirstName(), staff.getMiddleName(), staff.getLastName(), staff.getAcademicTitle(),
staff.getEmail(), null, staff.getDept(),
(staff.getPositionType() == null ? null : staff.getPositionType().getLabel()),
"Staff"));
}
}
示例5: checkCredential
import org.hibernate.Query; //导入方法依赖的package包/类
/**
* Checks whether a user can login to the repository. The Credential must include the password.
*/
@Override
public boolean checkCredential(ICredentials credential) throws RepositoryRuntimeException {
if (log.isDebugEnabled()) {
log.debug("Checking credential " + credential);
}
if (credential == null) {
return false;
}
Session hibernateSession = getSessionFactory().getCurrentSession();
Query query = hibernateSession.createQuery(CredentialDAO.CHECK_CREDENTIAL);
query.setString(0, credential.getName());
query.setString(1, String.valueOf(credential.getPassword()));
Long count = (Long) query.uniqueResult();
if (count > 2) {
log.warn("More than one credential found for name " + credential.getName());
}
return count > 0;
}
示例6: getDistPrefsTableAsPdf
import org.hibernate.Query; //导入方法依赖的package包/类
public void getDistPrefsTableAsPdf(OutputStream out, HttpServletRequest request, SessionContext context, Long subjectAreaId, String courseNbr, Long examTypeId) throws Exception {
Query q = new DistributionPrefDAO().getSession().createQuery(
"select distinct dp from DistributionPref dp " +
"inner join dp.distributionObjects do, Exam x inner join x.owners o " +
"where "+
(courseNbr==null || courseNbr.trim().length()==0?"":courseNbr.indexOf('*')>=0?"o.course.courseNbr like :courseNbr and ":"o.course.courseNbr=:courseNbr and")+
(subjectAreaId==null?"":" o.course.subjectArea.uniqueId=:subjectAreaId and ")+
"dp.distributionType.examPref = true and "+
"do.prefGroup = x and x.session.uniqueId=:sessionId and x.examType.uniqueId=:examTypeId")
.setLong("sessionId", context.getUser().getCurrentAcademicSessionId())
.setLong("examTypeId", examTypeId);
if (subjectAreaId!=null)
q.setLong("subjectAreaId", subjectAreaId);
if (courseNbr!=null && courseNbr.trim().length()!=0)
q.setString("courseNbr", courseNbr.trim().replaceAll("\\*", "%"));
List distPrefs = q.setCacheable(true).list();
toPdfTable(out, request, context, distPrefs, examTypeId);
}
示例7: isDeptInstructorUnique
import org.hibernate.Query; //导入方法依赖的package包/类
/**
* Checks that combination of Instructor/Dept
* does not already exist
* @param frm
* @return
*/
protected boolean isDeptInstructorUnique(
InstructorEditForm frm,
HttpServletRequest request ) {
String query = "from DepartmentalInstructor " +
"where externalUniqueId=:puid and department.uniqueId=:deptId";
if (frm.getInstructorId()!=null && frm.getInstructorId().trim().length()>0) {
query += " and uniqueId!=:uniqueId";
}
DepartmentalInstructorDAO ddao = new DepartmentalInstructorDAO();
org.hibernate.Session hibSession = ddao.getSession();
HttpSession httpSession = request.getSession();
String deptId = (String) httpSession.getAttribute(Constants.DEPT_ID_ATTR_NAME);
Query q = hibSession.createQuery(query);
q.setString("puid", frm.getPuId().trim());
q.setLong("deptId", Long.parseLong(deptId));
if (frm.getInstructorId()!=null && frm.getInstructorId().trim().length()>0) {
q.setString("uniqueId", frm.getInstructorId().trim());
}
return (q.list().size()==0);
}
示例8: createReminderJob
import org.hibernate.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void createReminderJob(List<String> principals,Session session,TaskImpl task,String processDefinitionId){
String hql="from "+TaskReminder.class.getName()+" where processDefinitionId=:processDefinitionId and taskName=:taskName";
Query query=null;
String fixedCompanyId=Configure.getString(IDao.FIXED_COMPANY_ID);
if(StringUtils.isNotEmpty(fixedCompanyId)){
hql+=" and companyId=:companyId";
query=session.createQuery(hql);
query.setString("companyId",fixedCompanyId);
}else{
query=session.createQuery(hql);
}
query.setString("processDefinitionId",processDefinitionId).setString("taskName",task.getName());
List<TaskReminder> reminders=query.list();
for(TaskReminder reminder:reminders){
createReminderJob(principals, session, task, reminder);
}
}
示例9: setQuery
import org.hibernate.Query; //导入方法依赖的package包/类
/******************* End:可执行语�?*************/
// 根据map设置参数
private void setQuery(Map<String, Object> map, Query query) {
if (map == null) {
return;
} else {
for (Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
if (key.indexOf("|") > 0) {
key = key.split("\\|")[0];
}
Object value = entry.getValue();
key = key.replaceAll("\\.", "_");
if (value instanceof Integer) {
query.setInteger(key, Integer.parseInt(value.toString()));
} else if (value instanceof String) {
query.setString(key, value.toString());
} else {
query.setParameter(key, value);
}
}
}
}
示例10: getCountPagedUsersBySession
import org.hibernate.Query; //导入方法依赖的package包/类
@Override
public int getCountPagedUsersBySession(Long sessionId, String searchString) {
String LOAD_USERS_ORDERED_BY_NAME = "SELECT COUNT(*) FROM " + TaskListUser.class.getName() + " user"
+ " WHERE user.session.sessionId = :sessionId "
+ " AND (CONCAT(user.lastName, ' ', user.firstName) LIKE CONCAT('%', :searchString, '%')) ";
Query query = getSession().createQuery(LOAD_USERS_ORDERED_BY_NAME);
query.setLong("sessionId", sessionId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
List list = query.list();
if ((list == null) || (list.size() == 0)) {
return 0;
} else {
return ((Number) list.get(0)).intValue();
}
}
示例11: findPeopleFromInstructors
import org.hibernate.Query; //导入方法依赖的package包/类
protected void findPeopleFromInstructors(SearchContext context) throws Exception {
String q = "select s from DepartmentalInstructor s where s.department.session.uniqueId = :sessionId";
for (int idx = 0; idx < context.getQueryTokens().size(); idx++) {
q += " and (lower(s.firstName) like :t" + idx + " || '%' " +
"or lower(s.firstName) like '% ' || :t" + idx + " || '%' " +
"or lower(s.middleName) like :t" + idx + " || '%' " +
"or lower(s.middleName) like '% ' || :t" + idx + " || '%' " +
"or lower(s.lastName) like :t" + idx + " || '%' " +
"or lower(s.lastName) like '% ' || :t" + idx + " || '%' " +
"or lower(s.email) like :t" + idx + " || '%')";
}
q += " order by s.lastName, s.firstName, s.middleName";
Query hq = DepartmentalInstructorDAO.getInstance().getSession().createQuery(q);
for (int idx = 0; idx < context.getQueryTokens().size(); idx++)
hq.setString("t" + idx, context.getQueryTokens().get(idx));
hq.setLong("sessionId", context.getSessionId());
if (context.getLimit() > 0)
hq.setMaxResults(context.getLimit());
for (DepartmentalInstructor instructor: (List<DepartmentalInstructor>)hq.setCacheable(true).list()) {
context.addPerson(new PersonInterface(translate(instructor.getExternalUniqueId(), Source.Staff),
Constants.toInitialCase(instructor.getFirstName()),
Constants.toInitialCase(instructor.getMiddleName()),
Constants.toInitialCase(instructor.getLastName()),
instructor.getAcademicTitle(),
instructor.getEmail(), null, instructor.getDepartment().getName(),
(instructor.getPositionType() == null ? null : instructor.getPositionType().getLabel()),
"Instructors"));
}
}
示例12: getTermStartDate
import org.hibernate.Query; //导入方法依赖的package包/类
@Override
public Date getTermStartDate(String userKey) {
if (userKey == null) {
return null;
}
String hql = "SELECT MIN(date) FROM CourseBean WHERE userKey = :userKey";
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery(hql);
query.setString("userKey", userKey);
return (Date) query.uniqueResult();
}
示例13: queryCoverApp
import org.hibernate.Query; //导入方法依赖的package包/类
@Override
public List<MonApp> queryCoverApp(String marketName) {
List<MonApp> list = new ArrayList<MonApp>();
StringBuilder sbSql = new StringBuilder();
sbSql.append("SELECT");
sbSql.append(" new.id,new.MarketAppId,");
sbSql.append(" new.MarketName as NewMarketName, ");
sbSql.append(" old.MarketName,");
sbSql.append(" old.ApkId,");
sbSql.append(" old.`Name`,");
sbSql.append(" new.NAME AS NewName,");
sbSql.append(" new.version as Newversion,");
sbSql.append(" old.version,");
sbSql.append(" new.versionCode as NewVersionCode,");
sbSql.append(" old.versionCode,");
sbSql.append(" old.pkname,");
sbSql.append(" old.downloadUrl,");
sbSql.append(" old.SignatureSHA1,");
sbSql.append(" old.MarketApkScanTime,");
sbSql.append(" new.LastFetchTime AS AppFetchTime ");
sbSql.append(" FROM ");
sbSql.append(" MarketApp old LEFT JOIN App new ");
sbSql.append(" ON old .Pkname = new.Pkname AND new.SignatureSHA1 = old .SignatureSHA1 AND new.MarketName<> old.MarketName ");
sbSql.append(" WHERE ");
sbSql.append(" new.versionCode > old .versionCode");
if (StringUtils.isNotEmpty(marketName)) {
sbSql.append(" AND old.MarketName =:marketName");
}
logger.debug(sbSql.toString());
Session sessionQuery = this.sessions.openSession();
Query q = sessionQuery.createSQLQuery(sbSql.toString()).addEntity(MonApp.class);
if (StringUtils.isNotEmpty(marketName)) {
q.setString("marketName", marketName);
}
list = HibernateHelper.list(q);
sessionQuery.close();
return list;
}
示例14: isExistsUser
import org.hibernate.Query; //导入方法依赖的package包/类
@Override
public boolean isExistsUser(String name, String email) {
Query query = getSession().createQuery("from User u where u.name=:username and u.email=:email");
query.setString("username", name);
query.setString("email", email);
@SuppressWarnings("unchecked")
List<User> list = query.list();
if (list == null || list.size() == 0) {
return false;
} else {
return true;
}
}
示例15: getCountCoursesByParentCourseAndTypeAndState
import org.hibernate.Query; //导入方法依赖的package包/类
@Override
public int getCountCoursesByParentCourseAndTypeAndState(Integer parentOrgId, Integer typeId, Integer stateId,
String searchString) {
Query query = getSession().createQuery(OrganisationDAO.GET_COUNT_COURSES_BY_PARENT_TYPE_STATE);
query.setInteger("parentOrgId", parentOrgId);
query.setInteger("typeId", typeId);
query.setInteger("stateId", stateId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
return ((Number) query.uniqueResult()).intValue();
}