Skip to content

Commit d3aba1c

Browse files
committed
new Version
1 parent 912c720 commit d3aba1c

File tree

11 files changed

+53
-53
lines changed

11 files changed

+53
-53
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import com.sfxcode.nosql.mongo.bson.BsonConverter
44
import org.mongodb.scala.Document
55

66
/**
7-
* Created by tom on 20.01.17.
8-
*/
7+
* Created by tom on 20.01.17.
8+
*/
99
object Converter {
1010

1111
def toDocument(value: Any): Document =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import org.mongodb.scala.{ Document, MongoCollection, MongoDatabase }
66
import scala.reflect.ClassTag
77

88
/**
9-
* Created by tom on 20.01.17.
10-
*/
9+
* Created by tom on 20.01.17.
10+
*/
1111
abstract class MongoDAO[A](database: MongoDatabase, collectionName: String)(implicit ct: ClassTag[A]) extends Crud[A] {
1212

1313
val collection: MongoCollection[A] = database.getCollection[A](collectionName)

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

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

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

9696
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 = classOf[BigInt]
8+
val BigIntClass = classOf[BigInt]
99
val BigDecimalClass = 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/gridfs/Base.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ abstract class Base extends LazyLogging {
2222
}
2323

2424
def downloadToStream(
25-
oid: ObjectId,
26-
outputPath: Path,
27-
openOptions: Seq[OpenOption] = List(StandardOpenOption.CREATE, StandardOpenOption.WRITE)
28-
): Observable[Long] = {
25+
oid: ObjectId,
26+
outputPath: Path,
27+
openOptions: Seq[OpenOption] = List(StandardOpenOption.CREATE, StandardOpenOption.WRITE)): Observable[Long] = {
2928
val streamToDownloadTo: AsynchronousFileChannel =
3029
AsynchronousFileChannel.open(outputPath, openOptions: _*)
3130
gridfsBucket.downloadToStream(oid, channelToOutputStream(streamToDownloadTo))

src/main/scala/com/sfxcode/nosql/mongo/gridfs/Crud.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ abstract class Crud extends Search {
1313

1414
def deleteOne(id: ObjectId): Observable[Completed] = gridfsBucket.delete(id)
1515

16-
def insertOne(fileName: String,
17-
stream: InputStream,
18-
metadata: AnyRef = Document(),
19-
chunkSizeBytes: Int = chunkSizeBytes): Observable[ObjectId] = {
16+
def insertOne(
17+
fileName: String,
18+
stream: InputStream,
19+
metadata: AnyRef = Document(),
20+
chunkSizeBytes: Int = chunkSizeBytes): Observable[ObjectId] = {
2021
val streamToUploadFrom: AsyncInputStream = toAsyncInputStream(stream)
2122
val metadataDocument = {
2223
metadata match {
2324
case document: Document => document
24-
case _ => Converter.toDocument(metadata)
25+
case _ => Converter.toDocument(metadata)
2526
}
2627
}
2728
val options: GridFSUploadOptions = new GridFSUploadOptions()

src/main/scala/com/sfxcode/nosql/mongo/gridfs/Metadata.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class Metadata(database: MongoDatabase, bucketName: String) extends Cru
1616

1717
def updateMetadata(oid: ObjectId, value: Any): Observable[UpdateResult] = {
1818
val doc: BsonValue = BsonConverter.toBson(value)
19-
val result = Files.updateOne(equal("_id", oid), set("metadata", doc))
19+
val result = Files.updateOne(equal("_id", oid), set("metadata", doc))
2020
result
2121
}
2222

src/main/scala/com/sfxcode/nosql/mongo/operation/Crud.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ abstract class Crud[A]()(implicit ct: ClassTag[A]) extends Search[A] {
2727

2828
def replaceOne(value: A): Observable[UpdateResult] = {
2929
val document = Converter.toDocument(value)
30-
val oid = document.get("_id").get
30+
val oid = document.get("_id").get
3131
coll.replaceOne(equal("_id", oid), value)
3232
}
3333

3434
def replaceOne(value: A, options: ReplaceOptions): Observable[UpdateResult] = {
3535
val document = Converter.toDocument(value)
36-
val oid = document.get("_id").get
36+
val oid = document.get("_id").get
3737
coll.replaceOne(equal("_id", oid), value, options)
3838
}
3939

0 commit comments

Comments
 (0)