Skip to content

Commit 32e023f

Browse files
committed
1 parent 91a1e35 commit 32e023f

16 files changed

Lines changed: 66 additions & 71 deletions

File tree

conf/common/database/schema/function/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

conf/common/database/schema/procedure/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

conf/common/database/schema/table/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

conf/common/database/schema/table/column/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

conf/common/database/schema/table/pk/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/main/kotlin/com/github/mgramin/sqlboot/model/resource/impl/FakeDbResource.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package com.github.mgramin.sqlboot.model.resource.impl
2626

2727
import com.github.mgramin.sqlboot.model.resource.DbResource
2828
import com.github.mgramin.sqlboot.model.resourcetype.ResourceType
29-
import com.github.mgramin.sqlboot.model.resourcetype.impl.FakeDbResourceType
29+
import com.github.mgramin.sqlboot.model.resourcetype.impl.FakeResourceType
3030
import com.github.mgramin.sqlboot.model.uri.Uri
3131
import com.google.common.collect.ImmutableMap.of
3232

@@ -40,7 +40,7 @@ class FakeDbResource(private val uri: Uri) : DbResource {
4040
}
4141

4242
override fun type(): ResourceType {
43-
return FakeDbResourceType()
43+
return FakeResourceType()
4444
}
4545

4646
override fun dbUri(): Uri {

src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/impl/FakeDbResourceType.kt renamed to src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/impl/FakeResourceType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import java.util.Arrays.asList
3636
/**
3737
* Created by maksim on 22.05.17.
3838
*/
39-
class FakeDbResourceType : ResourceType {
39+
class FakeResourceType : ResourceType {
4040

4141
override fun aliases(): List<String> {
4242
return asList("fake_resource_type", "fake_type", "frt", "f")

src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/impl/composite/FsResourceTypes.kt renamed to src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/impl/FsResourceType.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@
2222
* SOFTWARE.
2323
*/
2424

25-
package com.github.mgramin.sqlboot.model.resourcetype.impl.composite
25+
package com.github.mgramin.sqlboot.model.resourcetype.impl
2626

2727
import com.github.mgramin.sqlboot.exceptions.BootException
2828
import com.github.mgramin.sqlboot.model.connection.SimpleDbConnection
2929
import com.github.mgramin.sqlboot.model.resource.DbResource
3030
import com.github.mgramin.sqlboot.model.resourcetype.ResourceType
31-
import com.github.mgramin.sqlboot.model.resourcetype.impl.composite.md.MarkdownFile
32-
import com.github.mgramin.sqlboot.model.resourcetype.impl.sql.SqlResourceType
3331
import com.github.mgramin.sqlboot.model.resourcetype.wrappers.body.BodyWrapper
3432
import com.github.mgramin.sqlboot.model.resourcetype.wrappers.header.SelectWrapper
3533
import com.github.mgramin.sqlboot.model.resourcetype.wrappers.list.SortWrapper
3634
import com.github.mgramin.sqlboot.model.uri.Uri
3735
import com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator
36+
import com.github.mgramin.sqlboot.tools.files.file.impl.MarkdownFile
3837
import com.github.mgramin.sqlboot.tools.files.file.impl.SimpleFile
3938
import reactor.core.publisher.Flux
4039
import java.io.File
@@ -44,7 +43,7 @@ import java.nio.charset.StandardCharsets.UTF_8
4443
/**
4544
* Created by MGramin on 11.07.2017.
4645
*/
47-
class FsResourceTypes(
46+
class FsResourceType(
4847
private val dbConnections: List<SimpleDbConnection>,
4948
private val uri: Uri
5049
) : ResourceType {
@@ -86,11 +85,12 @@ class FsResourceTypes(
8685

8786
override fun read(uri: Uri): Flux<DbResource> {
8887
try {
89-
return resourceTypes
90-
.asSequence()
91-
.first { v -> v.name().equals(uri.type(), ignoreCase = true) }
92-
.read(uri)
93-
} catch (e : Exception) {
88+
return Flux.merge(
89+
resourceTypes
90+
.filter { v -> v.name().matches(uri.type().replace("?", ".?").replace("*", ".*?").toRegex()) }
91+
.map { it.read(uri) }
92+
.toList())
93+
} catch (e: Exception) {
9494
throw BootException("Type not found", 404)
9595
}
9696
}
@@ -101,7 +101,7 @@ class FsResourceTypes(
101101
.asSequence()
102102
.first { v -> v.name().equals(uri.type(), ignoreCase = true) }
103103
.metaData()
104-
} catch (e : Exception) {
104+
} catch (e: Exception) {
105105
throw BootException("Type not found", 404)
106106
}
107107
}

src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/impl/sql/SqlResourceType.kt renamed to src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/impl/SqlResourceType.kt

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424

25-
package com.github.mgramin.sqlboot.model.resourcetype.impl.sql
25+
package com.github.mgramin.sqlboot.model.resourcetype.impl
2626

2727
import com.github.mgramin.sqlboot.model.connection.DbConnection
2828
import com.github.mgramin.sqlboot.model.resource.DbResource
@@ -61,25 +61,19 @@ class SqlResourceType(
6161
}
6262

6363
override fun read(uri: Uri): Flux<DbResource> {
64-
val mergeSequential: Flux<Map<String, Any>> =
65-
Flux.merge(
66-
connections
67-
.asSequence()
68-
.map { connection ->
69-
return@map createQuery(uri, connection).execute(hashMapOf("uri" to uri))
70-
.map<Map<String, Any>?> {
71-
val mutableMap = it.toMutableMap()
72-
mutableMap["database"] = connection.name()
73-
mutableMap
74-
}
75-
}
76-
.toList()
77-
78-
)
79-
80-
return mergeSequential
64+
return Flux.merge(
65+
connections
66+
.map { connection ->
67+
return@map createQuery(uri, connection).execute(hashMapOf("uri" to uri))
68+
.map<Map<String, Any>?> {
69+
val mutableMap = it.toMutableMap()
70+
mutableMap["database"] = connection.name()
71+
mutableMap
72+
}
73+
}
74+
.toList())
8175
.map { o ->
82-
val path = o.entries
76+
val path = o!!.entries
8377
.filter { v -> v.key.startsWith("@") }
8478
.map { it.value.toString() }
8579
val name = path[path.size - 1]

src/main/kotlin/com/github/mgramin/sqlboot/rest/controllers/ApiController.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import com.github.mgramin.sqlboot.exceptions.BootException
2828
import com.github.mgramin.sqlboot.model.connection.DbConnectionList
2929
import com.github.mgramin.sqlboot.model.resourcetype.Metadata
3030
import com.github.mgramin.sqlboot.model.resourcetype.ResourceType
31-
import com.github.mgramin.sqlboot.model.resourcetype.impl.composite.FsResourceTypes
31+
import com.github.mgramin.sqlboot.model.resourcetype.impl.FsResourceType
3232
import com.github.mgramin.sqlboot.model.uri.Uri
3333
import com.github.mgramin.sqlboot.model.uri.impl.DbUri
3434
import com.github.mgramin.sqlboot.model.uri.impl.FakeUri
@@ -64,7 +64,7 @@ class ApiController {
6464

6565
@RequestMapping(value = ["/api/{connectionName}/types"])
6666
fun types(@PathVariable connectionName: String): List<ResourceType>? {
67-
return FsResourceTypes(dbConnectionList.getConnectionsByMask(connectionName), FakeUri()).resourceTypes()
67+
return FsResourceType(dbConnectionList.getConnectionsByMask(connectionName), FakeUri()).resourceTypes()
6868
}
6969

7070

@@ -89,7 +89,7 @@ class ApiController {
8989
private fun getListResponseEntityHeaders(uri: Uri): ResponseEntity<List<Map<String, Any>>> {
9090
val connections = dbConnectionList.getConnectionsByMask(uri.connection())
9191
try {
92-
val headers = FsResourceTypes(connections, uri)
92+
val headers = FsResourceType(connections, uri)
9393
.read(uri)
9494
.map { it.headers() }
9595
.collectList()
@@ -109,7 +109,7 @@ class ApiController {
109109

110110

111111
private fun responseEntity(uri: Uri): ResponseEntity<List<Metadata>> {
112-
val fsResourceTypes = FsResourceTypes(
112+
val fsResourceTypes = FsResourceType(
113113
listOf(dbConnectionList.getConnectionByName(uri.connection())), uri)
114114
val resourceType = fsResourceTypes
115115
.resourceTypes()

0 commit comments

Comments
 (0)