This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CompletableFASync { | |
private static CompletableFuture<Integer> doubleMe(final Integer number) { | |
return CompletableFuture.completedFuture(number * 2); | |
} | |
public static void main(String[] args) throws InterruptedException { | |
// Just an example future that returns double of an integer and convert it to String. | |
final CompletionStage<String> processedCompletableFuture = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else{ | |
while(!queue.empty()){ | |
currentPoint = queue.front(); | |
queue.pop(); | |
for(int j=0;j<dir.length;j++){ | |
if(validDir && notVisited){ | |
Point nextPoint = currentPoint; | |
switch (case){ | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val userPair = for{ | |
uuid <- databaseService.createUser(UUID.nameUUIDFromBytes("Sumanth".getBytes), "Sumanth", "Kumar", "[email protected]") | |
userByFirstName <- databaseService.selectUserByFirstName("Sumanth") | |
userById <- databaseService.selectUserById(uuid.get) | |
} yield (userById, userByFirstName) | |
val res = userPair.map { | |
case (userById, userByFirstName) => | |
logger.info(s"User by Id : ${userById.get}") | |
logger.info(s"User by first name: ${userByFirstName.get}") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object UserDatabase extends UserDatabase | |
object databaseService extends UserDatabaseService { | |
override def database: UserDatabase = UserDatabase | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val cassandraConnection: CassandraConnection = { | |
ContactPoint.local.keySpace("user_keyspace") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.outworkers.phantom.dsl._ | |
import scala.concurrent.Future | |
trait UserDatabaseService extends UserDbProvider { | |
// Orchestrate your low level queries appropriately. | |
def createUser(uuid: UUID, firstName: String, lastName: String, email:String): Future[Option[UUID]] = | |
database.userByIdInstance.createUserById(uuid, firstName, lastName, email) | |
.flatMap(_ => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.outworkers.phantom.dsl._ | |
// This class will encapsulate all the valid database instances | |
class UserDatabase(implicit cassandraConnection: CassandraConnection) | |
extends Database[UserDatabase](connector = cassandraConnection) { | |
object userByIdInstance extends UserById with Connector | |
object userByFirstName extends UserByFirstName with Connector | |
} | |
// This trait will act as a database instance provider. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Query based model | |
abstract class UserById extends Table[UserById, User] { | |
// Override table metadata | |
override def tableName: String = "user_by_id" | |
// Define the table schema | |
object id extends UUIDColumn with PartitionKey | |
object fName extends StringColumn { | |
override def name: String = "firstName" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Base model used as DTO | |
case class User(id: UUID, firstName: String, lastName: String, email: String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name := "phantom-scala-example" | |
version := "0.1" | |
scalaVersion := "2.12.8" | |
libraryDependencies ++= Seq( | |
// Database dependencies | |
"com.outworkers" % "phantom-dsl_2.12" % "2.30.0", | |
// scala logging |
NewerOlder