本文整理汇总了Java中org.springframework.dao.support.DataAccessUtils类的典型用法代码示例。如果您正苦于以下问题:Java DataAccessUtils类的具体用法?Java DataAccessUtils怎么用?Java DataAccessUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataAccessUtils类属于org.springframework.dao.support包,在下文中一共展示了DataAccessUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getByName
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
public User getByName (final String name)
{
User user = (User)DataAccessUtils.uniqueResult (
getHibernateTemplate ().find (
"From User u where u.username=?", name));
// Optimization user extraction: most of the users uses case-sensitive
// match for the login. A Requirement of the project asked for non-case
// sensitive match. The extraction of non-case sensitive login from
// database requires conversions and forbid the usage of indexes, so it
// is much more slow.
// This Fix aims to first try the extraction of the user with exact match
// equals operator, then if not match use the toLower conversion.
if (user==null)
user = (User)DataAccessUtils.uniqueResult (
getHibernateTemplate ().find (
"From User u where lower(u.username)=lower(?)", name));
return user;
}
示例2: count
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
/**
* Counts collections whose the given user is authorized.
* @param user the given user.
* @return number of authorized collection for user.
*/
public int count (User user)
{
String userString = "";
// Bypass for Data Right Managers. They can see all products and
// collections.
if ( !cfgManager.isDataPublic () && (user != null) &&
!user.getRoles ().contains (Role.DATA_MANAGER))
{
userString =
"WHERE ('" + user.getUUID () + "' in elements(authorizedUsers) OR '" +
userDao.getPublicData ().getUUID () +
"' in elements(authorizedUsers))";
}
return DataAccessUtils
.intResult (find ("select count(*) FROM Collection " + userString));
}
示例3: countOpenSessions
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
@SuppressWarnings ("rawtypes")
private int countOpenSessions ()
{
return DataAccessUtils.intResult (getHibernateTemplate ().execute (
new HibernateCallback<List>()
{
@Override
public List doInHibernate(Session session)
throws HibernateException, SQLException
{
String sql =
"SELECT count (*) FROM INFORMATION_SCHEMA.SYSTEM_SESSIONS";
SQLQuery query = session.createSQLQuery (sql);
return query.list ();
}
}));
}
示例4: getSystemByName
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
@SuppressWarnings ({ "unchecked", "rawtypes" })
private String getSystemByName (final String name, final int index)
{
return DataAccessUtils.uniqueResult (getHibernateTemplate ().execute (
new HibernateCallback<List>()
{
@Override
public List doInHibernate(Session session)
throws HibernateException, SQLException
{
String sql =
"SELECT " + name +
" FROM INFORMATION_SCHEMA.SYSTEM_SESSIONS" +
" LIMIT 1 OFFSET " + index;
SQLQuery query = session.createSQLQuery (sql);
return query.list ();
}
})).toString ();
}
示例5: count
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
/**
* Returns the number of Product records whose `processed` field is `true`.
* @param filter an optional additionnal `where` clause (without the "where" token).
* @param collection_uuid an optional parent collection ID.
* @return a number of rows in table `PRODUCTS`.
*/
public int count (String filter, final String collection_uuid)
{
StringBuilder sb = new StringBuilder("select count(*) ");
if (collection_uuid != null)
{
sb.append("from Collection c left outer join c.products p ");
sb.append("where c.uuid='").append(collection_uuid).append("' and ");
}
else
{
sb.append("from Product p where ");
}
sb.append("p.processed=true");
if (filter != null && !filter.isEmpty())
{
sb.append(" and ").append(filter);
}
return DataAccessUtils.intResult(find(sb.toString()));
}
示例6: doDataSourceHealthCheck
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
private void doDataSourceHealthCheck(Health.Builder builder) throws Exception {
String product = getProduct();
builder.up().withDetail("database", product);
String validationQuery = getValidationQuery(product);
if (StringUtils.hasText(validationQuery)) {
try {
// Avoid calling getObject as it breaks MySQL on Java 7
List<Object> results = this.jdbcTemplate.query(validationQuery,
new SingleColumnRowMapper());
Object result = DataAccessUtils.requiredSingleResult(results);
builder.withDetail("hello", result);
}
catch (Exception ex) {
builder.down(ex);
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:DataSourceHealthIndicator.java
示例7: selectMap
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <K, V> Map<K, V> selectMap(String statement, Object parameter,
String mapKey, RowBounds rowBounds) {
final List<?> list = selectList(statement, parameter, rowBounds);
if (list == null || list.size() == 0) {
return new HashMap<K, V>();
}
if (mapKey == null) {
return (Map<K, V>) DataAccessUtils.requiredSingleResult(list);
}
ObjectFactory objectFactory = configuration.getObjectFactory();
Map<K, V> selectedMap = objectFactory.create(Map.class);
for (Object o : list) {
V value = (V) o;
MetaObject mo = MetaObject.forObject(o, objectFactory);
final K key = (K) mo.getValue(mapKey);
selectedMap.put(key, value);
}
return selectedMap;
}
示例8: findServerLastDailyUsage
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
/**
* Najde posledni zname vyuziti zdroju serveru
*
* @return
*/
@Override
public DailyUsage findServerLastDailyUsage(Integer serverId) {
StringBuilder jpql = new StringBuilder();
jpql.append(" SELECT dailyUsage ");
jpql.append(" FROM DailyUsage AS dailyUsage ");
jpql.append(" JOIN dailyUsage.dailyImport AS dailyImport ");
jpql.append(" WHERE dailyUsage.server.id = :serverId ");
jpql.append(" ORDER BY dailyImport.date DESC ");
TypedQuery<DailyUsage> query = em.createQuery(jpql.toString(), DailyUsage.class);
query.setMaxResults(1);
query.setParameter("serverId", serverId);
return DataAccessUtils.uniqueResult(query.getResultList());
}
示例9: getNextOrder
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
/**
* Pro pozadovany kontrakt najde nejblizsi volne poradove cislo trasnakce v ramci tohoto kontraktu
*/
@Override
public Integer getNextOrder(Integer contractId) {
StringBuilder jpql = new StringBuilder();
jpql.append(" SELECT MAX(transaction.order) ");
jpql.append(" FROM Transaction AS transaction ");
jpql.append(" JOIN transaction.contract AS contract ");
jpql.append(" WHERE contract.id = :contractId ");
TypedQuery<Integer> query = em.createQuery(jpql.toString(), Integer.class);
query.setParameter("contractId", contractId);
Integer maxOrder = DataAccessUtils.uniqueResult(query.getResultList());
if (maxOrder == null) {
maxOrder = 0;
}
return maxOrder + 1;
}
示例10: getByCodeUserLoadAllData
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
public UserData getByCodeUserLoadAllData(String codeUser) {
MyLogger.info(log, CLASS_NAME, "getByCodeUserLoadAllData", "codeUser="+codeUser, "START");
Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession()
.createCriteria(UserData.class, "user")
.add( Restrictions.eq("user.codeUser", codeUser) )
.createAlias("user.profiles", "profile", Criteria.LEFT_JOIN)
.createAlias("user.roles", "role", Criteria.LEFT_JOIN)
.createAlias("role.permissions", "permission", Criteria.LEFT_JOIN)
.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY );
UserData data = (UserData) DataAccessUtils.uniqueResult( criteria.list() );
MyLogger.info(log, CLASS_NAME, "getByCodeUser", "codeUser="+codeUser, "END");
return data;
}
示例11: getPrimaryCalendarFolder
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
public void getPrimaryCalendarFolder() {
initializeCredentials();
GetFolder request = requestFactory.constructGetFolderByName(DistinguishedFolderIdNameType.CALENDAR);
assertNotNull(request);
GetFolderResponse response = ewsClient.getFolder(request);
assertNotNull(response);
Set<BaseFolderType> results = responseUtils.parseGetFolderResponse(response);
assertNotNull(results);
assertFalse(CollectionUtils.isEmpty(results));
assertEquals(1, results.size());
BaseFolderType singleResult = DataAccessUtils.singleResult(results);
assertNotNull(singleResult);
assertEquals("Calendar", singleResult.getDisplayName());
}
示例12: countNotDeleted
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
public int countNotDeleted (String filter)
{
return DataAccessUtils.intResult (find (
"select count(*) FROM " + entityClass.getName () +
" u WHERE u.deleted is false AND u.username LIKE '%" + filter +
"%' and " + "not u.username='" +
cfgManager.getAdministratorConfiguration ().getName () + "'" +
" and not u.username LIKE '"+getPublicData ().getUsername ()+"' "));
}
示例13: countForDataRight
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
public int countForDataRight (String filter)
{
return DataAccessUtils.intResult (find (
"select count(*) FROM " + entityClass.getName () +
" u WHERE u.deleted is false AND u.username LIKE '%" + filter +
"%' and " + "not u.username='" +
cfgManager.getAdministratorConfiguration ().getName () + "' "));
}
示例14: countAll
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
public int countAll (String filter)
{
return DataAccessUtils.intResult (find (
"select count(*) FROM " + entityClass.getName () +
" u WHERE u.username LIKE '%" + filter + "%'" +
" and not u.username LIKE '" + getPublicData ().getUsername () +
"' " ));
}
示例15: countNotDeletedByFilter
import org.springframework.dao.support.DataAccessUtils; //导入依赖的package包/类
public int countNotDeletedByFilter (String filter)
{
return DataAccessUtils.intResult (find (
"select count(*) FROM " + entityClass.getName () +
" u WHERE u.deleted is false AND (u.username LIKE '%" + filter +
"%' OR lower(u.firstname) LIKE '%"+filter.toLowerCase()+ "%' OR lower(u.lastname) LIKE '%"+filter.toLowerCase()+
"%' OR lower(u.email) LIKE '%"+filter.toLowerCase()+ "%') and not u.username='" +
cfgManager.getAdministratorConfiguration ().getName () + "'" +
" and not u.username LIKE '"+getPublicData ().getUsername ()+"' "));
}