Created
July 10, 2013 01:02
-
-
Save rei999/5962699 to your computer and use it in GitHub Desktop.
example serializable entity record for hadoop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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