Skip to content

Commit 4df5905

Browse files
committed
Readme updated
1 parent f97f48c commit 4df5905

34 files changed

+216
-201
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Support MongoDB 2.6 to 4.2.
1111
* Easy Database setup
1212
* DAO Pattern for collection
1313
* DAO Pattern for GridFS
14+
* GridFS: Upload from InputStream, Download to OutputStream
1415
* Implicit conversions for Document, Bson, ObjectID ...
1516
* Example Apps
1617

@@ -40,9 +41,8 @@ Scala Version is 2.13.x / 2.12.x.
4041
Add following lines to your build.sbt
4142

4243
```
43-
resolvers += "sxfcode Bintray Repo" at "https://dl.bintray.com/sfxcode/maven/"
4444
45-
libraryDependencies += "com.sfxcode.nosql" %% "simple-mongo" % "1.6.5"
45+
libraryDependencies += "com.sfxcode.nosql" %% "simple-mongo" % "1.8.0"
4646
4747
```
4848

src/main/scala/com/sfxcode/nosql/mongo/Aggregate.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ object Aggregate extends Aggregate
99
trait Aggregate extends Field with Filter with Sort {
1010

1111
def compositeProjection(resultFieldName: String, keys: List[String]): Bson =
12-
computed(resultFieldName,
13-
Map[String, Any]("$concat" -> keys.map(key => Map[String, Any]("$substr" -> List("$" + key, 0, 99999)))))
12+
computed(
13+
resultFieldName,
14+
Map[String, Any]("$concat" -> keys.map(key => Map[String, Any]("$substr" -> List("$" + key, 0, 99999)))))
1415

1516
def divideProjection(resultFieldName: String, dividendFieldName: String, divisorFieldName: String): Bson =
1617
computed(resultFieldName, Map[String, Any]("$divide" -> List("$" + dividendFieldName, "$" + divisorFieldName)))

src/main/scala/com/sfxcode/nosql/mongo/GridFSDAO.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class GridFSDAO(provider: DatabaseProvider, bucketName: String) extends
1313
var bucket: GridFSBucket = {
1414
if (bucketName.contains(DatabaseProvider.CollectionSeparator)) {
1515
val newDatabaseName = bucketName.substring(0, bucketName.indexOf(DatabaseProvider.CollectionSeparator))
16-
val newBucketName = bucketName.substring(bucketName.indexOf(DatabaseProvider.CollectionSeparator) + 1)
16+
val newBucketName = bucketName.substring(bucketName.indexOf(DatabaseProvider.CollectionSeparator) + 1)
1717
GridFSBucket(provider.database(newDatabaseName), newBucketName)
1818
} else {
1919
GridFSBucket(provider.database(), bucketName)

src/main/scala/com/sfxcode/nosql/mongo/MongoDAO.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import org.mongodb.scala.{ Document, MongoCollection }
77
import scala.reflect.ClassTag
88

99
/**
10-
* Created by tom on 20.01.17.
11-
*/
10+
* Created by tom on 20.01.17.
11+
*/
1212
abstract class MongoDAO[A](provider: DatabaseProvider, collectionName: String)(implicit ct: ClassTag[A])
13-
extends Crud[A] {
13+
extends Crud[A] {
1414

1515
val collection: MongoCollection[A] = {
1616
if (collectionName.contains(DatabaseProvider.CollectionSeparator)) {
17-
val newDatabaseName = collectionName.substring(0, collectionName.indexOf(DatabaseProvider.CollectionSeparator))
17+
val newDatabaseName = collectionName.substring(0, collectionName.indexOf(DatabaseProvider.CollectionSeparator))
1818
val newCollectionName = collectionName.substring(collectionName.indexOf(DatabaseProvider.CollectionSeparator) + 1)
1919
provider.database(newDatabaseName).getCollection[A](newCollectionName)
2020
} else {

src/main/scala/com/sfxcode/nosql/mongo/bson/BsonConverter.scala

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@ object BsonConverter {
2727
}
2828
case v: Any if converterPlugin.hasCustomClass(v) =>
2929
converterPlugin.toBson(v)
30-
case b: Boolean => BsonBoolean(b)
31-
case s: String => BsonString(s)
32-
case c: Char => BsonString(c.toString)
30+
case b: Boolean => BsonBoolean(b)
31+
case s: String => BsonString(s)
32+
case c: Char => BsonString(c.toString)
3333
case bytes: Array[Byte] => BsonBinary(bytes)
34-
case r: Regex => BsonRegularExpression(r)
35-
case d: Date => BsonDateTime(d)
34+
case r: Regex => BsonRegularExpression(r)
35+
case d: Date => BsonDateTime(d)
3636
case ld: LocalDate =>
3737
BsonDateTime(Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant))
3838
case ldt: LocalDateTime =>
3939
BsonDateTime(Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant))
40-
case oid: ObjectId => BsonObjectId(oid)
41-
case i: Int => BsonInt32(i)
42-
case l: Long => BsonInt64(l)
43-
case bi: BigInt => BsonInt64(bi.toLong)
44-
case bi: BigInteger => BsonInt64(bi.longValue())
45-
case d: Double => BsonDouble(d)
46-
case f: Float => BsonDouble(f)
47-
case bd: BigDecimal => BsonDecimal128.apply(bd)
40+
case oid: ObjectId => BsonObjectId(oid)
41+
case i: Int => BsonInt32(i)
42+
case l: Long => BsonInt64(l)
43+
case bi: BigInt => BsonInt64(bi.toLong)
44+
case bi: BigInteger => BsonInt64(bi.longValue())
45+
case d: Double => BsonDouble(d)
46+
case f: Float => BsonDouble(f)
47+
case bd: BigDecimal => BsonDecimal128.apply(bd)
4848
case bd: java.math.BigDecimal => BsonDecimal128.apply(bd)
49-
case doc: Document => BsonDocument(doc)
49+
case doc: Document => BsonDocument(doc)
5050
case map: Map[_, _] =>
5151
var doc = Document()
5252
map.keys.foreach(key => {
@@ -76,22 +76,22 @@ object BsonConverter {
7676
def fromBson(value: BsonValue): Any =
7777
value match {
7878

79-
case b: BsonBoolean => b.getValue
80-
case s: BsonString => s.getValue
81-
case bytes: BsonBinary => bytes.getData
79+
case b: BsonBoolean => b.getValue
80+
case s: BsonString => s.getValue
81+
case bytes: BsonBinary => bytes.getData
8282
case r: BsonRegularExpression => r.getPattern
83-
case d: BsonDateTime => new Date(d.getValue)
84-
case d: BsonTimestamp => new Date(d.getTime)
85-
case oid: BsonObjectId => oid.getValue
86-
case i: BsonInt32 => i.getValue
87-
case l: BsonInt64 => l.getValue
88-
case d: BsonDouble => d.doubleValue()
89-
case d: BsonDecimal128 => d.getValue.bigDecimalValue()
90-
case doc: BsonDocument => Document(doc)
83+
case d: BsonDateTime => new Date(d.getValue)
84+
case d: BsonTimestamp => new Date(d.getTime)
85+
case oid: BsonObjectId => oid.getValue
86+
case i: BsonInt32 => i.getValue
87+
case l: BsonInt64 => l.getValue
88+
case d: BsonDouble => d.doubleValue()
89+
case d: BsonDecimal128 => d.getValue.bigDecimalValue()
90+
case doc: BsonDocument => Document(doc)
9191
case array: BsonArray =>
9292
array.getValues.asScala.toList.map(v => fromBson(v))
9393
case n: BsonNull => null
94-
case _ => value
94+
case _ => value
9595
}
9696

9797
def asMap(document: Document): Map[String, Any] = {

src/main/scala/com/sfxcode/nosql/mongo/bson/codecs/BigDecimalCodec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import org.bson.codecs.{ Codec, DecoderContext, EncoderContext }
44
import org.bson.{ BsonReader, BsonWriter }
55

66
/**
7-
* A Codec for BigDecimal instances.
8-
*
9-
*/
7+
* A Codec for BigDecimal instances.
8+
*
9+
*/
1010
class BigDecimalCodec extends Codec[BigDecimal] {
1111

1212
override def decode(reader: BsonReader, decoderContext: DecoderContext): BigDecimal =

src/main/scala/com/sfxcode/nosql/mongo/bson/codecs/BigIntCodec.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import org.bson.codecs.{ Codec, DecoderContext, EncoderContext }
44
import org.bson.{ BsonReader, BsonWriter }
55

66
/**
7-
* A Codec for BigInt instances.
8-
*
9-
* @since 3.0
10-
*/
7+
* A Codec for BigInt instances.
8+
*
9+
* @since 3.0
10+
*/
1111
class BigIntCodec extends Codec[BigInt] {
1212

1313
override def decode(reader: BsonReader, decoderContext: DecoderContext): BigInt =

src/main/scala/com/sfxcode/nosql/mongo/bson/codecs/CustomCodecProvider.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import org.bson.codecs.configuration.{ CodecProvider, CodecRegistry }
55

66
case class CustomCodecProvider() extends CodecProvider {
77

8-
val BigIntClass: Class[BigInt] = classOf[BigInt]
8+
val BigIntClass: Class[BigInt] = classOf[BigInt]
99
val BigDecimalClass: Class[BigDecimal] = classOf[BigDecimal]
1010

1111
// scalastyle:off null
1212
@SuppressWarnings(Array("unchecked"))
1313
def get[T](clazz: Class[T], registry: CodecRegistry): Codec[T] =
1414
clazz match {
15-
case BigIntClass => new BigIntCodec().asInstanceOf[Codec[T]]
15+
case BigIntClass => new BigIntCodec().asInstanceOf[Codec[T]]
1616
case BigDecimalClass => new BigDecimalCodec().asInstanceOf[Codec[T]]
17-
case _ => null
17+
case _ => null
1818
}
1919
// scalastyle:on null
2020
}

src/main/scala/com/sfxcode/nosql/mongo/database/DatabaseProvider.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class DatabaseProvider(config: MongoConfig, registry: CodecRegistry) extends Ser
6060
database(name).listCollectionNames()
6161

6262
case class DocumentDao(provider: DatabaseProvider, collectionName: String)
63-
extends MongoDAO[Document](this, collectionName)
63+
extends MongoDAO[Document](this, collectionName)
6464

6565
}
6666

@@ -75,8 +75,9 @@ object DatabaseProvider {
7575
def apply(config: MongoConfig, registry: CodecRegistry = codecRegistry): DatabaseProvider =
7676
new DatabaseProvider(config, fromRegistries(registry, CustomRegistry, DEFAULT_CODEC_REGISTRY))
7777

78-
def fromPath(configPath: String = MongoConfig.DefaultConfigPathPrefix,
79-
registry: CodecRegistry = codecRegistry): DatabaseProvider =
78+
def fromPath(
79+
configPath: String = MongoConfig.DefaultConfigPathPrefix,
80+
registry: CodecRegistry = codecRegistry): DatabaseProvider =
8081
apply(MongoConfig.fromPath(configPath), fromRegistries(registry, CustomRegistry, DEFAULT_CODEC_REGISTRY))
8182

8283
}

src/main/scala/com/sfxcode/nosql/mongo/database/MongoConfig.scala

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import org.mongodb.scala.{ MongoClientSettings, MongoCredential, ServerAddress }
1010

1111
import scala.collection.JavaConverters._
1212

13-
case class MongoConfig(database: String,
14-
host: String = DefaultHost,
15-
port: Int = DefaultPort,
16-
applicationName: String = DefaultApplicationName,
17-
userName: Option[String] = None,
18-
password: Option[String] = None,
19-
authDatabase: String = DefaultAuthenticationDatabaseName,
20-
poolOptions: MongoPoolOptions = MongoPoolOptions(),
21-
customClientSettings: Option[MongoClientSettings] = None) {
13+
case class MongoConfig(
14+
database: String,
15+
host: String = DefaultHost,
16+
port: Int = DefaultPort,
17+
applicationName: String = DefaultApplicationName,
18+
userName: Option[String] = None,
19+
password: Option[String] = None,
20+
authDatabase: String = DefaultAuthenticationDatabaseName,
21+
poolOptions: MongoPoolOptions = MongoPoolOptions(),
22+
customClientSettings: Option[MongoClientSettings] = None) {
2223

2324
val clientSettings: MongoClientSettings = {
2425
if (customClientSettings.isDefined) {
@@ -39,8 +40,7 @@ case class MongoConfig(database: String,
3940
.builder()
4041
.applicationName(applicationName)
4142
.applyToConnectionPoolSettings(
42-
(b: com.mongodb.connection.ConnectionPoolSettings.Builder) => b.applySettings(connectionPoolSettings)
43-
)
43+
(b: com.mongodb.connection.ConnectionPoolSettings.Builder) => b.applySettings(connectionPoolSettings))
4444
.applyToClusterSettings((b: com.mongodb.connection.ClusterSettings.Builder) => b.applySettings(clusterSettings))
4545

4646
if (userName.isDefined && password.isDefined) {
@@ -55,15 +55,15 @@ case class MongoConfig(database: String,
5555
}
5656

5757
object MongoConfig {
58-
val DefaultHost = "127.0.0.1"
59-
val DefaultPort = 27017
58+
val DefaultHost = "127.0.0.1"
59+
val DefaultPort = 27017
6060
val DefaultAuthenticationDatabaseName = "admin"
61-
val DefaultApplicationName = "simple-mongo-app"
61+
val DefaultApplicationName = "simple-mongo-app"
6262

63-
val DefaultPoolMaxConnectionIdleTime = 60
64-
val DefaultPoolMaxSize = 50
65-
val DefaultPoolMinSize = 0
66-
val DefaultPoolMaxWaitQueueSize = 500
63+
val DefaultPoolMaxConnectionIdleTime = 60
64+
val DefaultPoolMaxSize = 50
65+
val DefaultPoolMinSize = 0
66+
val DefaultPoolMaxWaitQueueSize = 500
6767
val DefaultPoolMaintenanceInitialDelay = 0
6868

6969
val DefaultConfigPathPrefix = "mongo"
@@ -96,20 +96,19 @@ object MongoConfig {
9696
DefaultPort
9797
}
9898

99-
val host = stringConfig("host", DefaultHost).get
100-
val port = portConfig
101-
val database = stringConfig("database").get
102-
val userName = stringConfig("userName")
103-
val password = stringConfig("password")
104-
val authDatabase = stringConfig("authDatabase", DefaultAuthenticationDatabaseName).get
99+
val host = stringConfig("host", DefaultHost).get
100+
val port = portConfig
101+
val database = stringConfig("database").get
102+
val userName = stringConfig("userName")
103+
val password = stringConfig("password")
104+
val authDatabase = stringConfig("authDatabase", DefaultAuthenticationDatabaseName).get
105105
val applicationName = stringConfig("applicationName", DefaultApplicationName).get
106106

107107
val poolOptions = MongoPoolOptions(
108108
poolOptionsConfig("maxConnectionIdleTime", DefaultPoolMaxConnectionIdleTime),
109109
poolOptionsConfig("maxSize", DefaultPoolMaxSize),
110110
poolOptionsConfig("minSize", DefaultPoolMinSize),
111-
poolOptionsConfig("maintenanceInitialDelay", DefaultPoolMaintenanceInitialDelay)
112-
)
111+
poolOptionsConfig("maintenanceInitialDelay", DefaultPoolMaintenanceInitialDelay))
113112

114113
MongoConfig(database, host, port, applicationName, userName, password, authDatabase, poolOptions)
115114
}

0 commit comments

Comments
 (0)