aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuicommon/db/repositories/RepositoryLogging.scala
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-06-13 16:12:20 -0700
committervlad <vlad@driver.xyz>2017-06-13 16:12:20 -0700
commitcd1b635b2ae90d9ac2d8b1779183a1fbd8c5fd5c (patch)
tree062e8dad1a1513e26b0fd08b1742d6ff2ee874f7 /src/main/scala/xyz/driver/pdsuicommon/db/repositories/RepositoryLogging.scala
parent0000a65ab4479a2a40e2d6468036438e9705b4aa (diff)
downloadrest-query-cd1b635b2ae90d9ac2d8b1779183a1fbd8c5fd5c.tar.gz
rest-query-cd1b635b2ae90d9ac2d8b1779183a1fbd8c5fd5c.tar.bz2
rest-query-cd1b635b2ae90d9ac2d8b1779183a1fbd8c5fd5c.zip
Adding domain entitiesv0.1.0
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuicommon/db/repositories/RepositoryLogging.scala')
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/db/repositories/RepositoryLogging.scala62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/db/repositories/RepositoryLogging.scala b/src/main/scala/xyz/driver/pdsuicommon/db/repositories/RepositoryLogging.scala
new file mode 100644
index 0000000..d1ec1da
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuicommon/db/repositories/RepositoryLogging.scala
@@ -0,0 +1,62 @@
+package xyz.driver.pdsuicommon.db.repositories
+
+import xyz.driver.pdsuicommon.logging._
+
+trait RepositoryLogging extends PhiLogging {
+
+ protected def logCreatedOne[T](x: T)(implicit toPhiString: T => PhiString): T = {
+ logger.info(phi"An entity was created: $x")
+ x
+ }
+
+ protected def logCreatedMultiple[T <: Iterable[_]](xs: T)(implicit toPhiString: T => PhiString): T = {
+ if (xs.nonEmpty) {
+ logger.info(phi"Entities were created: $xs")
+ }
+ xs
+ }
+
+ protected def logUpdatedOne(rowsAffected: Long): Long = {
+ rowsAffected match {
+ case 0 => logger.trace(phi"The entity is up to date")
+ case 1 => logger.info(phi"The entity was updated")
+ case x => logger.warn(phi"The ${Unsafe(x)} entities were updated")
+ }
+ rowsAffected
+ }
+
+ protected def logUpdatedOneUnimportant(rowsAffected: Long): Long = {
+ rowsAffected match {
+ case 0 => logger.trace(phi"The entity is up to date")
+ case 1 => logger.trace(phi"The entity was updated")
+ case x => logger.warn(phi"The ${Unsafe(x)} entities were updated")
+ }
+ rowsAffected
+ }
+
+ protected def logUpdatedMultiple(rowsAffected: Long): Long = {
+ rowsAffected match {
+ case 0 => logger.trace(phi"All entities are up to date")
+ case x => logger.info(phi"The ${Unsafe(x)} entities were updated")
+ }
+ rowsAffected
+ }
+
+ protected def logDeletedOne(rowsAffected: Long): Long = {
+ rowsAffected match {
+ case 0 => logger.trace(phi"The entity does not exist")
+ case 1 => logger.info(phi"The entity was deleted")
+ case x => logger.warn(phi"Deleted ${Unsafe(x)} entities, expected one")
+ }
+ rowsAffected
+ }
+
+ protected def logDeletedMultiple(rowsAffected: Long): Long = {
+ rowsAffected match {
+ case 0 => logger.trace(phi"Entities do not exist")
+ case x => logger.info(phi"Deleted ${Unsafe(x)} entities")
+ }
+ rowsAffected
+ }
+
+}