Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
CTF
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grzegorz
CTF
Commits
dacaaf6c
Commit
dacaaf6c
authored
Nov 11, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial version of couchdb integration
parent
43e17aad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
8 deletions
+19
-8
DatastoreProvider.java
...ephoners/krakyournet/ctf/providers/DatastoreProvider.java
+19
-8
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/providers/DatastoreProvider.java
View file @
dacaaf6c
package
com
.
telephoners
.
krakyournet
.
ctf
.
providers
;
import
com.mongodb.MongoClient
;
import
com.telephoners.krakyournet.ctf.core.ApplicationConfiguration
;
import
org.mongodb.morphia.Datastore
;
import
org.mongodb.morphia.Morphia
;
import
org.ektorp.CouchDbConnector
;
import
org.ektorp.CouchDbInstance
;
import
org.ektorp.http.HttpClient
;
import
org.ektorp.http.StdHttpClient
;
import
org.ektorp.impl.StdCouchDbConnector
;
import
org.ektorp.impl.StdCouchDbInstance
;
import
javax.inject.Inject
;
import
java.net.MalformedURLException
;
//todo: move to module @Provides
public
class
DatastoreProvider
{
private
final
ApplicationConfiguration
applicationConfiguration
;
...
...
@@ -17,12 +22,18 @@ public class DatastoreProvider
this
.
applicationConfiguration
=
applicationConfiguration
;
}
public
Datastore
getDatastore
()
public
CouchDbConnector
getDatastore
()
throws
MalformedURLException
{
Morphia
morphia
=
new
Morphia
();
Datastore
datastore
=
morphia
.
createDatastore
(
new
MongoClient
(
applicationConfiguration
.
getDbHost
(),
applicationConfiguration
.
getDbPort
()),
applicationConfiguration
.
getDbName
());
datastore
.
ensureIndexes
();
final
HttpClient
httpClient
=
new
StdHttpClient
.
Builder
()
.
url
(
"http://localhost:5984"
)
//todo: to configuartion
.
build
();
final
CouchDbInstance
dbInstance
=
new
StdCouchDbInstance
(
httpClient
);
CouchDbConnector
datastore
=
new
StdCouchDbConnector
(
"mydatabase"
,
dbInstance
);
//todo: to configuration
//todo: if setup enabled
datastore
.
createDatabaseIfNotExists
();
return
datastore
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment