Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
working on new db system
Browse files Browse the repository at this point in the history
  • Loading branch information
fulton committed May 5, 2020
1 parent 7908b75 commit fcb7dca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/andromeda/araserver/persona/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Main {
val optionsDB = RequestOptions()
optionsDB.partitionKey = com.microsoft.azure.cosmosdb.PartitionKey("likesmodel")
val data = WordTrainingModel(1, 1, 0, params.word)
NewDoc().generate(data, Random().nextInt().toString(), "likesmodel", optionsDB)
NewDoc().generate(data, Random().nextInt().toString(), "likesmodel")
return Gson().toJson(outputModel)

}
Expand All @@ -62,6 +62,6 @@ class Main {
val model = LikesModel(text, name)
val optionsDB = RequestOptions()
optionsDB.partitionKey = com.microsoft.azure.cosmosdb.PartitionKey("likes")
NewDoc().generate(model, Random().nextInt().toString(), "likes", optionsDB)
NewDoc().generate(model, Random().nextInt().toString(), "likes")
}
}
38 changes: 2 additions & 36 deletions src/main/java/com/andromeda/araserver/util/NewDoc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package com.andromeda.araserver.util
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.microsoft.azure.cosmosdb.*
import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient
import rx.Observable
import rx.functions.Action1


class NewDoc {
Expand Down Expand Up @@ -40,38 +37,7 @@ class NewDoc {

}

fun generate(
data: Any,
id: String,
key: String,
options: RequestOptions
) {
policy.setConnectionMode(ConnectionMode.Direct);
val document = Document(data, id, key)

val asyncClient = AsyncDocumentClient.Builder()
.withServiceEndpoint("https://ara-account-data.documents.azure.com:443/")
.withMasterKeyOrResourceToken(System.getenv("IOTDB"))
.withConnectionPolicy(policy)
.withConsistencyLevel(ConsistencyLevel.Eventual)
.build()
val doc =
Document(Gson().toJson(document))

val createDocumentObservable: Observable<ResourceResponse<com.microsoft.azure.cosmosdb.Document>> =
asyncClient.createDocument("dbs/Ara-android-database/colls/Ara-android-collection", doc, options, true)
createDocumentObservable
.single() // we know there will be one response
.subscribe(
{ documentResourceResponse: ResourceResponse<com.microsoft.azure.cosmosdb.Document> ->
println(
documentResourceResponse.requestCharge
)
},
{ error: Throwable ->
System.err.println("an error happened: " + error.message)
throw error
}
)
fun generate(data: Any, id: String, key: String) {
DatabaseClient().new(id, key, data)
}
}

0 comments on commit fcb7dca

Please sign in to comment.