Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 
 package base.jee.api.cassandra.util;
 
public class AddPerson {
	public static UUID addPerson(Session sString firstNameString lastNameString emailString usernameString passwordDate expirythrows IOException {
		UUID uuid = new base.uuid.UUID().toJavaUUID();
		if(email == null || email.length() < 4) {
			throw new IllegalArgumentException("Invalid email parameter");
		}
		PreparedStatement p = s.prepare("select email from person where email=?");
		ResultSet rs = s.execute(p.bind(email));
		if(rs.iterator().hasNext()) {
			throw new IllegalArgumentException("Person already exists with this email address.");
		}
		if(username != null && username.length() == 0) {
			username = null;
		}
		if(username != null) {
			p = s.prepare("select username from person where username=?");
			rs = s.execute(p.bind(username));
			if(rs.iterator().hasNext()) {
				throw new IllegalArgumentException("Person already exists with this username.");
			}
		}
		try {
			String pwd = (password == null || password.length() == 0?null: Password.encode(password));
			p = s.prepare("insert into person (uuid, first_name, last_name, email, username, password, created, expiry) values(?,?,?,?,?,?,?,?)");
			s.execute(p.bind(uuidfirstNamelastNameemailusernamepwdnew Date().getTime(), expiry == null ? 0 : expiry.getTime()));
			return uuid;
			throw new IOException("Password encoding problem"e);
		}
	}
New to GrepCode? Check out our FAQ X