Generate Data
src/main/java/com/admatic/GenerateUserData.java
package com.admatic;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import java.util.UUID;
public class GenerateUserData {
private static String[] CONTACT_POINTS = {"127.0.0.1"};
public static void main(String[] args) {
GenerateUserData client = new GenerateUserData();
try {
client.connect(CONTACT_POINTS, 9042);
client.loadData();
} finally {
client.close();
}
}
private Cluster cluster;
private Session session;
private void connect(String[] contactPoints, int port) {
cluster = Cluster.builder()
.addContactPoints(contactPoints).withPort(port)
.build();
System.out.printf("Connected to cluster: %s%n", cluster.getMetadata().getClusterName());
session = cluster.connect();
}
private void loadData() {
for (int i = 0; i < 9999; i++) {
String username = UUID.randomUUID().toString();
String email = UUID.randomUUID().toString();
session.execute("INSERT INTO admatic.users_by_username(username, email, age) VALUES ('" + username + "', '" + email + "', 21);");
session.execute("INSERT INTO admatic.users_by_email(email, username, age) VALUES ('" + email + "', '" + username + "', 21);");
}
}
private void close() {
session.close();
cluster.close();
}
}
src/main/java/com/admatic/GenerateOtherData.java
package com.admatic;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import java.util.UUID;
public class GenerateOtherData {
private static String[] CONTACT_POINTS = {"127.0.0.1"};
public static void main(String[] args) {
GenerateOtherData client = new GenerateOtherData();
try {
client.connect(CONTACT_POINTS, 9042);
client.loadData();
} finally {
client.close();
}
}
private Cluster cluster;
private Session session;
private void connect(String[] contactPoints, int port) {
cluster = Cluster.builder()
.addContactPoints(contactPoints).withPort(port)
.build();
System.out.printf("Connected to cluster: %s%n", cluster.getMetadata().getClusterName());
session = cluster.connect();
}
private void loadData() {
for (int i = 0; i < 9999; i++) {
String uuid = UUID.randomUUID().toString();
String username = UUID.randomUUID().toString();
String email = UUID.randomUUID().toString();
session.execute("INSERT INTO others.users(id, username, email, age) VALUES (" + uuid + ",'" + username + "', '" + email + "', 21);");
session.execute("INSERT INTO others.users_by_username(username, id) VALUES ('" + username + "', " + uuid + ");");
session.execute("INSERT INTO others.users_by_email(email, id) VALUES ('" + email + "', " + uuid + ");");
}
}
private void close() {
session.close();
cluster.close();
}
}