Database Reference
In-Depth Information
generator.generate(nUsers, nEmails);
} catch (Exception e) {
System.out.println("Problem writig files: " + e.getMessage());
e.printStackTrace(System.out);
}
}
As you can see, the main method simply collects two arguments and passes them on
to the generate() method. It also explains the usage and gives an explanatory error
message when the usage is not observed.
The key code fragment is the generate() method and it starts by preparing the
output directory like this:
private void generate(int nUsers, int nEmails) throws IOException {
SimpleDateFormat dateFormat = new SimpleDateFormat
("yyyy-MM-dd HH:mm:ss");
new File(Util.ROOT_DIR).mkdirs();
Charset charset = Charset.forName("US-ASCII");
if (nEmails < 1) {
nEmails = 1;
}
The most important loop to generate is the users. Here it is:
for (int u = 1; u <= nUsers; ++u) {
StringBuilder insert = new StringBuilder();
insert.append("INSERT INTO users (username, firstname, lastname,
email, password, created_date) VALUES (");
String firstName = util.generateName();
String lastName = util.generateName();
String username = firstName + lastName;
insert.append("'").append(username).append("',").
append("'").
append(firstName).append("',").append("'").append(lastName).
append("',");
insert.append("[");
for (int e = 0; e < nEmails; ++e) {
insert.append("'").append(util.generateName()).
append("@").
append(util.generateDomain()).append("'");
if (e < nEmails - 1) {
insert.append(",");
}
}
insert.append("],");
 
Search WWH ::




Custom Search