11package com .datastax .cdm ;
22
3+ import com .datastax .driver .core .Cluster ;
34import com .datastax .driver .core .Session ;
45import com .fasterxml .jackson .core .type .TypeReference ;
56import com .fasterxml .jackson .databind .ObjectMapper ;
67import com .fasterxml .jackson .dataformat .yaml .YAMLFactory ;
78import org .apache .commons .cli .*;
9+ import org .apache .commons .csv .CSVFormat ;
10+ import org .apache .commons .csv .CSVRecord ;
811import org .apache .commons .io .FileUtils ;
912import org .eclipse .jgit .api .Git ;
1013import org .eclipse .jgit .api .errors .GitAPIException ;
@@ -110,13 +113,13 @@ private void dump() throws IOException, InterruptedException {
110113 for (String table : config .tables ) {
111114 StringBuilder command = new StringBuilder ();
112115 command .append ("cqlsh -k " )
113- .append (config .keyspace )
114- .append (" -e \" " )
115- .append ("COPY " )
116- .append (table )
117- .append (" TO 'data/" )
118- .append (table )
119- .append (".csv'\" " );
116+ .append (config .keyspace )
117+ .append (" -e \" " )
118+ .append ("COPY " )
119+ .append (table )
120+ .append (" TO 'data/" )
121+ .append (table )
122+ .append (".csv'\" " );
120123 System .out .println (command );
121124 Runtime .getRuntime ().exec (new String []{"bash" , "-c" , command .toString ()}).waitFor ();
122125 }
@@ -210,12 +213,23 @@ void install(String name) throws IOException, InterruptedException, GitAPIExcept
210213
211214 Config config = mapper .readValue (configFile , Config .class );
212215
213- String createKeyspace = "cqlsh -e \" DROP KEYSPACE IF EXISTS " + config .keyspace +
214- "; CREATE KEYSPACE " + config .keyspace +
215- " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}\" " ;
216+ Cluster cluster = Cluster .builder ().addContactPoint ("127.0.0.1" ).build ();
217+ Session session = cluster .connect ();
218+
219+ // String createKeyspace = "DROP KEYSPACE IF EXISTS " + config.keyspace +
220+ // "; CREATE KEYSPACE " + config.keyspace +
221+ // " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}";
222+
223+ StringBuilder createKeyspace = new StringBuilder ();
224+ createKeyspace .append (" CREATE KEYSPACE " )
225+ .append (config .keyspace )
226+ .append ( " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}" );
216227
217228 System .out .println (createKeyspace );
218- Runtime .getRuntime ().exec (new String []{"bash" , "-c" , createKeyspace }).waitFor ();
229+ session .execute ("DROP KEYSPACE IF EXISTS " + config .keyspace );
230+ session .execute (createKeyspace .toString ());
231+
232+ // Runtime.getRuntime().exec(new String[]{"bash", "-c", createKeyspace}).waitFor();
219233
220234
221235 System .out .println ("Schema: " + schema );
@@ -226,10 +240,17 @@ void install(String name) throws IOException, InterruptedException, GitAPIExcept
226240
227241 for (String table : config .tables ) {
228242 String dataFile = dataPath + table + ".csv" ;
229- String command = "COPY " + table + " FROM " + "'" + dataFile + "'" ;
230- String loadData = "cqlsh -k " + config .keyspace + " -e \" " + command + "\" " ;
231- System .out .println (loadData );
232- Runtime .getRuntime ().exec (new String []{"bash" , "-c" , loadData }).waitFor ();
243+
244+ Reader in = new FileReader (dataFile );
245+ Iterable <CSVRecord > records = CSVFormat .RFC4180 .parse (in );
246+ for (CSVRecord record : records ) {
247+
248+ }
249+
250+ // String command = "COPY " + table + " FROM " + "'" + dataFile + "'";
251+ // String loadData= "cqlsh -k " + config.keyspace + " -e \"" + command + "\"";
252+ // System.out.println(loadData);
253+ // Runtime.getRuntime().exec(new String[]{"bash", "-c", loadData}).waitFor();
233254 }
234255
235256
0 commit comments