Skip to content

Commit

Permalink
Began migration to using Java async driver for better performance and…
Browse files Browse the repository at this point in the history
… reliability
  • Loading branch information
darkfrog26 committed Jul 24, 2021
1 parent 94df2b5 commit 96a3b59
Show file tree
Hide file tree
Showing 86 changed files with 587 additions and 413 deletions.
69 changes: 30 additions & 39 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Tests._

name := "scarango"
ThisBuild / organization := "com.outr"
ThisBuild / version := "2.4.4-SNAPSHOT"
ThisBuild / version := "3.0.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / crossScalaVersions := List("2.13.6", "2.12.12")
ThisBuild / scalacOptions ++= Seq("-unchecked", "-deprecation")
Expand All @@ -26,9 +26,7 @@ ThisBuild / developers := List(
Developer(id="darkfrog", name="Matt Hicks", email="matt@matthicks.com", url=url("http://matthicks.com"))
)

val youiVersion = "0.14.1-SNAPSHOT"
val profigVersion = "3.2.6"
val scalaTestVersion = "3.2.3"
def dep: Dependencies.type = Dependencies

def groupByName(tests: Seq[TestDefinition]): Seq[Group] = {
tests.groupBy(_.name).map {
Expand All @@ -39,29 +37,19 @@ def groupByName(tests: Seq[TestDefinition]): Seq[Group] = {
}

lazy val root = project.in(file("."))
.aggregate(api, coreJS, coreJVM, driver, monitored)
.aggregate(coreJS, coreJVM, driver) //, monitored)
.settings(
publish := {},
publishLocal := {}
)

lazy val api = project.in(file("api"))
.settings(
name := "scarango-api",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"io.youi" %% "youi-client" % youiVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % "test"
)
)

lazy val core = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("core"))
.settings(
name := "scarango-core",
libraryDependencies ++= Seq(
"io.youi" %% "youi-core" % youiVersion
dep.profig
)
)

Expand All @@ -76,29 +64,32 @@ lazy val driver = project.in(file("driver"))
Test / testOptions += Tests.Argument("-oD"),
Test / parallelExecution := false,
libraryDependencies ++= Seq(
"com.outr" %% "profig" % profigVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % "test"
)
)
.dependsOn(coreJVM, api)

lazy val monitored = project.in(file("monitored"))
.settings(
name := "scarango-monitored",
fork := true,
Test / testGrouping := groupByName((Test / definedTests).value),
Test / testOptions += Tests.Argument("-oD"),
Test / parallelExecution := false,
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalaTestVersion % "test"
dep.arangoDBJavaDriver,
dep.jacksonDataformatVelocypack,
dep.catsEffect,
dep.fs2,
dep.scalaTest
)
)
.dependsOn(driver)
.dependsOn(coreJVM)

lazy val plugin = project.in(file("plugin"))
.settings(
name := "scarango-plugin",
sbtPlugin := true,
scalaVersion := "2.12.13",
crossSbtVersions := Vector("1.5.2")
)
//lazy val monitored = project.in(file("monitored"))
// .settings(
// name := "scarango-monitored",
// fork := true,
// Test / testGrouping := groupByName((Test / definedTests).value),
// Test / testOptions += Tests.Argument("-oD"),
// Test / parallelExecution := false,
// libraryDependencies ++= Seq(
// "org.scalatest" %% "scalatest" % scalaTestVersion % "test"
// )
// )
// .dependsOn(driver)
//
//lazy val plugin = project.in(file("plugin"))
// .settings(
// name := "scarango-plugin",
// sbtPlugin := true,
// scalaVersion := "2.12.13",
// crossSbtVersions := Vector("1.5.2")
// )
1 change: 0 additions & 1 deletion core/src/main/scala/com/outr/arango/DocumentModel.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.outr.arango

import io.youi.Unique
import fabric.rw.ReaderWriter

trait DocumentModel[D <: Document[D]] {
Expand Down
73 changes: 73 additions & 0 deletions core/src/main/scala/com/outr/arango/Unique.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.outr.arango

import java.util.concurrent.ThreadLocalRandom

/**
* Unique String generator
*/
object Unique {
lazy val LettersLower = "abcdefghijklmnopqrstuvwxyz"
lazy val LettersUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lazy val Numbers = "0123456789"
lazy val Readable = "ABCDEFGHJKLMNPQRSTWXYZ23456789"
lazy val Hexadecimal = s"${Numbers}abcdef"
lazy val LettersAndNumbers = s"$LettersLower$Numbers"
lazy val AllLettersAndNumbers = s"$LettersLower$LettersUpper$Numbers"

/**
* Random number generator used to generate unique values. Defaults to `threadLocalRandom`.
*/
var random: Int => Int = threadLocalRandom

/**
* The default length to use for generating unique values. Defaults to 32.
*/
var defaultLength: Int = 32

/**
* The default characters to use for generating unique values. Defaults to AllLettersAndNumbers.
*/
var defaultCharacters: String = AllLettersAndNumbers

/**
* Uses java.util.concurrent.ThreadLocalRandom to generate random numbers.
*
* @param max the maximum value to include
* @return random number between 0 and max
*/
final def threadLocalRandom(max: Int): Int = ThreadLocalRandom.current().nextInt(max)

/**
* Generates a unique String using the characters supplied at the length defined.
*
* @param length the length of the resulting String. Defaults to Unique.defaultLength.
* @param characters the characters for use in the String. Defaults to Unique.defaultCharacters.
* @return a unique String
*/
def apply(length: Int = defaultLength, characters: String = defaultCharacters): String = {
val charMax = characters.length
(0 until length).map(i => characters.charAt(random(charMax))).mkString
}

/**
* Convenience functionality to generate a UUID (https://en.wikipedia.org/wiki/Universally_unique_identifier)
*
* 32 characters of unique hexadecimal values with dashes representing 36 total characters
*/
def uuid: String = {
val a = apply(8, Hexadecimal)
val b = apply(4, Hexadecimal)
val c = apply(3, Hexadecimal)
val d = apply(1, "89ab")
val e = apply(3, Hexadecimal)
val f = apply(12, Hexadecimal)
s"$a-$b-4$c-$d$e-$f"
}

/**
* Returns the number of possible values for a specific length and characters.
*/
def poolSize(length: Int = 32, characters: String = AllLettersAndNumbers): Long = {
math.pow(characters.length, length).toLong
}
}
Loading

0 comments on commit 96a3b59

Please sign in to comment.