Skip to content

Commit b048977

Browse files
authored
Merge pull request #73 from MongoCamp/scala3
Scala3
2 parents db8112a + d433d73 commit b048977

File tree

159 files changed

+5033
-3127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+5033
-3127
lines changed

.github/workflows/main_test_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
mongodb-version: [ '4.4', '5.0', '6.0', '7.0' , '8.0' ]
16+
mongodb-version: ['4.4', '5.0', '6.0', '7.0', '8.0']
1717
java: [ '21', '23' ]
1818
steps:
1919
- uses: actions/checkout@main

.github/workflows/other_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
mongodb-version: [ '4.4', '5.0', '6.0', '7.0' , '8.0' ]
16+
mongodb-version: [ '4.4', '5.0', '6.0', '7.0', '8.0' ]
1717
java: [ '21', '23' ]
1818
steps:
1919
- uses: actions/checkout@main

README.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
A library for easy usage of the mongo-scala-driver (5.1.xa). Full MongoDB Functionality in Scala with a few lines of code.
44

55
## MongoDB Support
6-
7-
Support MongoDB 3.6 to 7.0.x.
8-
6+
We currently testing with '4.4', '5.0', '6.0', '7.0' and '8.0'.
97

108
## Features
119

@@ -28,7 +26,7 @@ Documentation can be found [here](https://mongodb-driver.mongocamp.dev/).
2826

2927
## Version
3028

31-
Scala Version is 2.13.x / 2.12.x.
29+
Scala Version is 3.6.x / 2.13.x
3230

3331
## CI
3432

@@ -46,7 +44,7 @@ Add following lines to your build.sbt (replace x.x with the actual Version)
4644

4745
```
4846
49-
libraryDependencies += "dev.mongocamp" %% "mongodb-driver" % "2.x.x"
47+
libraryDependencies += "dev.mongocamp" %% "mongodb-driver" % "3.x.x"
5048
5149
```
5250

@@ -61,6 +59,8 @@ import dev.mongocamp.driver.mongodb.database.DatabaseProvider
6159
import org.bson.codecs.configuration.CodecRegistries._
6260
import org.mongodb.scala.bson.ObjectId
6361
import org.mongodb.scala.bson.codecs.Macros._
62+
import dev.mongocamp.driver.mongodb.json._
63+
import io.circe.generic.auto._
6464

6565
/**
6666
* import mongodb restaurants sample data
@@ -71,12 +71,9 @@ object RestaurantDatabase {
7171

7272
case class Grade(date: Date, grade: String, score: Int)
7373

74-
case class Restaurant(restaurant_id: String, name: String, borough: String, cuisine: String,
75-
grades: List[Grade], address: Address, _id: ObjectId = new ObjectId())
76-
77-
private val registry = fromProviders(classOf[Restaurant], classOf[Address], classOf[Grade])
74+
case class Restaurant(restaurant_id: String, name: String, borough: String, cuisine: String, grades: List[Grade], address: Address, _id: ObjectId = new ObjectId())
7875

79-
val provider = DatabaseProvider("test", registry)
76+
val provider = DatabaseProvider.fromPath("dev.mongocamp")
8077

8178
object RestaurantDAO extends MongoDAO[Restaurant](provider, "restaurants")
8279

@@ -88,7 +85,6 @@ object RestaurantDatabase {
8885
Import the database object and execute some find and CRUD functions on the DAO object ...
8986

9087
```scala
91-
9288
import dev.mongocamp.driver.mongodb.demo.restaurant.RestaurantDemoDatabase._
9389
import dev.mongocamp.driver.mongodb._
9490

@@ -97,17 +93,14 @@ trait RestaurantDemoDatabaseFunctions {
9793
/**
9894
* single result with implicit conversion to Entity Option
9995
*/
100-
def findRestaurantByName(name: String): Option[Restaurant] =
101-
RestaurantDAO.find("name", name)
96+
def findRestaurantByName(name: String): Option[Restaurant] = RestaurantDAO.find("name", name)
10297

10398
def restaurantsSize: Long = RestaurantDAO.count()
10499

105100
/**
106101
* result with implicit conversion to List of Entities
107102
*/
108-
def findAllRestaurants(filterValues: Map[String, Any] = Map()): List[Restaurant] =
109-
RestaurantDAO.find(filterValues)
110-
103+
def findAllRestaurants(filterValues: Map[String, Any] = Map()): List[Restaurant] = RestaurantDAO.find(filterValues)
111104
```
112105

113106

@@ -137,7 +130,6 @@ Use the mongodb functions in your app ...
137130
Write some spec tests ...
138131

139132
```scala
140-
141133
import dev.mongocamp.driver.mongodb.demo.restaurant.RestaurantDemoDatabase._
142134
import org.specs2.mutable.Specification
143135

@@ -159,9 +151,9 @@ class RestaurantDemoSpec extends Specification with RestaurantDemoDatabaseFuncti
159151

160152
## Run Tests
161153
```shell
162-
docker run -d --publish 27017:27017 --name mongodb mongocamp/mongodb:latest;
163-
sbt test;
164154
docker rm -f mongodb;
155+
docker run -d --publish 27017:27017 --name mongodb mongocamp/mongodb:latest;
156+
sbt +test
165157
```
166158

167159
## Supporters

build.sbt

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ developers := List(
4040

4141
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html"))
4242

43-
crossScalaVersions := Seq("2.13.15", "2.12.20")
43+
//crossScalaVersions := Seq("2.13.16")
44+
crossScalaVersions := Seq("3.6.0", "2.13.16")
4445

4546
scalaVersion := crossScalaVersions.value.head
4647

@@ -59,12 +60,6 @@ buildInfoOptions += BuildInfoOption.BuildTime
5960

6061
resolvers += "Sonatype OSS Snapshots".at("https://oss.sonatype.org/content/repositories/snapshots")
6162

62-
// Test
63-
64-
libraryDependencies += "org.specs2" %% "specs2-core" % "4.20.9" % Test
65-
66-
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.5.12" % Test
67-
6863
libraryDependencies += "joda-time" % "joda-time" % "2.13.0"
6964

7065
val circeVersion = "0.14.10"
@@ -75,34 +70,31 @@ libraryDependencies ++= Seq(
7570
"io.circe" %% "circe-parser"
7671
).map(_ % circeVersion)
7772

78-
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "5.1.4"
73+
libraryDependencies += ("org.mongodb.scala" %% "mongo-scala-driver" % "5.3.1").cross(CrossVersion.for3Use2_13)
7974

80-
// MongoDB 5.2.0 not supported for de.bwaldvogel -> https://github.com/bwaldvogel/mongo-java-server/issues/233
81-
val MongoJavaServerVersion = "1.45.0"
75+
val MongoJavaServerVersion = "1.46.0"
8276

8377
libraryDependencies += "de.bwaldvogel" % "mongo-java-server" % MongoJavaServerVersion % Provided
8478

8579
libraryDependencies += "de.bwaldvogel" % "mongo-java-server-h2-backend" % MongoJavaServerVersion % Provided
8680

8781
libraryDependencies += "org.xerial.snappy" % "snappy-java" % "1.1.10.7" % Provided
8882

89-
libraryDependencies += "com.github.luben" % "zstd-jni" % "1.5.6-7" % Provided
83+
libraryDependencies += "com.github.luben" % "zstd-jni" % "1.5.6-9" % Provided
9084

91-
libraryDependencies += "org.apache.lucene" % "lucene-queryparser" % "10.0.0"
85+
libraryDependencies += "org.apache.lucene" % "lucene-queryparser" % "10.1.0"
9286

9387
libraryDependencies += "com.github.pathikrit" %% "better-files" % "3.9.2"
9488

9589
libraryDependencies += "com.typesafe" % "config" % "1.4.3"
9690

9791
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5"
9892

99-
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.12.0"
93+
//libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.12.0"
10094

10195
libraryDependencies += "com.vdurmont" % "semver4j" % "3.1.0"
10296

103-
libraryDependencies += "com.github.jsqlparser" % "jsqlparser" % "5.0"
104-
105-
libraryDependencies += "org.liquibase" % "liquibase-core" % "4.30.0" % Test
97+
libraryDependencies += "com.github.jsqlparser" % "jsqlparser" % "5.1"
10698

10799
buildInfoPackage := "dev.mongocamp.driver.mongodb"
108100

build_release.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import com.vdurmont.semver4j.Semver
22
import dev.quadstingray.sbt.json.JsonFile
33
import sbtrelease.ReleasePlugin.autoImport.ReleaseKeys.versions
4-
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations.*
4+
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
55
import sbtrelease.ReleasePlugin.runtimeVersion
66

7-
import scala.sys.process.*
7+
import scala.sys.process._
88

99
releaseVersionBump := sbtrelease.Version.Bump.NextStable
1010

build_test.sbt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Test / parallelExecution := false
2+
3+
libraryDependencies += "org.liquibase" % "liquibase-core" % "4.31.0" % Test
4+
5+
// Test
6+
7+
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.5.16" % Test
8+
9+
libraryDependencies += "org.scalameta" %% "munit" % "1.1.0"

docs/documentation/collection/aggregation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ MongoDB support an easy to use [Aggregation Handling](https://docs.mongodb.com/m
77
## Demo
88

99
### Setup imports
10-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/operation/AggregationSpec.scala#agg_imports
10+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/operation/AggregationSuite.scala#agg_imports
1111

1212
### Define stages
13-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/operation/AggregationSpec.scala#agg_stages
13+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/operation/AggregationSuite.scala#agg_stages
1414

1515
### Execute Aggregation
1616

@@ -19,10 +19,10 @@ MongoDB support an easy to use [Aggregation Handling](https://docs.mongodb.com/m
1919
:::
2020

2121

22-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/operation/AggregationSpec.scala#agg_execute
22+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/operation/AggregationSuite.scala#agg_execute
2323

2424
### Convert Result
2525

2626
For easy result handling, using the implicit Document to Map conversion can be useful.
2727

28-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/operation/AggregationSpec.scala#agg_convert
28+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/operation/AggregationSuite.scala#agg_convert

docs/documentation/collection/analyse-schema.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The driver supports an automated detection of the schema of an existing collecti
66
### Schema Analysis
77
Analyse a collection to detect the values for each field and the percentage distribution of the types.
88

9-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/schema/SchemaSpec.scala#schema-analysis
9+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/schema/SchemaSuite.scala#schema-analysis
1010

1111
### Detect Schema
1212
The Schema Detector can be used to detect the schema of a collection and is based on [Schema Anaysis](analyse-schema.md#schema-analysis). The schema is used to detect the types of the columns and generate a [JSON Schema](https://json-schema.org) for the collection. In case of multiple types of a field the Generation of the JSON Schema use the type with the most elements.
@@ -15,4 +15,4 @@ The Schema Detector can be used to detect the schema of a collection and is base
1515
The [JSON Schema](https://json-schema.org) format can be use to validate or generate data, as well to secure your [Mongo Collection](https://www.mongodb.com/docs/manual/core/schema-validation/).
1616
:::
1717

18-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/schema/SchemaSpec.scala#schema-explorer
18+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/schema/SchemaSuite.scala#schema-explorer

docs/documentation/collection/pagination.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ In many cases you want to have the possibility to paginate over the response of
88
The Pagination over an aggregation pipeline supports only the response of `Document`, also if you use an case class MongoDAO you will got an `Document` back.
99
:::
1010

11-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/pagination/PaginationAggregationSpec.scala#aggregation-pagination
11+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/pagination/PaginationAggregationSuite.scala#aggregation-pagination
1212

1313
## Find Pagination
1414

15-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/pagination/PaginationFilterSpec.scala#filter-pagination
15+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/pagination/PaginationFilterSuite.scala#filter-pagination
1616

1717
## Foreach over Pagination result
1818

1919
### With default row count
20-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/pagination/PaginationIterationSpec.scala#foreach-default-rows
20+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/pagination/PaginationIterationSuite.scala#foreach-default-rows
2121

2222
### With specific row count
23-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/pagination/PaginationIterationSpec.scala#foreach-with-rows
23+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/pagination/PaginationIterationSuite.scala#foreach-with-rows

docs/documentation/database/bson.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,36 @@ BSON converter is used for bidirectional converting of BSON data.
1414
### toBson
1515

1616
```scala
17-
val result = BsonConverter.toBson(3) // result = BsonInt32(3)
17+
val result = BsonConverter.toBson(3) // result = BsonInt32(3)
1818
```
1919

2020

2121
### fromBson
2222

2323
```scala
24-
val result = BsonConverter.fromBson(BsonInt32(3)) // result = 3
24+
val result = BsonConverter.fromBson(BsonInt32(3)) // result = 3
2525
```
2626

2727
### toDocument
2828

2929
```scala
30-
case class Base(int: Int, Long: Long, float: Float, double: Double,
31-
string: String, date: Date = new Date())
3230

33-
object Base {
34-
def apply(): Base = new Base(1, 2, 3, 4, "test")
35-
}
31+
case class Base(int: Int, Long: Long, float: Float, double: Double, string: String, date: Date = new Date())
3632

37-
val document = Converter.toDocument(Base())
33+
object Base {
34+
def apply(): Base = new Base(1, 2, 3, 4, "test")
35+
}
3836

39-
// Document((float,BsonDouble{value=3.0}), (string,BsonString{value='test'}),
40-
// (double,BsonDouble{value=4.0}), (Long,BsonInt64{value=2}), (date,
41-
// BsonDateTime{value=1531166757627}), (int,BsonInt32{value=1}))
37+
val document = Converter.toDocument(Base())
38+
39+
// Document(
40+
// (float,BsonDouble{value=3.0}),
41+
// (string,BsonString{value='test'}),
42+
// (double,BsonDouble{value=4.0}),
43+
// (Long,BsonInt64{value=2}),
44+
// (date, BsonDateTime{value=1531166757627}),
45+
// (int,BsonInt32{value=1})
46+
// )
4247
```
4348

4449
## Plugins

docs/documentation/database/config.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mongo.db.test {
4040

4141
Scala Code Snippet
4242
```scala
43-
val customConfig: MongoConfig = MongoConfig.fromPath("mongodb.db.prod")
43+
val customConfig: MongoConfig = MongoConfig.fromPath("mongodb.db.prod")
4444
```
4545

4646

@@ -76,5 +76,3 @@ It is used for DatabaseProvider creation.
7676
| minSize | 0 |
7777
| DefaultMaintenanceInitialDelay | 0 |
7878

79-
## Multiple databases access
80-

docs/documentation/database/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ DatabaseProvider is the central repository for MongoClient, registries, database
1313
Every [Mongo DAO](../mongo-dao/index.md) / [GridFs DAO](../gridfs-dao/index.md) Instance needs this class.
1414

1515
```scala
16-
val provider: DatabaseProvider = DatabaseProvider(MongoConfig.fromPath())
16+
val provider: DatabaseProvider = DatabaseProvider(MongoConfig.fromPath())
1717

18-
val database: MongoDatabase = provider.database()
18+
val database: MongoDatabase = provider.database()
1919

20-
// Infos for all collections in the default database
21-
val collectionInfos: List[CollectionInfo] = provider.collectionInfos()
20+
// Infos for all collections in the default database
21+
val collectionInfos: List[CollectionInfo] = provider.collectionInfos()
2222
```

docs/documentation/database/lucene.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ MongoCamp Mongo Driver support the usage of [Lucene Query](https://lucene.apache
66
### Explicit Usage
77
The LuceneConverter has the methods to parse a String to and `Query` and a other to the document conversion.
88

9-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/lucene/LuceneSearchSpec.scala#lucene-parser-with-explicit
9+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/lucene/LuceneSearchSuite.scala#lucene-parser-with-explicit
1010

1111
### Implicit Usage
1212
Like the Map to Bson conversion there is also an implicit method to convert `Query` to find Bson.
1313

14-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/lucene/LuceneSearchSpec.scala#lucene-parser-with-implicit
14+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/lucene/LuceneSearchSuite.scala#lucene-parser-with-implicit
1515

1616
### Parse String to Query
1717
We have an individual parser to parse an string to Lucene Query, because the default Lucene Analyser is case-insensitive and convert all search data into lower case. So the best way to seach in MongoDb with Lucene Query is to use this code.
1818

19-
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/lucene/LuceneSearchSpec.scala#lucene-parser
19+
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/lucene/LuceneSearchSuite.scala#lucene-parser
2020

2121
## Read More
2222
[Lucene Cheatsheet](https://www.lucenetutorial.com/lucene-query-syntax.html)

0 commit comments

Comments
 (0)