|
|
|
@ -22,7 +22,10 @@ import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
import java.util.stream.StreamSupport; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.ibatis.cursor.Cursor; |
|
|
|
import org.apache.ibatis.session.SqlSession; |
|
|
|
import org.apache.ibatis.session.SqlSession; |
|
|
|
import org.mybatis.spring.SqlSessionTemplate; |
|
|
|
import org.mybatis.spring.SqlSessionTemplate; |
|
|
|
import org.springframework.dao.EmptyResultDataAccessException; |
|
|
|
import org.springframework.dao.EmptyResultDataAccessException; |
|
|
|
@ -59,6 +62,7 @@ import org.springframework.util.Assert; |
|
|
|
* @author Chirag Tailor |
|
|
|
* @author Chirag Tailor |
|
|
|
* @author Christopher Klein |
|
|
|
* @author Christopher Klein |
|
|
|
* @author Mikhail Polivakha |
|
|
|
* @author Mikhail Polivakha |
|
|
|
|
|
|
|
* @author Sergey Korotaev |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class MyBatisDataAccessStrategy implements DataAccessStrategy { |
|
|
|
public class MyBatisDataAccessStrategy implements DataAccessStrategy { |
|
|
|
|
|
|
|
|
|
|
|
@ -263,12 +267,28 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy { |
|
|
|
return sqlSession().selectList(statement, parameter); |
|
|
|
return sqlSession().selectList(statement, parameter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public <T> Stream<T> streamAll(Class<T> domainType) { |
|
|
|
|
|
|
|
String statement = namespace(domainType) + ".streamAll"; |
|
|
|
|
|
|
|
MyBatisContext parameter = new MyBatisContext(null, null, domainType, Collections.emptyMap()); |
|
|
|
|
|
|
|
Cursor<T> cursor = sqlSession().selectCursor(statement, parameter); |
|
|
|
|
|
|
|
return StreamSupport.stream(cursor.spliterator(), false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public <T> List<T> findAllById(Iterable<?> ids, Class<T> domainType) { |
|
|
|
public <T> List<T> findAllById(Iterable<?> ids, Class<T> domainType) { |
|
|
|
return sqlSession().selectList(namespace(domainType) + ".findAllById", |
|
|
|
return sqlSession().selectList(namespace(domainType) + ".findAllById", |
|
|
|
new MyBatisContext(ids, null, domainType, Collections.emptyMap())); |
|
|
|
new MyBatisContext(ids, null, domainType, Collections.emptyMap())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public <T> Stream<T> streamAllByIds(Iterable<?> ids, Class<T> domainType) { |
|
|
|
|
|
|
|
String statement = namespace(domainType) + ".streamAllByIds"; |
|
|
|
|
|
|
|
MyBatisContext parameter = new MyBatisContext(ids, null, domainType, Collections.emptyMap()); |
|
|
|
|
|
|
|
Cursor<T> cursor = sqlSession().selectCursor(statement, parameter); |
|
|
|
|
|
|
|
return StreamSupport.stream(cursor.spliterator(), false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<Object> findAllByPath(Identifier identifier, |
|
|
|
public List<Object> findAllByPath(Identifier identifier, |
|
|
|
PersistentPropertyPath<? extends RelationalPersistentProperty> path) { |
|
|
|
PersistentPropertyPath<? extends RelationalPersistentProperty> path) { |
|
|
|
@ -296,6 +316,19 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy { |
|
|
|
new MyBatisContext(null, null, domainType, additionalContext)); |
|
|
|
new MyBatisContext(null, null, domainType, additionalContext)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public <T> Stream<T> streamAll(Class<T> domainType, Sort sort) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> additionalContext = new HashMap<>(); |
|
|
|
|
|
|
|
additionalContext.put("sort", sort); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String statement = namespace(domainType) + ".streamAllSorted"; |
|
|
|
|
|
|
|
MyBatisContext parameter = new MyBatisContext(null, null, domainType, additionalContext); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cursor<T> cursor = sqlSession().selectCursor(statement, parameter); |
|
|
|
|
|
|
|
return StreamSupport.stream(cursor.spliterator(), false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public <T> List<T> findAll(Class<T> domainType, Pageable pageable) { |
|
|
|
public <T> List<T> findAll(Class<T> domainType, Pageable pageable) { |
|
|
|
|
|
|
|
|
|
|
|
@ -315,6 +348,11 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy { |
|
|
|
throw new UnsupportedOperationException("Not implemented"); |
|
|
|
throw new UnsupportedOperationException("Not implemented"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public <T> Stream<T> streamAll(Query query, Class<T> probeType) { |
|
|
|
|
|
|
|
throw new UnsupportedOperationException("Not implemented"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public <T> List<T> findAll(Query query, Class<T> probeType, Pageable pageable) { |
|
|
|
public <T> List<T> findAll(Query query, Class<T> probeType, Pageable pageable) { |
|
|
|
throw new UnsupportedOperationException("Not implemented"); |
|
|
|
throw new UnsupportedOperationException("Not implemented"); |
|
|
|
|