Skip to content

Instantly share code, notes, and snippets.

@rei999
Created July 10, 2013 01:02
Show Gist options
  • Select an option

  • Save rei999/5962699 to your computer and use it in GitHub Desktop.

Select an option

Save rei999/5962699 to your computer and use it in GitHub Desktop.
example serializable entity record for hadoop
package com.mycompany.emr.model;
import java.sql.*;
import java.io.*;
import java.sql.ResultSet;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;
public class EmployeeRecord implements Writable, DBWritable {
private static int DB_ID_INDEX = 1;
private static int DB_TITLE_INDEX = 2;
public Long id;
public String title;
public void write(DataOutput out) throws IOException {
out.writeLong(this.id);
out.writeUTF(this.title);
}
public void readFields(DataInput in) throws IOException {
this.id = in.readLong();
this.title = in.readUTF();
}
public void write(PreparedStatement statement) throws SQLException {
statement.setLong(DB_ID_INDEX, this.id);
statement.setString(DB_TITLE_INDEX, this.title);
}
public void readFields(ResultSet resultSet) throws SQLException {
this.id = resultSet.getLong(DB_ID_INDEX);
this.title = resultSet.getString(DB_TITLE_INDEX);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment