光滑3.1.1流 - 分页

时间:2016-03-23 11:24:22

标签: playframework playframework-2.0 slick slick-3.0

我正在尝试使用Slick Stream来实现分页的行为。 我的Dao代码如下:

def getStreamCompanies: DatabasePublisher[CompanyVO] = {
    val disableAutoCommit = SimpleDBIO(_.connection.setAutoCommit(false))
    val action = companies.take(50).result.withStatementParameters(fetchSize = 10)
    dbConfig.db.stream(disableAutoCommit andThen action)
}

我的控制器代码如下:

def getStreamCompanies = Action {
    implicit val companyWrites: Writes[CompanyVO] = Json.writes[CompanyVO]
    val publisher = CompanyService.getStreamCompanies
    val enumerator = Streams.publisherToEnumerator(publisher)
    Ok.chunked(enumerator map companyWrites.writes)
}

根据目前的方法,我有10家公司作为回应。但是当我再次请求时,我收到此错误

slick.SlickException: Read NULL value for ResultSet column <computed>
at slick.jdbc.BaseResultConverter$mcD$sp.read$mcD$sp(JdbcResultConverter.scala:13) ~[slick_2.11-3.1.1.jar:na]
at slick.jdbc.BaseResultConverter$mcD$sp.read(JdbcResultConverter.scala:11) ~[slick_2.11-3.1.1.jar:na]
at slick.jdbc.BaseResultConverter$mcD$sp.read(JdbcResultConverter.scala:10) ~[slick_2.11-3.1.1.jar:na]
at slick.relational.ProductResultConverter.read(ResultConverter.scala:56) ~[slick_2.11-3.1.1.jar:na]
at slick.relational.ProductResultConverter.read(ResultConverter.scala:46) ~[slick_2.11-3.1.1.jar:na]
at slick.relational.TypeMappingResultConverter.read(ResultConverter.scala:136) ~[slick_2.11-3.1.1.jar:na]
at slick.driver.JdbcInvokerComponent$QueryInvokerImpl.extractValue(JdbcInvokerComponent.scala:37) ~[slick_2.11-3.1.1.jar:na]
at slick.jdbc.StatementInvoker$$anon$1.extractValue(StatementInvoker.scala:67) ~[slick_2.11-3.1.1.jar:na]
at slick.jdbc.PositionedResultIterator.fetchNext(PositionedResult.scala:176) ~[slick_2.11-3.1.1.jar:na]
at slick.util.ReadAheadIterator$class.slick$util$ReadAheadIterator$$update(ReadAheadIterator.scala:34) ~[slick_2.11-3.1.1.jar:na]
at slick.util.ReadAheadIterator$class.hasNext(ReadAheadIterator.scala:40) ~[slick_2.11-3.1.1.jar:na]
at slick.jdbc.PositionedResultIterator.hasNext(PositionedResult.scala:167) ~[slick_2.11-3.1.1.jar:na]
at slick.jdbc.StreamingInvokerAction$class.emitStream(StreamingInvokerAction.scala:31) ~[slick_2.11-3.1.1.jar:na]
at slick.driver.JdbcActionComponent$QueryActionExtensionMethodsImpl$$anon$1.emitStream(JdbcActionComponent.scala:218) ~[slick_2.11-3.1.1.jar:na]
at slick.driver.JdbcActionComponent$QueryActionExtensionMethodsImpl$$anon$1.emitStream(JdbcActionComponent.scala:218) ~[slick_2.11-3.1.1.jar:na]
at slick.backend.DatabaseComponent$DatabaseDef$$anon$3.run(DatabaseComponent.scala:285) ~[slick_2.11-3.1.1.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_72-internal]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_72-internal]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_72-internal]

如何进一步处理? chunked 的目的是什么?

0 个答案:

没有答案