Skip to content

Commit

Permalink
feat: Optimize the order in which the jooq pager fetches the total nu…
Browse files Browse the repository at this point in the history
…mber of data
  • Loading branch information
T-baby committed Sep 7, 2021
1 parent 5103191 commit 487bc58
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ package net.cloudopt.next.jooq

import java.io.Serializable

/*
* @author: Cloudopt
* @Time: 2018/4/5
* @Description: Pagination
*/
data class JooqPage(
val count: Int = 0,
val page: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@ import org.jooq.SelectWindowStep

class JooqPaginate(query: SelectWindowStep<*>, private var count: Int, private val page: Int) {

private var totalPage: Int = 0
private val totalRow: Long
private var totalPage: Int = -1
private var totalRow: Long = -1
private var firstPage = false
private var lastPage = false
private var query: SelectWindowStep<*>
private lateinit var orderField: OrderField<*>

init {
this.query = query
this.totalRow = count().toLong()
}

fun order(orderField: OrderField<*>) {
this.orderField = orderField
}

fun <T> find(clazz: Class<T>): JooqPage {
this.totalRow = this.query.count().toLong()
this.totalPage = (totalRow / count.toLong()).toInt()
if (totalRow % count.toLong() != 0L) {
++totalPage
Expand All @@ -47,13 +54,6 @@ class JooqPaginate(query: SelectWindowStep<*>, private var count: Int, private v
this.firstPage = this.page == 1
this.lastPage = this.page == this.totalPage

}

fun order(orderField: OrderField<*>) {
this.orderField = orderField
}

fun <T> find(clazz: Class<T>): JooqPage {
var list = query.orderBy(orderField).limit(this.count).offset(skip()).fetchInto(clazz)
list = if (list.isNotEmpty()) {
list.toMutableList()
Expand All @@ -76,9 +76,5 @@ class JooqPaginate(query: SelectWindowStep<*>, private var count: Int, private v
return (page - 1) * count
}

fun count(): Int {
return this.query.count()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,22 @@ import org.jooq.impl.DefaultTransactionProvider
import java.sql.SQLException
import kotlin.reflect.full.createInstance


/*
* @author: Cloudopt
* @Time: 2018/2/6
* @Description: Jooq plugin of cloudopt next
*/
class JooqPlugin : Plugin {

override fun start(): Boolean {

System.getProperties().setProperty("org.jooq.no-logo", "true")

try {
var map = ConfigManager.init("jooq")
val map = ConfigManager.init("jooq")

pool = HikariCPPool()

if (map["pool"] != null) {
pool = Classer.loadClass(map["pool"] as String).createInstance() as ConnectionPool
}

var sqlDialect = when (map["database"]) {
val sqlDialect = when (map["database"]) {
"mysql" -> SQLDialect.MYSQL
"derby" -> SQLDialect.DERBY
"firebird" -> SQLDialect.FIREBIRD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package net.cloudopt.next.jooq.test

import net.cloudopt.next.health.HealthChecksManager
import net.cloudopt.next.jooq.DBHealthIndicator
import net.cloudopt.next.jooq.JooqPlugin
import net.cloudopt.next.web.NextServer
import net.cloudopt.next.web.health.HealthChecksManager
import net.cloudopt.next.web.health.HealthChecksPlugin
import net.cloudopt.next.health.HealthChecksPlugin


/*
Expand Down

0 comments on commit 487bc58

Please sign in to comment.