-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
124 lines (109 loc) · 3.56 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
buildscript {
ext {
cassandraDriverVersion = "3.6.0"
playVersion = "2.6.19"
scalaVersion = "2.12"
}
repositories {
jcenter()
}
dependencies {
classpath("com.datastax.cassandra:cassandra-driver-core:$cassandraDriverVersion")
classpath("com.typesafe.play:play-guice_$scalaVersion:$playVersion")
classpath files('conf')
}
}
plugins {
id 'java'
id 'play'
id 'idea'
}
wrapper {
gradleVersion = '4.10.2'
}
model {
components {
play {
platform play: playVersion, scala: scalaVersion, java: '1.8'
injectedRoutesGenerator = true
}
}
}
dependencies {
play "com.typesafe.play:play-guice_$scalaVersion:$playVersion"
play "com.typesafe.play:play-logback_$scalaVersion:$playVersion"
play "com.datastax.cassandra:cassandra-driver-core:$cassandraDriverVersion"
play "com.datastax.cassandra:cassandra-driver-mapping:$cassandraDriverVersion"
}
repositories {
jcenter()
maven {
name "lightbend-maven-releases"
url "https://repo.lightbend.com/lightbend/maven-release"
}
ivy {
name "lightbend-ivy-release"
url "https://repo.lightbend.com/lightbend/ivy-releases"
layout "ivy"
}
}
idea {
module {
sourceDirs += file("app")
testSourceDirs += file("test")
scopes.COMPILE = [plus: [configurations.play], minus: []]
scopes.RUNTIME = [plus: [configurations.playRun], minus: [configurations.play]]
scopes.TEST = [plus: [configurations.playTest], minus: [configurations.playRun]]
}
}
/*task dataStax(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'DataStaxDriver'
}*/
import com.datastax.driver.core.*
import com.typesafe.config.*
Config conf = ConfigFactory.load("additional.conf")
def contactPoint = conf.getString("cassandra.contact-point")
def port = Integer.valueOf(conf.getString("cassandra.port"))
def createCassandraCluster(String node, int port) {
return Cluster.builder().addContactPoint(node).withPort(port).build()
}
task createSchema {
doLast {
Cluster cluster = createCassandraCluster(contactPoint, port)
Session session = cluster.connect()
new File("conf/create.cql").eachLine { line -> session.execute(line) }
cluster.close()
}
}
task fillTables {
doLast {
Cluster cluster = createCassandraCluster(contactPoint, port)
Session session = cluster.connect("random_sayings_generator")
String authorPrefix = "author:"
String author
def insertContentStatement = session.prepare(
"INSERT INTO sayings_content (id, text, author) VALUES (?, ?, ?)")
def updateRatingStatement = session.prepare(
"UPDATE sayings_rating SET likes = likes + 0, dislikes = dislikes + 0 WHERE id = ?")
new File("conf/init_data.txt").eachLine { line ->
if (line.startsWith(authorPrefix)) {
author = line.substring(authorPrefix.length()).trim()
}
else if (!line.trim().isEmpty()) {
UUID id = UUID.randomUUID()
session.execute(insertContentStatement.bind(id, line, author))
session.execute(updateRatingStatement.bind(id))
}
}
cluster.close()
}
}
task dropSchema {
doLast {
Cluster cluster = createCassandraCluster(contactPoint, port)
Session session = cluster.connect("random_sayings_generator")
session.execute("drop keyspace random_sayings_generator")
cluster.close()
}
}