public List<ListenableFuture<ResultSet>> moveTableUpdate( String name, ResultSet sourceResult, ColumnDefinitions defs) throws ExecutionException { int ncols = defs.size(); StringBuilder body = new StringBuilder("update " + name).append(" SET "); boolean nb = true; boolean ns = true; List<ListenableFuture<ResultSet>> list = new ArrayList<>(); StringBuilder spec = new StringBuilder(" WHERE "); for (int i = 0; i < ncols; ++i) { String cn = defs.getName(i); boolean isRowKey = name == null ? false : (cn.startsWith("row_") || cn.startsWith("cluster_")); if (isRowKey) { if (ns) { ns = false; } else { spec.append(" AND "); } spec.append(cn + " = ?"); } else { if (nb) { nb = false; } else { body.append(", "); } DataType dt = defs.getType(i); if (!DataType.Name.COUNTER.equals(dt.getName())) { body.append(cn + " = ?"); } else { body.append(cn + " = " + cn + " + ?"); } } } body.append(spec.toString()); System.out.println(body.toString()); BoundStatement export = destination.peer.bPrepare(destination.session, body.toString()); // Row row; int counter = 0; for (Row row : sourceResult) { for (int i = 0; i < ncols; ++i) { export.setBytesUnsafe(i, row.getBytesUnsafe(i)); } list.add(destination.session.executeAsync(export)); ++counter; } System.out.println("" + counter + " rows applied"); return list; }
public List<ListenableFuture<ResultSet>> moveTable(String name) throws ExecutionException { System.out.println("inserting data to destination:" + name); String query = "select * from " + name; BoundStatement bs = source.peer.bPrepare(source.session, query); ResultSet rs = source.session.execute(bs); ColumnDefinitions defs = rs.getColumnDefinitions(); int ncols = defs.size(); boolean update = false; for (int i = 0; i < ncols; ++i) { DataType dt = defs.getType(i); if (DataType.Name.COUNTER.equals(dt.getName())) { update = true; break; } } if (update) { return moveTableUpdate(name, rs, defs); } else { return moveTableInsert(name, rs, defs); } }