Skip to content

Commit

Permalink
Add couple storage tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
zbsz committed Feb 1, 2016
1 parent d44222a commit 27e9fd5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.5.0")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")

addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.5.11")
addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.5.14")
7 changes: 6 additions & 1 deletion src/main/scala/com/geteit/cache/CacheEntryData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import com.geteit.json.{Json, JsonValue}
import com.geteit.util.Log

@JsonValue
case class Uid(str: String)
case class Uid(str: String) {
lazy val (leastSigBits, mostSigBits) = {
val uuid = UUID.fromString(str)
(uuid.getLeastSignificantBits, uuid.getMostSignificantBits)
}
}

object Uid {
def apply() = new Uid(UUID.randomUUID().toString)
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/com/geteit/db/CachedStorage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ abstract class CachedStorage[K, V](implicit val dao: Dao[K, V], inj: Injector) e

def query(matcher: Matcher[V]): Future[Cursor] = storage.read { dao.query(matcher.whereSql)(_) }

def list(matcher: Matcher[V]): Future[Seq[V]] = storage.read { db => dao.list(dao.query(matcher.whereSql)(db)) } // TODO: add loaded items to cache

def count(matcher: Matcher[V]): Future[Long] = storage.read { dao.count(matcher.whereSql)(_) }

def remove(matcher: Matcher[V]): Future[Unit] = find(matcher) map { _ foreach remove }

def insert(item: V) = updateOrCreate(dao.getId(item), _ => item, item)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/geteit/db/Dao.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ abstract class Dao[I: Id, A: JsonDecoder : JsonEncoder] {

def decode(c: Cursor) = decoder(c.getString(DataIndex))

protected[db] def single(c: Cursor) = try {
def single(c: Cursor) = try {
if (c.moveToFirst()) Some(decode(c)) else None
} finally c.close()

protected[db] def list(c: Cursor) = try {
def list(c: Cursor) = try {
val builder = Seq.newBuilder[A]
while (c.moveToNext()) builder += decode(c)
builder.result()
Expand Down

0 comments on commit 27e9fd5

Please sign in to comment.