Package org.apache.gora.mock.persistency

Source Code of org.apache.gora.mock.persistency.MockPersistent

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.gora.mock.persistency;

import org.apache.avro.Schema;
import org.apache.gora.persistency.Persistent;
import org.apache.gora.persistency.Tombstone;
import org.apache.gora.persistency.impl.PersistentBase;

public class MockPersistent extends PersistentBase {

  public static final String FOO = "foo";
  public static final String BAZ = "baz";
 
  public static final String[] _ALL_FIELDS = {FOO, BAZ};
 
  private int foo;
  private int baz;
 
  public MockPersistent() {
  }
 
 
  @Override
  public Object get(int field) {
    switch(field) {
      case 0: return foo;
      case 1: return baz;
    }
    return null;
  }

  @Override
  public void put(int field, Object value) {
    switch(field) {
      case 0:  foo = (Integer)value;
      case 1:  baz = (Integer)value;
    }
  }

  @Override
  public Schema getSchema() {
    Schema.Parser parser = new Schema.Parser();
    return parser.parse("{\"type\":\"record\",\"name\":\"MockPersistent\",\"namespace\":\"org.apache.gora.mock.persistency\",\"fields\":[{\"name\":\"foo\",\"type\":\"int\"},{\"name\":\"baz\",\"type\":\"int\"}]}");
  }
 
  public void setFoo(int foo) {
    this.foo = foo;
  }
 
  public void setBaz(int baz) {
    this.baz = baz;
  }
 
  public int getFoo() {
    return foo;
  }
 
  public int getBaz() {
    return baz;
  }

  @Override
  public Tombstone getTombstone() {
    return new Tombstone(){};
  }

  @Override
  public Persistent newInstance() {
    return new MockPersistent();
  }

}
TOP

Related Classes of org.apache.gora.mock.persistency.MockPersistent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.