-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,25 +5,28 @@ import com.bio4j.dynamograph.dao.go.AnyDynamoDbDao | |
import com.bio4j.dynamograph.model.GeneralSchema.id | ||
import com.amazonaws.services.dynamodbv2.model.AttributeValue | ||
import scala.collection.JavaConverters._ | ||
import ohnosequences.tabula.AnyItem | ||
import ohnosequences.tabula.AnyItem._ | ||
|
||
|
||
trait AnyDynamoVertex extends AnyVertex { dynamoVertex => | ||
|
||
final type Raw = Map[String, AttributeValue] | ||
type Raw <: AnyItem | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
eparejatobes
Member
|
||
|
||
val dao: AnyDynamoDbDao = ServiceProvider.dao | ||
|
||
|
||
implicit def unsafeGetProperty[P <: AnyProperty: Property.Of[this.Tpe]#is](p: P) = | ||
new PropertyGetter[P](p) { | ||
def apply(rep: Rep): p.Raw = getValue(rep, p.label) | ||
def apply(rep: Rep): p.Raw = rep.get(p) | ||
} | ||
|
||
|
||
implicit def unsafeGetOneOutEdge[E <: Singleton with AnyDynamoEdge { | ||
type Tpe <: From[dynamoVertex.Tpe] with OneOut }](e: E): GetOutEdge[E] = new GetOutEdge[E](e) { | ||
|
||
def apply(rep: dynamoVertex.Rep): e.tpe.Out[e.Rep] = { | ||
val it = dao.getOutRelationships(getId(rep), e).asInstanceOf[List[e.Rep]] | ||
val it = dao.getOutRelationships(rep.get(id), e).asInstanceOf[List[e.Rep]] | ||
it.headOption: Option[e.Rep] | ||
} | ||
} | ||
|
@@ -32,7 +35,7 @@ trait AnyDynamoVertex extends AnyVertex { dynamoVertex => | |
type Tpe <: From[dynamoVertex.Tpe] with ManyOut }](e: E): GetOutEdge[E] = new GetOutEdge[E](e) { | ||
|
||
def apply(rep: dynamoVertex.Rep): e.tpe.Out[e.Rep] = { | ||
val it = dao.getOutRelationships(getId(rep),e).asInstanceOf[List[e.Rep]] | ||
val it = dao.getOutRelationships(rep.get(id),e).asInstanceOf[List[e.Rep]] | ||
it: List[e.Rep] | ||
} | ||
} | ||
|
@@ -41,7 +44,7 @@ trait AnyDynamoVertex extends AnyVertex { dynamoVertex => | |
type Tpe <: To[dynamoVertex.Tpe] with OneIn }](e: E): GetInEdge[E] = new GetInEdge[E](e) { | ||
|
||
def apply(rep: dynamoVertex.Rep): e.tpe.In[e.Rep] = { | ||
val it = dao.getOutRelationships(getId(rep),e).asInstanceOf[List[e.Rep]] | ||
val it = dao.getOutRelationships(rep.get(id),e).asInstanceOf[List[e.Rep]] | ||
it.headOption: Option[e.Rep] | ||
} | ||
} | ||
|
@@ -50,22 +53,17 @@ trait AnyDynamoVertex extends AnyVertex { dynamoVertex => | |
type Tpe <: To[dynamoVertex.Tpe] with ManyIn }](e: E): GetInEdge[E] = new GetInEdge[E](e) { | ||
|
||
def apply(rep: dynamoVertex.Rep): e.tpe.In[e.Rep] = { | ||
val it = dao.getOutRelationships(getId(rep), e).asInstanceOf[List[e.Rep]] | ||
val it = dao.getOutRelationships(rep.get(id), e).asInstanceOf[List[e.Rep]] | ||
it.toList: List[e.Rep] | ||
} | ||
} | ||
|
||
private def getValue[T](rep: Rep, attributeName : String) : T = rep.get(attributeName).getOrElse(new AttributeValue().withS("")).getS.asInstanceOf[T] | ||
|
||
private def getId(rep: Rep) : String = getValue(rep, id.label) | ||
|
||
} | ||
|
||
class DynamoVertex[VT <: Singleton with AnyVertexType](val tpe: VT) extends AnyDynamoVertex { | ||
class DynamoVertex[VT <: Singleton with DynamoVertexType](val tpe: VT) extends AnyDynamoVertex { | ||
type Tpe = VT | ||
} | ||
|
||
object AnyDynamoVertex{ | ||
type ofType[VT <: AnyVertexType] = AnyDynamoVertex { type Tpe = VT } | ||
type ofType[VT <: DynamoVertexType] = AnyDynamoVertex { type Tpe = VT } | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
src/main/scala/com/bio4j/dynamograph/DynamoVertexType.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.bio4j.dynamograph | ||
|
||
import ohnosequences.scarph.VertexType | ||
import ohnosequences.typesets.TypeSet | ||
import ohnosequences.tabula.{AnyItem, Item} | ||
|
||
|
||
class DynamoVertexType[As <:TypeSet ](override val label: String, val attributes : As) extends VertexType(label){ | ||
type Attributes = As | ||
} |
This file contains 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
What type there should be? Raw <: Any Item or, <:AnyItem#Raw or just <:TypeSet?