From e178d04972dba3c4117ca203d713da4734915e26 Mon Sep 17 00:00:00 2001 From: Lintterer Date: Tue, 23 Jul 2024 16:16:36 +0200 Subject: [PATCH] feat: removing joda date support --- build.sbt | 22 ++++------ .../sangria/implicits/JodaScalarType.scala | 27 ------------ .../codegen/CustomizedCodeGeneratorBase.scala | 41 +++++++++---------- .../play/db/codegen/XPostgresProfile.scala | 9 ++-- .../slick/enhanced/query/EnhancedQuery.scala | 26 ++++++++---- 5 files changed, 50 insertions(+), 75 deletions(-) delete mode 100755 util-graphql/src/main/scala/de/innfactory/grapqhl/sangria/implicits/JodaScalarType.scala diff --git a/build.sbt b/build.sbt index f84c256..60c2963 100755 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ import sbt._ //settings name := """scala-utils""" -val releaseVersion = "2.0.11" +val releaseVersion = "2.0.12" val token = sys.env.getOrElse("GITHUB_TOKEN", "") @@ -44,7 +44,6 @@ lazy val utilGraphQL = (project in file("util-graphql")) libraryDependencies ++= Seq( typesafePlay, playJson, - joda, sangria, sangriaMarshallingApi, sangriaSlowlog @@ -56,16 +55,14 @@ lazy val utilImplicits = (project in file("util-implicits")).settings( ) settings ( name := "util-implicits" ) -val slickPgJts = "com.github.tminglei" %% "slick-pg_jts" % "0.19.3" -val slick = "com.typesafe.slick" %% "slick" % "3.3.3" -val slickCodegen = "com.typesafe.slick" %% "slick-codegen" % "3.3.3" -val slickHikaricp = "com.typesafe.slick" %% "slick-hikaricp" % "3.3.3" -val hikariCP = "com.zaxxer" % "HikariCP" % "5.0.1" -val slickPg = "com.github.tminglei" %% "slick-pg" % "0.20.2" -val slickPgPlayJson = "com.github.tminglei" %% "slick-pg_play-json" % "0.20.2" -val slickJodaMapper = "com.github.tototoshi" %% "slick-joda-mapper" % "2.4.2" -val flyWayCore = "org.flywaydb" % "flyway-core" % "8.4.1" -val joda = "joda-time" % "joda-time" % "2.10.13" +val slickPgJts = "com.github.tminglei" %% "slick-pg_jts" % "0.22.2" +val slick = "com.typesafe.slick" %% "slick" % "3.5.1" +val slickCodegen = "com.typesafe.slick" %% "slick-codegen" % "3.5.1" +val slickHikaricp = "com.typesafe.slick" %% "slick-hikaricp" % "3.5.1" +val hikariCP = "com.zaxxer" % "HikariCP" % "5.1.0" +val slickPg = "com.github.tminglei" %% "slick-pg" % "0.22.2" +val slickPgPlayJson = "com.github.tminglei" %% "slick-pg_play-json" % "0.22.2" +val flyWayCore = "org.flywaydb" % "flyway-core" % "8.4.1" val playVersion = "2.9.0-RC2" val typesafePlay = "com.typesafe.play" %% "play" % playVersion @@ -111,7 +108,6 @@ lazy val play = (project in file("util-play")) typesafePlay, slickPg, slickPgPlayJson, - slickJodaMapper, slick, slickCodegen, slickHikaricp, diff --git a/util-graphql/src/main/scala/de/innfactory/grapqhl/sangria/implicits/JodaScalarType.scala b/util-graphql/src/main/scala/de/innfactory/grapqhl/sangria/implicits/JodaScalarType.scala deleted file mode 100755 index d64595a..0000000 --- a/util-graphql/src/main/scala/de/innfactory/grapqhl/sangria/implicits/JodaScalarType.scala +++ /dev/null @@ -1,27 +0,0 @@ -package de.innfactory.grapqhl.sangria.implicits - -import org.joda.time.DateTime -import sangria.ast.StringValue -import sangria.schema.ScalarType -import sangria.validation.Violation - -object JodaScalarType { - - case object DateTimeCoerceViolation extends Violation { - override def errorMessage: String = "Error during parsing DateTime" - } - - implicit val GraphQLDateTime: ScalarType[DateTime] = ScalarType[DateTime]( - "DateTime", - coerceOutput = (dt, _) => dt.toString, - coerceInput = { - case s: StringValue => Right(DateTime.parse(s.value)) - case _ => Left(DateTimeCoerceViolation) - }, - coerceUserInput = { - case s: StringValue => Right(DateTime.parse(s.value)) - case _ => Left(DateTimeCoerceViolation) - } - ) - -} diff --git a/util-play/src/main/scala/de/innfactory/play/db/codegen/CustomizedCodeGeneratorBase.scala b/util-play/src/main/scala/de/innfactory/play/db/codegen/CustomizedCodeGeneratorBase.scala index 16735e7..0f179f4 100755 --- a/util-play/src/main/scala/de/innfactory/play/db/codegen/CustomizedCodeGeneratorBase.scala +++ b/util-play/src/main/scala/de/innfactory/play/db/codegen/CustomizedCodeGeneratorBase.scala @@ -5,12 +5,15 @@ import slick.codegen.SourceCodeGenerator import slick.sql.SqlProfile.ColumnOption import scala.concurrent.duration._ -import scala.concurrent.{Await, Future} +import scala.concurrent.{ Await, Future } /** * This customizes the Slick code generator. */ -abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCodeGeneratorConfig: CustomizedCodeGeneratorConfig, config: Config[T]) { +abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile]( + customizedCodeGeneratorConfig: CustomizedCodeGeneratorConfig, + config: Config[T] +) { import scala.concurrent.ExecutionContext.Implicits.global /** @@ -26,7 +29,7 @@ abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCod * @param typeName * @return */ - def rawTypeMatcherBase(typeName: String): Option[String] = { + def rawTypeMatcherBase(typeName: String): Option[String] = typeName match { case "hstore" => Option("Map[String, String]") case "_text" | "text[]" | "_varchar" | "varchar[]" => Option("List[String]") @@ -35,7 +38,6 @@ abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCod case "_int2" | "int2[]" => Option("List[Short]") case s: String => rawTypeMatcherExtension(s) } - } /** * RawTypeMatcher for non standard types like geometry @@ -43,46 +45,40 @@ abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCod * @param typeName * @return */ - def rawTypeMatcherExtension(typeName: String): Option[String] = { + def rawTypeMatcherExtension(typeName: String): Option[String] = typeName match { - case "geometry" => Option("com.vividsolutions.jts.geom.Geometry") - case _ => None + case "geometry" => Option("com.vividsolutions.jts.geom.Geometry") + case _ => None } - } /** * sql raw type mapper to override standard sql types to custom types * @param typeName * @return */ - def sqlTypeMapper(typeName: String, superRawType: String): String = { + def sqlTypeMapper(typeName: String, superRawType: String): String = typeName match { - case "java.sql.Date" => "org.joda.time.LocalDate" - case "java.sql.Time" => "org.joda.time.LocalTime" - case "java.sql.Timestamp" => "org.joda.time.DateTime" + case "java.sql.Timestamp" => "java.time.LocalDateTime" + case "java.sql.Date" => "java.time.LocalDate" case _ => superRawType } - } - val codeGenImports: String = { + val codeGenImports: String = s""" - import com.github.tototoshi.slick.PostgresJodaSupport._ - import org.joda.time.DateTime import com.vividsolutions.jts.geom.Point """ - } val projectDir: String = System.getProperty("user.dir") def main(args: Array[String]): Unit = - // write the generated results to file + // write the generated results to file Await.result( codegen.map( _.writeToFile( profile = customizedCodeGeneratorConfig.profile, // Using customized Codegen profile from config - folder= s"$projectDir${customizedCodeGeneratorConfig.folder}" , + folder = s"$projectDir${customizedCodeGeneratorConfig.folder}", pkg = customizedCodeGeneratorConfig.pkg, - container= customizedCodeGeneratorConfig.container, + container = customizedCodeGeneratorConfig.container, fileName = customizedCodeGeneratorConfig.fileName ) ), @@ -94,7 +90,8 @@ abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCod val db = slickProfile.api.Database.forURL(config.url, driver = config.jdbcDriver) lazy val codegen: Future[SourceCodeGenerator] = db.run { - config.slickProfile.defaultTables.map(_.filter(t => included contains t.name.name.toUpperCase)) + config.slickProfile.defaultTables + .map(_.filter(t => included contains t.name.name.toUpperCase)) .flatMap( config.slickProfile .createModelBuilder(_, ignoreInvalidDefaults = false) @@ -110,7 +107,7 @@ abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCod override def rawType: String = model.options .find(_.isInstanceOf[ColumnOption.SqlType]) - .flatMap( tpe => rawTypeMatcherBase(tpe.asInstanceOf[ColumnOption.SqlType].typeName)) + .flatMap(tpe => rawTypeMatcherBase(tpe.asInstanceOf[ColumnOption.SqlType].typeName)) .getOrElse(sqlTypeMapper(model.tpe, super.rawType)) } } diff --git a/util-play/src/main/scala/de/innfactory/play/db/codegen/XPostgresProfile.scala b/util-play/src/main/scala/de/innfactory/play/db/codegen/XPostgresProfile.scala index 656e0ae..d5aa36a 100755 --- a/util-play/src/main/scala/de/innfactory/play/db/codegen/XPostgresProfile.scala +++ b/util-play/src/main/scala/de/innfactory/play/db/codegen/XPostgresProfile.scala @@ -5,7 +5,7 @@ import play.api.libs.json.{JsValue, Json} import slick.basic.Capability trait XPostgresProfile - extends ExPostgresProfile + extends ExPostgresProfile with PgArraySupport with PgDate2Support with PgRangeSupport @@ -26,9 +26,9 @@ trait XPostgresProfile override val api = CodegenAPI object CodegenAPI - extends API + extends ExtPostgresAPI with ArrayImplicits - with DateTimeImplicits + with Date2DateTimeImplicitsDuration with JsonImplicits with NetImplicits with LTreeImplicits @@ -38,7 +38,7 @@ trait XPostgresProfile with PlayJsonImplicits with SearchImplicits with SearchAssistants { - implicit val strListTypeMapper: DriverJdbcType[List[String]] = + implicit val strListTypeMapper: DriverJdbcType[List[String]] = new SimpleArrayJdbcType[String]("text").to(_.toList) implicit val playJsonArrayTypeMapper: DriverJdbcType[List[JsValue]] = new AdvancedArrayJdbcType[JsValue]( @@ -50,4 +50,3 @@ trait XPostgresProfile } object XPostgresProfile extends XPostgresProfile - diff --git a/util-play/src/main/scala/de/innfactory/play/slick/enhanced/query/EnhancedQuery.scala b/util-play/src/main/scala/de/innfactory/play/slick/enhanced/query/EnhancedQuery.scala index ea5612b..0417a40 100755 --- a/util-play/src/main/scala/de/innfactory/play/slick/enhanced/query/EnhancedQuery.scala +++ b/util-play/src/main/scala/de/innfactory/play/slick/enhanced/query/EnhancedQuery.scala @@ -1,7 +1,17 @@ package de.innfactory.play.slick.enhanced.query import de.innfactory.play.db.codegen.XPostgresProfile -import de.innfactory.play.slick.enhanced.utils.filteroptions.{BooleanFilterOptions, DoubleFilterOptions, FilterOptions, IntFilterOptions, LongFilterOptions, LongSeqFilterOptions, OptionStringFilterOptions, SeqFilterOptions, StringFilterOptions} +import de.innfactory.play.slick.enhanced.utils.filteroptions.{ + BooleanFilterOptions, + DoubleFilterOptions, + FilterOptions, + IntFilterOptions, + LongFilterOptions, + LongSeqFilterOptions, + OptionStringFilterOptions, + SeqFilterOptions, + StringFilterOptions +} import play.api.Logger import slick.lifted.StringColumnExtensionMethods @@ -51,11 +61,11 @@ object EnhancedQuery { applyFilterOptions(processedQuery.filterOptDoubleOptions(option), seq.tail) case option: SeqFilterOptions[I] => applyFilterOptions(processedQuery.filterOptSeqString(option), seq.tail) case option: LongSeqFilterOptions[I] => applyFilterOptions(processedQuery.filterOptSeqLong(option), seq.tail) - case option: BooleanFilterOptions[I] => applyFilterOptions(processedQuery.filterOptBooleanOptions(option), seq.tail) - case o => { + case option: BooleanFilterOptions[I] => + applyFilterOptions(processedQuery.filterOptBooleanOptions(option), seq.tail) + case o => Logger.apply("EnhancedQuery").logger.error("process filterOptions | unknown Option: " + o) applyFilterOptions(query, seq.tail) - } } def filterOptStringOptions[T <: StringFilterOptions[I]]( @@ -97,8 +107,8 @@ object EnhancedQuery { /* Boolean OPTIONS */ def filterOptBooleanOptions[T <: BooleanFilterOptions[I]]( - booleanFilterOption: BooleanFilterOptions[I] - ): Query[I, F, Seq] = { + booleanFilterOption: BooleanFilterOptions[I] + ): Query[I, F, Seq] = { implicit val selector: I => Rep[Boolean] = booleanFilterOption.selector query.filterOptBoolean(booleanFilterOption.equalsOption.value) } @@ -196,8 +206,8 @@ object EnhancedQuery { /* REP[BOOLEAN] OPTIONS */ def filterOptBoolean( - option: Option[Boolean] - )(implicit selector: I => Rep[Boolean]): Query[I, F, Seq] = + option: Option[Boolean] + )(implicit selector: I => Rep[Boolean]): Query[I, F, Seq] = query.filterOpt(option)((r, v) => selector(r) === v) /* REP[STRING] OPTIONS */