|
27 | 27 | import java.io.*; |
28 | 28 | import java.net.URL; |
29 | 29 | import java.nio.charset.Charset; |
| 30 | +import java.nio.file.Files; |
| 31 | +import java.nio.file.Paths; |
30 | 32 | import java.util.*; |
31 | 33 |
|
32 | 34 | /** |
@@ -230,33 +232,40 @@ void install(String name) throws IOException, InterruptedException, GitAPIExcept |
230 | 232 |
|
231 | 233 | Config config = mapper.readValue(configFile, Config.class); |
232 | 234 | String address = this.host; |
233 | | - { |
234 | | - Cluster cluster = Cluster.builder().addContactPoint(address).build(); |
235 | | - Session session = cluster.connect(); |
236 | 235 |
|
237 | | - StringBuilder createKeyspace = new StringBuilder(); |
238 | | - createKeyspace.append(" CREATE KEYSPACE ") |
239 | | - .append(config.keyspace) |
240 | | - .append(" WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); |
| 236 | + Cluster cluster = Cluster.builder().addContactPoint(address).build(); |
| 237 | + Session session = cluster.connect(); |
241 | 238 |
|
242 | | - System.out.println(createKeyspace); |
243 | | - session.execute("DROP KEYSPACE IF EXISTS " + config.keyspace); |
244 | | - session.execute(createKeyspace.toString()); |
245 | | - cluster.close(); |
| 239 | + StringBuilder createKeyspace = new StringBuilder(); |
| 240 | + createKeyspace.append(" CREATE KEYSPACE ") |
| 241 | + .append(config.keyspace) |
| 242 | + .append(" WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); |
246 | 243 |
|
| 244 | + System.out.println(createKeyspace); |
| 245 | + session.execute("DROP KEYSPACE IF EXISTS " + config.keyspace); |
| 246 | + session.execute(createKeyspace.toString()); |
| 247 | + session.execute("USE " + config.keyspace); |
| 248 | + |
| 249 | + System.out.println("Schema: " + schema); |
| 250 | +// String loadSchema = "cqlsh -k " + config.keyspace + " -f " + schema; |
| 251 | + |
| 252 | + byte[] bytes = Files.readAllBytes(Paths.get(schema)); |
| 253 | + String[] create_tables = new String(bytes).split(";"); |
| 254 | + for(String c: create_tables) { |
| 255 | + String tmp = c.trim(); |
| 256 | + if(tmp.length() > 0) { |
| 257 | + session.execute(tmp); |
| 258 | + } |
247 | 259 | } |
248 | 260 |
|
249 | | - System.out.println("Schema: " + schema); |
250 | | - String loadSchema = "cqlsh -k " + config.keyspace + " -f " + schema; |
251 | | - Runtime.getRuntime().exec(new String[]{"bash", "-c", loadSchema}).waitFor(); |
| 261 | +// Runtime.getRuntime().exec(new String[]{"bash", "-c", loadSchema}).waitFor(); |
252 | 262 |
|
253 | 263 | System.out.println("Loading data"); |
254 | 264 |
|
255 | 265 | Cluster cluster2 = Cluster.builder() |
256 | 266 | .addContactPoint(address) |
257 | 267 | .build(); |
258 | 268 |
|
259 | | - Session session = cluster2.connect(config.keyspace); |
260 | 269 |
|
261 | 270 | this.session = session; |
262 | 271 |
|
|
0 commit comments