参考官方文档:http://gora.apache.org/current/tutorial.html

项目代码见:https://code.csdn.net/jediael_lu/mygorademo

一、环境准备

1、下载gora并解压



2、分别进入$GORA_HOME/gora-hbase/,$GORA_HOME/gora-core,$GORA_HOME/gora-compiler,$GORA_HOME/gora-compiler-CLI执行

$ mvn clean install

或者直接在$GORA_HOME执行此命令。



3、启动hbase,需要有zookeeper,即一般为分布式的hbase。

注意gora-0.5对应Hbase0.94



4、准备好日志文件,用于本项目的分析





二、建立项目



1、建立一个java project

(1)创建以下几个目录



(2)构建build path,增加hadoop library,hbase library以及avro, gora相关的类包,详见后面的项目结构。



(3)将准备好的日志文件放到resource目录下



2、在conf目录下创建gora.properties,内容如下:

##gora.datastore.default is the default detastore implementation to use
##if it is not passed to the DataStoreFactory#createDataStore() method.
gora.datastore.default=org.apache.gora.hbase.store.HBaseStore ##whether to create schema automatically if not exists.
gora.datastore.autocreateschema=true

3、在avro目录下创建pageview.json,内容如下:

{
"type": "record",
"name": "Pageview", "default":null,
"namespace": "org.apache.gora.tutorial.log.generated",
"fields" : [
{"name": "url", "type": ["null","string"], "default":null},
{"name": "timestamp", "type": "long", "default":0},
{"name": "ip", "type": ["null","string"], "default":null},
{"name": "httpMethod", "type": ["null","string"], "default":null},
{"name": "httpStatusCode", "type": "int", "default":0},
{"name": "responseSize", "type": "int", "default":0},
{"name": "referrer", "type": ["null","string"], "default":null},
{"name": "userAgent", "type": ["null","string"], "default":null}
]
}

4、根据pageview.json生成java类

$ pwd

/Users/liaoliuqing/99_Project/1_myCodes/MyGoraDemo



$ gora goracompiler avro/pageview.json src/

Compiling: /Users/liaoliuqing/99_Project/1_myCodes/MyGoraDemo/avro/pageview.json

Compiled into: /Users/liaoliuqing/99_Project/1_myCodes/MyGoraDemo/src

Compiler executed SUCCESSFULL.

此命令在src目录下生成一个类:

org.apache.gora.tutorial.log.generated.Pageview.java

生成的内容请见最后面。

5、创建gora-hbase-mapping.xml,内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<!--
Gora Mapping file for HBase Backend
-->
<gora-otd>
<table name="Pageview"> <!-- optional descriptors for tables -->
<family name="common"/> <!-- This can also have params like compression, bloom filters -->
<family name="http"/>
<family name="misc"/>
</table> <class name="org.apache.gora.tutorial.log.generated.Pageview" keyClass="java.lang.Long" table="AccessLog">
<field name="url" family="common" qualifier="url"/>
<field name="timestamp" family="common" qualifier="timestamp"/>
<field name="ip" family="common" qualifier="ip" />
<field name="httpMethod" family="http" qualifier="httpMethod"/>
<field name="httpStatusCode" family="http" qualifier="httpStatusCode"/>
<field name="responseSize" family="http" qualifier="responseSize"/>
<field name="referrer" family="misc" qualifier="referrer"/>
<field name="userAgent" family="misc" qualifier="userAgent"/>
</class> </gora-otd>

三、代码编写及分析

1、编写以下代码

package org.apache.gora.tutorial.log;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.StringTokenizer; import org.apache.avro.util.Utf8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.gora.query.Query;
import org.apache.gora.query.Result;
import org.apache.gora.store.DataStore;
import org.apache.gora.store.DataStoreFactory;
import org.apache.gora.tutorial.log.generated.Pageview;
import org.apache.hadoop.conf.Configuration; /**
* LogManager is the tutorial class to illustrate the basic
* {@link DataStore} API usage. The LogManager class is used
* to parse the web server logs in combined log format, store the
* data in a Gora compatible data store, query and manipulate the stored data.
*
* <p>In the data model, keys are the line numbers in the log file,
* and the values are Pageview objects, generated from
* <code>gora-tutorial/src/main/avro/pageview.json</code>.
*
* <p>See the tutorial.html file in docs or go to the
* <a href="http://gora.apache.org/docs/current/tutorial.html">
* web site</a>for more information.</p>
*/
public class LogManager { private static final Logger log = LoggerFactory.getLogger(LogManager.class); private DataStore<Long, Pageview> dataStore; private static final SimpleDateFormat dateFormat
= new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z"); public LogManager() {
try {
init();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} private void init() throws IOException {
//Data store objects are created from a factory. It is necessary to
//provide the key and value class. The datastore class is optional,
//and if not specified it will be read from the properties file
dataStore = DataStoreFactory.getDataStore(Long.class, Pageview.class,
new Configuration());
} /**
* Parses a log file and store the contents at the data store.
* @param input the input file location
*/
private void parse(String input) throws IOException, ParseException, Exception {
log.info("Parsing file:" + input);
BufferedReader reader = new BufferedReader(new FileReader(input));
long lineCount = 0;
try {
String line = reader.readLine();
do {
Pageview pageview = parseLine(line); if(pageview != null) {
//store the pageview
storePageview(lineCount++, pageview);
} line = reader.readLine();
} while(line != null); } finally {
reader.close();
}
log.info("finished parsing file. Total number of log lines:" + lineCount);
} /** Parses a single log line in combined log format using StringTokenizers */
private Pageview parseLine(String line) throws ParseException {
StringTokenizer matcher = new StringTokenizer(line);
//parse the log line
String ip = matcher.nextToken();
matcher.nextToken(); //discard
matcher.nextToken();
long timestamp = dateFormat.parse(matcher.nextToken("]").substring(2)).getTime();
matcher.nextToken("\"");
String request = matcher.nextToken("\"");
String[] requestParts = request.split(" ");
String httpMethod = requestParts[0];
String url = requestParts[1];
matcher.nextToken(" ");
int httpStatusCode = Integer.parseInt(matcher.nextToken());
int responseSize = Integer.parseInt(matcher.nextToken());
matcher.nextToken("\"");
String referrer = matcher.nextToken("\"");
matcher.nextToken("\"");
String userAgent = matcher.nextToken("\""); //construct and return pageview object
Pageview pageview = new Pageview();
pageview.setIp(new Utf8(ip));
pageview.setTimestamp(timestamp);
pageview.setHttpMethod(new Utf8(httpMethod));
pageview.setUrl(new Utf8(url));
pageview.setHttpStatusCode(httpStatusCode);
pageview.setResponseSize(responseSize);
pageview.setReferrer(new Utf8(referrer));
pageview.setUserAgent(new Utf8(userAgent)); return pageview;
} /** Stores the pageview object with the given key */
private void storePageview(long key, Pageview pageview) throws IOException, Exception {
log.info("Storing Pageview in: " + dataStore.toString());
dataStore.put(key, pageview);
} /** Fetches a single pageview object and prints it*/
private void get(long key) throws IOException, Exception {
Pageview pageview = dataStore.get(key);
printPageview(pageview);
} /** Queries and prints a single pageview object */
private void query(long key) throws IOException, Exception {
//Queries are constructed from the data store
Query<Long, Pageview> query = dataStore.newQuery();
query.setKey(key); Result<Long, Pageview> result = query.execute(); //Actually executes the query.
// alternatively dataStore.execute(query); can be used printResult(result);
} /** Queries and prints pageview object that have keys between startKey and endKey*/
private void query(long startKey, long endKey) throws IOException, Exception {
Query<Long, Pageview> query = dataStore.newQuery();
//set the properties of query
query.setStartKey(startKey);
query.setEndKey(endKey); Result<Long, Pageview> result = query.execute(); printResult(result);
} /**Deletes the pageview with the given line number */
private void delete(long lineNum) throws Exception {
dataStore.delete(lineNum);
dataStore.flush(); //write changes may need to be flushed before
//they are committed
log.info("pageview with key:" + lineNum + " deleted");
} /** This method illustrates delete by query call */
private void deleteByQuery(long startKey, long endKey) throws IOException, Exception {
//Constructs a query from the dataStore. The matching rows to this query will be deleted
Query<Long, Pageview> query = dataStore.newQuery();
//set the properties of query
query.setStartKey(startKey);
query.setEndKey(endKey); dataStore.deleteByQuery(query);
log.info("pageviews with keys between " + startKey + " and " + endKey + " are deleted");
} private void printResult(Result<Long, Pageview> result) throws IOException, Exception { while(result.next()) { //advances the Result object and breaks if at end
long resultKey = result.getKey(); //obtain current key
Pageview resultPageview = result.get(); //obtain current value object //print the results
System.out.println(resultKey + ":");
printPageview(resultPageview);
} System.out.println("Number of pageviews from the query:" + result.getOffset());
} /** Pretty prints the pageview object to stdout */
private void printPageview(Pageview pageview) {
if(pageview == null) {
System.out.println("No result to show");
} else {
System.out.println(pageview.toString());
}
} private void close() throws IOException, Exception {
//It is very important to close the datastore properly, otherwise
//some data loss might occur.
if(dataStore != null)
dataStore.close();
} private static final String USAGE = "LogManager -parse <input_log_file>\n" +
" -get <lineNum>\n" +
" -query <lineNum>\n" +
" -query <startLineNum> <endLineNum>\n" +
" -delete <lineNum>\n" +
" -deleteByQuery <startLineNum> <endLineNum>\n"; public static void main(String[] args) throws Exception {
if(args.length < 2) {
System.err.println(USAGE);
System.exit(1);
} LogManager manager = new LogManager(); if("-parse".equals(args[0])) {
manager.parse(args[1]);
} else if("-get".equals(args[0])) {
manager.get(Long.parseLong(args[1]));
} else if("-query".equals(args[0])) {
if(args.length == 2)
manager.query(Long.parseLong(args[1]));
else
manager.query(Long.parseLong(args[1]), Long.parseLong(args[2]));
} else if("-delete".equals(args[0])) {
manager.delete(Long.parseLong(args[1]));
} else if("-deleteByQuery".equalsIgnoreCase(args[0])) {
manager.deleteByQuery(Long.parseLong(args[1]), Long.parseLong(args[2]));
} else {
System.err.println(USAGE);
System.exit(1);
} manager.close();
} }

2、在eclipse中run as java application,输出如下:

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/Users/liaoliuqing/99_Project/1_myCodes/MyGoraDemo/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/Users/liaoliuqing/99_Project/99_userLibrary/log4j_2.0/log4j-slf4j-impl-2.0-rc2.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/Users/liaoliuqing/1_BigData/1_Hadoop/0_Official/hadoop-1.2.1/lib/slf4j-log4j12-1.4.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

LogManager -parse <input_log_file>

           -get <lineNum>

           -query <lineNum>

           -query <startLineNum> <endLineNum>

           -delete <lineNum>

           -deleteByQuery <startLineNum> <endLineNum>

3、将项目打包并放至服务器中。

export --> runnable jar file

4、执行程序

在bin目录下执行以下命令

$ java -jar MyGoraDemo.jar  -parse resource/access.log

5、查看结果

$hbase shell



hbase(main):001:0> list

TABLE                                                                                                                                                                   

AccessLog                                                                                                                                                               

Jan2814_webpage                                                                                                                                                         

Jan2819_webpage                                                                                                                                                         

Jan2910_webpage                                                                                                                                                         

member                                                                                                                                                                  

5 row(s) in 1.2440 seconds



hbase(main):002:0> count 'AccessLog'

Current count: 1000, row: \x00\x00\x00\x00\x00\x00\x03\xE7                                                                                                              

Current count: 2000, row: \x00\x00\x00\x00\x00\x00\x07\xCF                                                                                                              

Current count: 3000, row: \x00\x00\x00\x00\x00\x00\x0B\xB7                                                                                                              

Current count: 4000, row: \x00\x00\x00\x00\x00\x00\x0F\x9F                                                                                                              

Current count: 5000, row: \x00\x00\x00\x00\x00\x00\x13\x87                                                                                                              

Current count: 6000, row: \x00\x00\x00\x00\x00\x00\x17o                                                                                                                 

Current count: 7000, row: \x00\x00\x00\x00\x00\x00\x1BW                                                                                                                 

Current count: 8000, row: \x00\x00\x00\x00\x00\x00\x1F?                                                                                                                 

Current count: 9000, row: \x00\x00\x00\x00\x00\x00#'                                                                                                                    

Current count: 10000, row: \x00\x00\x00\x00\x00\x00'\x0F                                                                                                                

10000 row(s) in 1.8960 seconds

四、程序分析

1、项目结构

2、数据库的其它操作(读取与删除)请参考官方文档。

以下为部分内容的截取,更详细内容请见http://gora.apache.org/current/tutorial.html

Fetching objects from data store



Fetching objects from the data store is as easy as storing them. There are essentially two methods for fetching objects. First one is to fetch a single object given it's key. The second method is to run a query through the data store.



To fetch objects one by one, we can use one of the overloaded get() methods. The method with signature get(K key) returns the object corresponding to the given key fetching all the fields. On the other hand get(K key, String[] fields) returns the object corresponding
to the given key, but fetching only the fields given as the second argument.



When run with the argument -get LogManager class fetches the pageview object from the data store and prints the results.



/** Fetches a single pageview object and prints it*/

private void get(long key) throws IOException {

  Pageview pageview = dataStore.get(key);

  printPageview(pageview);

}



To display the 42nd line of the access log :



$ bin/gora logmanager -get 42



org.apache.gora.tutorial.log.generated.Pageview@321ce053 {

  "url":"/index.php?i=0&amp;a=1__rntjt9z0q9w&amp;k=398179"

  "timestamp":"1236710649000"

  "ip":"88.240.129.183"

  "httpMethod":"GET"

  "httpStatusCode":"200"

  "responseSize":"43"

  "referrer":"http://www.buldinle.com/index.php?i=0&amp;a=1__RnTjT9z0Q9w&amp;k=398179"

  "userAgent":"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"

}



Querying objects



DataStore API defines a Query interface to query the objects at the data store. Each data store implementation can use a specific implementation of the Query interface. Queries are instantiated by calling DataStore#newQuery(). When the query is run through
the datastore, the results are returned via the Result interface. Let's see how we can run a query and display the results below in the the LogManager class.



/** Queries and prints pageview object that have keys between startKey and endKey*/

private void query(long startKey, long endKey) throws IOException {

  Query<Long, Pageview> query = dataStore.newQuery();

  //set the properties of query

  query.setStartKey(startKey);

  query.setEndKey(endKey);



  Result<Long, Pageview> result = query.execute();



  printResult(result);

}



After constructing a Query, its properties are set via the setter methods. Then calling query.execute() returns the Result object.



Result interface allows us to iterate the results one by one by calling the next() method. The getKey() method returns the current key and get() returns current persistent object.



private void printResult(Result<Long, Pageview> result) throws IOException {



  while(result.next()) { //advances the Result object and breaks if at end

    long resultKey = result.getKey(); //obtain current key

    Pageview resultPageview = result.get(); //obtain current value object



    //print the results

    System.out.println(resultKey + ":");

    printPageview(resultPageview);

  }



  System.out.println("Number of pageviews from the query:" + result.getOffset());

}



With these functions defined, we can run the Log Manager class, to query the access logs at HBase. For example, to display the log records between lines 10 and 12 we can use:



bin/gora logmanager -query 10 12



Which results in:



10:

org.apache.gora.tutorial.log.generated.Pageview@d38d0eaa {

  "url":"/"

  "timestamp":"1236710442000"

  "ip":"144.122.180.55"

  "httpMethod":"GET"

  "httpStatusCode":"200"

  "responseSize":"43"

  "referrer":"http://buldinle.com/"

  "userAgent":"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009020911 Ubuntu/8.10 (intrepid) Firefox/3.0.6"

}

11:

org.apache.gora.tutorial.log.generated.Pageview@b513110a {

  "url":"/index.php?i=7&amp;a=1__gefuumyhl5c&amp;k=5143555"

  "timestamp":"1236710453000"

  "ip":"85.100.75.104"

  "httpMethod":"GET"

  "httpStatusCode":"200"

  "responseSize":"43"

  "referrer":"http://www.buldinle.com/index.php?i=7&amp;a=1__GeFUuMyHl5c&amp;k=5143555"

  "userAgent":"Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7"

}



Deleting objects



Just like fetching objects, there are two main methods to delete objects from the data store. The first one is to delete objects one by one using the DataStore#delete(K key) method, which takes the key of the object. Alternatively we can delete all of the data
that matches a given query by calling the DataStore#deleteByQuery(Query query) method. By using #deleteByQuery, we can do fine-grain deletes, for example deleting just a specific field from several records. Continueing from the LogManager class, the api's
for both are given below.



/**Deletes the pageview with the given line number */

private void delete(long lineNum) throws Exception {

  dataStore.delete(lineNum);

  dataStore.flush(); //write changes may need to be flushed before they are committed

}



/** This method illustrates delete by query call */

private void deleteByQuery(long startKey, long endKey) throws IOException {

  //Constructs a query from the dataStore. The matching rows to this query will be deleted

  Query<Long, Pageview> query = dataStore.newQuery();

  //set the properties of query

  query.setStartKey(startKey);

  query.setEndKey(endKey);



  dataStore.deleteByQuery(query);

}



And from the command line :



bin/gora logmanager -delete 12

bin/gora logmanager -deleteByQuery 40 50



- See more at: http://gora.apache.org/current/tutorial.html#sthash.i7gfQUe7.dpufFetching objects from the data store is as easy as storing them. There are essentially two methods for fetching objects. First one is to fetch a single object given it's key. The
second method is to run a query through the data store.

附生成的java类:

/**
* Autogenerated by Avro
*
* DO NOT EDIT DIRECTLY
*/
package org.apache.gora.tutorial.log.generated;
@SuppressWarnings("all")
public class Pageview extends org.apache.gora.persistency.impl.PersistentBase implements org.apache.avro.specific.SpecificRecord, org.apache.gora.persistency.Persistent {
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Pageview\",\"namespace\":\"org.apache.gora.tutorial.log.generated\",\"fields\":[{\"name\":\"url\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"timestamp\",\"type\":\"long\",\"default\":0},{\"name\":\"ip\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"httpMethod\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"httpStatusCode\",\"type\":\"int\",\"default\":0},{\"name\":\"responseSize\",\"type\":\"int\",\"default\":0},{\"name\":\"referrer\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"userAgent\",\"type\":[\"null\",\"string\"],\"default\":null}],\"default\":null}"); /** Enum containing all data bean's fields. */
public static enum Field {
URL(0, "url"),
TIMESTAMP(1, "timestamp"),
IP(2, "ip"),
HTTP_METHOD(3, "httpMethod"),
HTTP_STATUS_CODE(4, "httpStatusCode"),
RESPONSE_SIZE(5, "responseSize"),
REFERRER(6, "referrer"),
USER_AGENT(7, "userAgent"),
;
/**
* Field's index.
*/
private int index; /**
* Field's name.
*/
private String name; /**
* Field's constructor
* @param index field's index.
* @param name field's name.
*/
Field(int index, String name) {this.index=index;this.name=name;} /**
* Gets field's index.
* @return int field's index.
*/
public int getIndex() {return index;} /**
* Gets field's name.
* @return String field's name.
*/
public String getName() {return name;} /**
* Gets field's attributes to string.
* @return String field's attributes to string.
*/
public String toString() {return name;}
}; public static final String[] _ALL_FIELDS = {
"url",
"timestamp",
"ip",
"httpMethod",
"httpStatusCode",
"responseSize",
"referrer",
"userAgent",
}; /**
* Gets the total field count.
* @return int field count
*/
public int getFieldsCount() {
return Pageview._ALL_FIELDS.length;
} private java.lang.CharSequence url;
private long timestamp;
private java.lang.CharSequence ip;
private java.lang.CharSequence httpMethod;
private int httpStatusCode;
private int responseSize;
private java.lang.CharSequence referrer;
private java.lang.CharSequence userAgent;
public org.apache.avro.Schema getSchema() { return SCHEMA$; }
// Used by DatumWriter. Applications should not call.
public java.lang.Object get(int field$) {
switch (field$) {
case 0: return url;
case 1: return timestamp;
case 2: return ip;
case 3: return httpMethod;
case 4: return httpStatusCode;
case 5: return responseSize;
case 6: return referrer;
case 7: return userAgent;
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
}
} // Used by DatumReader. Applications should not call.
@SuppressWarnings(value="unchecked")
public void put(int field$, java.lang.Object value) {
switch (field$) {
case 0: url = (java.lang.CharSequence)(value); break;
case 1: timestamp = (java.lang.Long)(value); break;
case 2: ip = (java.lang.CharSequence)(value); break;
case 3: httpMethod = (java.lang.CharSequence)(value); break;
case 4: httpStatusCode = (java.lang.Integer)(value); break;
case 5: responseSize = (java.lang.Integer)(value); break;
case 6: referrer = (java.lang.CharSequence)(value); break;
case 7: userAgent = (java.lang.CharSequence)(value); break;
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
}
} /**
* Gets the value of the 'url' field.
*/
public java.lang.CharSequence getUrl() {
return url;
} /**
* Sets the value of the 'url' field.
* @param value the value to set.
*/
public void setUrl(java.lang.CharSequence value) {
this.url = value;
setDirty(0);
} /**
* Checks the dirty status of the 'url' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isUrlDirty(java.lang.CharSequence value) {
return isDirty(0);
} /**
* Gets the value of the 'timestamp' field.
*/
public java.lang.Long getTimestamp() {
return timestamp;
} /**
* Sets the value of the 'timestamp' field.
* @param value the value to set.
*/
public void setTimestamp(java.lang.Long value) {
this.timestamp = value;
setDirty(1);
} /**
* Checks the dirty status of the 'timestamp' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isTimestampDirty(java.lang.Long value) {
return isDirty(1);
} /**
* Gets the value of the 'ip' field.
*/
public java.lang.CharSequence getIp() {
return ip;
} /**
* Sets the value of the 'ip' field.
* @param value the value to set.
*/
public void setIp(java.lang.CharSequence value) {
this.ip = value;
setDirty(2);
} /**
* Checks the dirty status of the 'ip' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isIpDirty(java.lang.CharSequence value) {
return isDirty(2);
} /**
* Gets the value of the 'httpMethod' field.
*/
public java.lang.CharSequence getHttpMethod() {
return httpMethod;
} /**
* Sets the value of the 'httpMethod' field.
* @param value the value to set.
*/
public void setHttpMethod(java.lang.CharSequence value) {
this.httpMethod = value;
setDirty(3);
} /**
* Checks the dirty status of the 'httpMethod' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isHttpMethodDirty(java.lang.CharSequence value) {
return isDirty(3);
} /**
* Gets the value of the 'httpStatusCode' field.
*/
public java.lang.Integer getHttpStatusCode() {
return httpStatusCode;
} /**
* Sets the value of the 'httpStatusCode' field.
* @param value the value to set.
*/
public void setHttpStatusCode(java.lang.Integer value) {
this.httpStatusCode = value;
setDirty(4);
} /**
* Checks the dirty status of the 'httpStatusCode' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isHttpStatusCodeDirty(java.lang.Integer value) {
return isDirty(4);
} /**
* Gets the value of the 'responseSize' field.
*/
public java.lang.Integer getResponseSize() {
return responseSize;
} /**
* Sets the value of the 'responseSize' field.
* @param value the value to set.
*/
public void setResponseSize(java.lang.Integer value) {
this.responseSize = value;
setDirty(5);
} /**
* Checks the dirty status of the 'responseSize' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isResponseSizeDirty(java.lang.Integer value) {
return isDirty(5);
} /**
* Gets the value of the 'referrer' field.
*/
public java.lang.CharSequence getReferrer() {
return referrer;
} /**
* Sets the value of the 'referrer' field.
* @param value the value to set.
*/
public void setReferrer(java.lang.CharSequence value) {
this.referrer = value;
setDirty(6);
} /**
* Checks the dirty status of the 'referrer' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isReferrerDirty(java.lang.CharSequence value) {
return isDirty(6);
} /**
* Gets the value of the 'userAgent' field.
*/
public java.lang.CharSequence getUserAgent() {
return userAgent;
} /**
* Sets the value of the 'userAgent' field.
* @param value the value to set.
*/
public void setUserAgent(java.lang.CharSequence value) {
this.userAgent = value;
setDirty(7);
} /**
* Checks the dirty status of the 'userAgent' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isUserAgentDirty(java.lang.CharSequence value) {
return isDirty(7);
} /** Creates a new Pageview RecordBuilder */
public static org.apache.gora.tutorial.log.generated.Pageview.Builder newBuilder() {
return new org.apache.gora.tutorial.log.generated.Pageview.Builder();
} /** Creates a new Pageview RecordBuilder by copying an existing Builder */
public static org.apache.gora.tutorial.log.generated.Pageview.Builder newBuilder(org.apache.gora.tutorial.log.generated.Pageview.Builder other) {
return new org.apache.gora.tutorial.log.generated.Pageview.Builder(other);
} /** Creates a new Pageview RecordBuilder by copying an existing Pageview instance */
public static org.apache.gora.tutorial.log.generated.Pageview.Builder newBuilder(org.apache.gora.tutorial.log.generated.Pageview other) {
return new org.apache.gora.tutorial.log.generated.Pageview.Builder(other);
} private static java.nio.ByteBuffer deepCopyToReadOnlyBuffer(
java.nio.ByteBuffer input) {
java.nio.ByteBuffer copy = java.nio.ByteBuffer.allocate(input.capacity());
int position = input.position();
input.reset();
int mark = input.position();
int limit = input.limit();
input.rewind();
input.limit(input.capacity());
copy.put(input);
input.rewind();
copy.rewind();
input.position(mark);
input.mark();
copy.position(mark);
copy.mark();
input.position(position);
copy.position(position);
input.limit(limit);
copy.limit(limit);
return copy.asReadOnlyBuffer();
} /**
* RecordBuilder for Pageview instances.
*/
public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<Pageview>
implements org.apache.avro.data.RecordBuilder<Pageview> { private java.lang.CharSequence url;
private long timestamp;
private java.lang.CharSequence ip;
private java.lang.CharSequence httpMethod;
private int httpStatusCode;
private int responseSize;
private java.lang.CharSequence referrer;
private java.lang.CharSequence userAgent; /** Creates a new Builder */
private Builder() {
super(org.apache.gora.tutorial.log.generated.Pageview.SCHEMA$);
} /** Creates a Builder by copying an existing Builder */
private Builder(org.apache.gora.tutorial.log.generated.Pageview.Builder other) {
super(other);
} /** Creates a Builder by copying an existing Pageview instance */
private Builder(org.apache.gora.tutorial.log.generated.Pageview other) {
super(org.apache.gora.tutorial.log.generated.Pageview.SCHEMA$);
if (isValidValue(fields()[0], other.url)) {
this.url = (java.lang.CharSequence) data().deepCopy(fields()[0].schema(), other.url);
fieldSetFlags()[0] = true;
}
if (isValidValue(fields()[1], other.timestamp)) {
this.timestamp = (java.lang.Long) data().deepCopy(fields()[1].schema(), other.timestamp);
fieldSetFlags()[1] = true;
}
if (isValidValue(fields()[2], other.ip)) {
this.ip = (java.lang.CharSequence) data().deepCopy(fields()[2].schema(), other.ip);
fieldSetFlags()[2] = true;
}
if (isValidValue(fields()[3], other.httpMethod)) {
this.httpMethod = (java.lang.CharSequence) data().deepCopy(fields()[3].schema(), other.httpMethod);
fieldSetFlags()[3] = true;
}
if (isValidValue(fields()[4], other.httpStatusCode)) {
this.httpStatusCode = (java.lang.Integer) data().deepCopy(fields()[4].schema(), other.httpStatusCode);
fieldSetFlags()[4] = true;
}
if (isValidValue(fields()[5], other.responseSize)) {
this.responseSize = (java.lang.Integer) data().deepCopy(fields()[5].schema(), other.responseSize);
fieldSetFlags()[5] = true;
}
if (isValidValue(fields()[6], other.referrer)) {
this.referrer = (java.lang.CharSequence) data().deepCopy(fields()[6].schema(), other.referrer);
fieldSetFlags()[6] = true;
}
if (isValidValue(fields()[7], other.userAgent)) {
this.userAgent = (java.lang.CharSequence) data().deepCopy(fields()[7].schema(), other.userAgent);
fieldSetFlags()[7] = true;
}
} /** Gets the value of the 'url' field */
public java.lang.CharSequence getUrl() {
return url;
} /** Sets the value of the 'url' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder setUrl(java.lang.CharSequence value) {
validate(fields()[0], value);
this.url = value;
fieldSetFlags()[0] = true;
return this;
} /** Checks whether the 'url' field has been set */
public boolean hasUrl() {
return fieldSetFlags()[0];
} /** Clears the value of the 'url' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder clearUrl() {
url = null;
fieldSetFlags()[0] = false;
return this;
} /** Gets the value of the 'timestamp' field */
public java.lang.Long getTimestamp() {
return timestamp;
} /** Sets the value of the 'timestamp' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder setTimestamp(long value) {
validate(fields()[1], value);
this.timestamp = value;
fieldSetFlags()[1] = true;
return this;
} /** Checks whether the 'timestamp' field has been set */
public boolean hasTimestamp() {
return fieldSetFlags()[1];
} /** Clears the value of the 'timestamp' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder clearTimestamp() {
fieldSetFlags()[1] = false;
return this;
} /** Gets the value of the 'ip' field */
public java.lang.CharSequence getIp() {
return ip;
} /** Sets the value of the 'ip' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder setIp(java.lang.CharSequence value) {
validate(fields()[2], value);
this.ip = value;
fieldSetFlags()[2] = true;
return this;
} /** Checks whether the 'ip' field has been set */
public boolean hasIp() {
return fieldSetFlags()[2];
} /** Clears the value of the 'ip' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder clearIp() {
ip = null;
fieldSetFlags()[2] = false;
return this;
} /** Gets the value of the 'httpMethod' field */
public java.lang.CharSequence getHttpMethod() {
return httpMethod;
} /** Sets the value of the 'httpMethod' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder setHttpMethod(java.lang.CharSequence value) {
validate(fields()[3], value);
this.httpMethod = value;
fieldSetFlags()[3] = true;
return this;
} /** Checks whether the 'httpMethod' field has been set */
public boolean hasHttpMethod() {
return fieldSetFlags()[3];
} /** Clears the value of the 'httpMethod' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder clearHttpMethod() {
httpMethod = null;
fieldSetFlags()[3] = false;
return this;
} /** Gets the value of the 'httpStatusCode' field */
public java.lang.Integer getHttpStatusCode() {
return httpStatusCode;
} /** Sets the value of the 'httpStatusCode' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder setHttpStatusCode(int value) {
validate(fields()[4], value);
this.httpStatusCode = value;
fieldSetFlags()[4] = true;
return this;
} /** Checks whether the 'httpStatusCode' field has been set */
public boolean hasHttpStatusCode() {
return fieldSetFlags()[4];
} /** Clears the value of the 'httpStatusCode' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder clearHttpStatusCode() {
fieldSetFlags()[4] = false;
return this;
} /** Gets the value of the 'responseSize' field */
public java.lang.Integer getResponseSize() {
return responseSize;
} /** Sets the value of the 'responseSize' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder setResponseSize(int value) {
validate(fields()[5], value);
this.responseSize = value;
fieldSetFlags()[5] = true;
return this;
} /** Checks whether the 'responseSize' field has been set */
public boolean hasResponseSize() {
return fieldSetFlags()[5];
} /** Clears the value of the 'responseSize' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder clearResponseSize() {
fieldSetFlags()[5] = false;
return this;
} /** Gets the value of the 'referrer' field */
public java.lang.CharSequence getReferrer() {
return referrer;
} /** Sets the value of the 'referrer' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder setReferrer(java.lang.CharSequence value) {
validate(fields()[6], value);
this.referrer = value;
fieldSetFlags()[6] = true;
return this;
} /** Checks whether the 'referrer' field has been set */
public boolean hasReferrer() {
return fieldSetFlags()[6];
} /** Clears the value of the 'referrer' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder clearReferrer() {
referrer = null;
fieldSetFlags()[6] = false;
return this;
} /** Gets the value of the 'userAgent' field */
public java.lang.CharSequence getUserAgent() {
return userAgent;
} /** Sets the value of the 'userAgent' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder setUserAgent(java.lang.CharSequence value) {
validate(fields()[7], value);
this.userAgent = value;
fieldSetFlags()[7] = true;
return this;
} /** Checks whether the 'userAgent' field has been set */
public boolean hasUserAgent() {
return fieldSetFlags()[7];
} /** Clears the value of the 'userAgent' field */
public org.apache.gora.tutorial.log.generated.Pageview.Builder clearUserAgent() {
userAgent = null;
fieldSetFlags()[7] = false;
return this;
} @Override
public Pageview build() {
try {
Pageview record = new Pageview();
record.url = fieldSetFlags()[0] ? this.url : (java.lang.CharSequence) defaultValue(fields()[0]);
record.timestamp = fieldSetFlags()[1] ? this.timestamp : (java.lang.Long) defaultValue(fields()[1]);
record.ip = fieldSetFlags()[2] ? this.ip : (java.lang.CharSequence) defaultValue(fields()[2]);
record.httpMethod = fieldSetFlags()[3] ? this.httpMethod : (java.lang.CharSequence) defaultValue(fields()[3]);
record.httpStatusCode = fieldSetFlags()[4] ? this.httpStatusCode : (java.lang.Integer) defaultValue(fields()[4]);
record.responseSize = fieldSetFlags()[5] ? this.responseSize : (java.lang.Integer) defaultValue(fields()[5]);
record.referrer = fieldSetFlags()[6] ? this.referrer : (java.lang.CharSequence) defaultValue(fields()[6]);
record.userAgent = fieldSetFlags()[7] ? this.userAgent : (java.lang.CharSequence) defaultValue(fields()[7]);
return record;
} catch (Exception e) {
throw new org.apache.avro.AvroRuntimeException(e);
}
}
} public Pageview.Tombstone getTombstone(){
return TOMBSTONE;
} public Pageview newInstance(){
return newBuilder().build();
} private static final Tombstone TOMBSTONE = new Tombstone(); public static final class Tombstone extends Pageview implements org.apache.gora.persistency.Tombstone { private Tombstone() { } /**
* Gets the value of the 'url' field.
*/
public java.lang.CharSequence getUrl() {
throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
} /**
* Sets the value of the 'url' field.
* @param value the value to set.
*/
public void setUrl(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
} /**
* Checks the dirty status of the 'url' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isUrlDirty(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
} /**
* Gets the value of the 'timestamp' field.
*/
public java.lang.Long getTimestamp() {
throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
} /**
* Sets the value of the 'timestamp' field.
* @param value the value to set.
*/
public void setTimestamp(java.lang.Long value) {
throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
} /**
* Checks the dirty status of the 'timestamp' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isTimestampDirty(java.lang.Long value) {
throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
} /**
* Gets the value of the 'ip' field.
*/
public java.lang.CharSequence getIp() {
throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
} /**
* Sets the value of the 'ip' field.
* @param value the value to set.
*/
public void setIp(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
} /**
* Checks the dirty status of the 'ip' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isIpDirty(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
} /**
* Gets the value of the 'httpMethod' field.
*/
public java.lang.CharSequence getHttpMethod() {
throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
} /**
* Sets the value of the 'httpMethod' field.
* @param value the value to set.
*/
public void setHttpMethod(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
} /**
* Checks the dirty status of the 'httpMethod' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isHttpMethodDirty(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
} /**
* Gets the value of the 'httpStatusCode' field.
*/
public java.lang.Integer getHttpStatusCode() {
throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
} /**
* Sets the value of the 'httpStatusCode' field.
* @param value the value to set.
*/
public void setHttpStatusCode(java.lang.Integer value) {
throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
} /**
* Checks the dirty status of the 'httpStatusCode' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isHttpStatusCodeDirty(java.lang.Integer value) {
throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
} /**
* Gets the value of the 'responseSize' field.
*/
public java.lang.Integer getResponseSize() {
throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
} /**
* Sets the value of the 'responseSize' field.
* @param value the value to set.
*/
public void setResponseSize(java.lang.Integer value) {
throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
} /**
* Checks the dirty status of the 'responseSize' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isResponseSizeDirty(java.lang.Integer value) {
throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
} /**
* Gets the value of the 'referrer' field.
*/
public java.lang.CharSequence getReferrer() {
throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
} /**
* Sets the value of the 'referrer' field.
* @param value the value to set.
*/
public void setReferrer(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
} /**
* Checks the dirty status of the 'referrer' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isReferrerDirty(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
} /**
* Gets the value of the 'userAgent' field.
*/
public java.lang.CharSequence getUserAgent() {
throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
} /**
* Sets the value of the 'userAgent' field.
* @param value the value to set.
*/
public void setUserAgent(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
} /**
* Checks the dirty status of the 'userAgent' field. A field is dirty if it represents a change that has not yet been written to the database.
* @param value the value to set.
*/
public boolean isUserAgentDirty(java.lang.CharSequence value) {
throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
} } }

版权声明:本文为博主原创文章,未经博主允许不得转载。

Gora官方范例 分类: C_OHTERS 2015-01-29 16:14 632人阅读 评论(0) 收藏的更多相关文章

  1. iOS开发网络数据之AFNetworking使用 分类: ios技术 2015-04-03 16:35 105人阅读 评论(0) 收藏

    http网络库是集XML解析,Json解析,网络图片下载,plist解析,数据流请求操作,上传,下载,缓存等网络众多功能于一身的强大的类库.最新版本支持session,xctool单元测试.网络获取数 ...

  2. Hardwood Species 分类: POJ 树 2015-08-05 16:24 2人阅读 评论(0) 收藏

    Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20619 Accepted: 8083 De ...

  3. iOS自定义字体及类目 分类: ios技术 2015-05-15 16:34 195人阅读 评论(0) 收藏

    1:获取字体文件 从各种渠道下载字体文件ttf, 网站或者从别的ipa里扣出来.(以fzltxh.ttf为例) 2:将fzltxh.ttf文件拷贝到工程中 3:在Info.plist中添加项: Fon ...

  4. iOS纯代码手动适配 分类: ios技术 2015-05-04 17:14 239人阅读 评论(0) 收藏

    首先说下让自己的程序支持iPhone6和6+,第一种使用官方提供的launch screen.xib,这个直接看官方文档即可,这里不再多述:第二种方法是和之前iPhone5的类似,比较简单,为iPho ...

  5. NPOI 通用导出数据到Excel 分类: C# Helper 2014-11-04 16:06 246人阅读 评论(0) 收藏

    应用场景: 在项目中,经常遇到将数据库数据导出到Excel,针对这种情况做了个程序封装.工作原理:利用NPOI将SQL语句查询出的DataTable数据导出到Excel,所见即所得. 程序界面:   ...

  6. ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 175人阅读 评论(0) 收藏

    一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...

  7. ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 174人阅读 评论(0) 收藏

    一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...

  8. Prime Path 分类: 搜索 POJ 2015-08-09 16:21 4人阅读 评论(0) 收藏

    Prime Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14091 Accepted: 7959 Descripti ...

  9. Removing Columns 分类: 贪心 CF 2015-08-08 16:10 10人阅读 评论(0) 收藏

    Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

随机推荐

  1. Windows学习总结(5)——【IIS建站】Windows10怎么打开站点服务?

    从Windows8开始,界面发生了很大的变动,再到Windows10,仍然有不小的变动,鉴于以后Windows10会成为主流,我们姑且介绍下Windows10建站的方法,虽然它并不是专业的服务器系统, ...

  2. 洛谷 P1405 苦恼的小明

    P1405 苦恼的小明 题目描述 黄小明和他的合伙人想要创办一所英语培训机构,注册的时候要填一张个人情况的表格,在身高一栏小明犯了愁. 身高要求精确到厘米,但小明实在太高了,无法在纸上填下这么长的数字 ...

  3. 洛谷 P1911 L国的战斗之排兵布阵

    P1911 L国的战斗之排兵布阵 题目背景 L国即将与I国发动战争!! 题目描述 L国的指挥官想让他的每一个军营都呈现出国徽形——“L”形(方向无所谓).当然,他的指挥营除外(这叫做个性),他想不出该 ...

  4. cocoapod卡在了analyzing dependencies

    尽管公司的项目没有使用cocoapod,可是有一些第三方库本身依赖其它第三方的库,而且是用cocoapod来管理这些依赖的.所以在使用某些第三方库时.还是须要用到cocoapod的.今天在github ...

  5. 【Android Studio探索之路系列】之六:Android Studio加入依赖

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.co ...

  6. Mysql数据库的瓶颈处理一点建议

    Mysql数据库的瓶颈处理一点建议         我们在使用Mysql数据库是常见的两个瓶颈是CPU和I/O的瓶颈,CPU在饱和的时候一般发生在数据装入内存或从磁盘上读取数据时候.磁盘I/O瓶颈的出 ...

  7. position记录

    1.  relative(相对定位):生成相对定位的元素,通过top,bottom,left,right的设置相对于其正常(原先本身)位置进行定位.可通过z-index进行层次分级.均是以父级的左上角 ...

  8. bzoj3786星系探索(splay维护dfs序)

    Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为1号星球),其余的所有星球均有且仅有一个依赖星球.主星球 ...

  9. 3/19 Django框架 url路由配置及模板渲染

    3/19 Django框架 url路由配置及模板渲染 1.路由分配 URL(Uniform Resoure Locato):统一资源定位符是对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示, ...

  10. Quartz学习总结(1)——Spring集成Quartz框架

    一.Quartz简介 Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与J2SE应用程序相结合也可以单独使用.Quartz可以用来创建简 ...