Package org.objectweb.speedo.ejb.pobjects.basic

Source Code of org.objectweb.speedo.ejb.pobjects.basic.FieldBasicType

/**
* Copyright (C) 2001-2005 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package org.objectweb.speedo.ejb.pobjects.basic;

import junit.framework.Assert;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* This class contains the primitive type that Speedo must support:
* boolean
* byte
* short
* int
* long
* float
* double
* char
* Boolean
* Byte
* Short
* Integer
* Long
* Float
* Double
* Character
* String
* BigDecimal
* BigInteger
* It defines a persistent attribute for each of them. They are defined through
* Java class fields.
*
* @author P. Dechamboux
*/
@Entity
@Table(name="EJB_FIELDBASICTYPE")
public class FieldBasicType implements Serializable {
  @Id
  @Column(name="ID")
  private Long oid;
  @Column(name="FBOOLEAN")
  private boolean boolean_field;
  @Column(name="FBYTE")
  private byte byte_field;
  @Column(name="FSHORT")
  private short short_field;
  @Column(name="FINT")
  private int int_field;
  @Column(name="FLONG")
  private long long_field;
  @Column(name="FFLOAT")
  private float float_field;
  @Column(name="FDOUBLE")
  private double double_field;
  @Column(name="FCHAR")
  private char char_field;

  @Column(name="FOBOOLEAN")
  private Boolean oboolean_field;
  @Column(name="FOBYTE")
  private Byte obyte_field;
  @Column(name="FOSHORT")
  private Short oshort_field;
  @Column(name="FOINT")
  private Integer oint_field;
  @Column(name="FOLONG")
  private Long olong_field;
  @Column(name="FOFLOAT")
  private Float ofloat_field;
  @Column(name="FODOUBLE")
  private Double odouble_field;
  @Column(name="FOCHAR")
  private Character ochar_field;

  @Column(name="FCHARARRAY")
  private char[] chararray_field;
  @Column(name="FBYTEARRAY")
  private byte[] bytearray_field;
  @Column(name="FDOUBLEARRAY")
  private double[] doubleArray_field;
  @Column(name="FSTRING")
  private String string_field;
  @Column(name="FBIGDECIMAL")
  private BigDecimal bigdecimal_field;
  @Column(name="FBIGINTEGER")
  private BigInteger biginteger_field;
 
  public void assign(long longval) {
    this.boolean_field = (longval % 2) == 1;
    this.oboolean_field = (boolean_field ? new Boolean(boolean_field) : null);

    this.byte_field = (byte) longval;
    this.obyte_field = (boolean_field ? new Byte(byte_field) : null);

    this.char_field = (char) longval;
    this.ochar_field = (boolean_field ? new Character(char_field) : null);

    this.short_field = (short) longval;
    this.oshort_field = (boolean_field ? new Short(short_field) : null);

    this.int_field = (int) longval;
    this.oint_field = (boolean_field ? new Integer(int_field) : null);

    this.long_field = longval;
    this.olong_field = (boolean_field ? new Long(long_field) : null);

    this.float_field = longval;
    this.ofloat_field = (boolean_field ? new Float(float_field) : null);

    this.double_field = longval;
    this.odouble_field = (boolean_field ? new Double(double_field) : null);

    this.chararray_field = (boolean_field ? new char[] {char_field} : null);
    this.bytearray_field = (boolean_field ? new byte[] {byte_field} : null);
    this.doubleArray_field = (boolean_field ? new double[] {double_field} : null);
    this.string_field = (boolean_field ? "str" + longval : null);
    biginteger_field = (boolean_field ? new BigInteger("" + longval) : null);
    bigdecimal_field = (boolean_field ? new BigDecimal(biginteger_field) : null);
  }

  public void check(long longval) {
    boolean isnull = (longval % 2) != 1;
    Assert.assertEquals("bad boolean_field value", boolean_field, (longval % 2) == 1);
    Assert.assertEquals("bad boolean_field value", byte_field, (byte) longval);
    Assert.assertEquals("bad boolean_field value", char_field, (char) longval);
    Assert.assertEquals("bad boolean_field value", short_field, (short) longval);
    Assert.assertEquals("bad boolean_field value", int_field, (int) longval);
    Assert.assertEquals("bad boolean_field value", long_field, longval);
    if (isnull) {
      Assert.assertNull("oboolean_field not null", oboolean_field);
      Assert.assertNull("obyte_field not null", obyte_field);
      Assert.assertNull("ochar_field not null", ochar_field);
      Assert.assertNull("oshort_field not null", oshort_field);
      Assert.assertNull("oint_field not null", oint_field);
      Assert.assertNull("olong_field not null", olong_field);
      Assert.assertNull("ofloat_field not null", ofloat_field);
      Assert.assertNull("odouble_field not null", odouble_field);
      Assert.assertNull("chararray_field not null", chararray_field);
      Assert.assertNull("bytearray_field not null", bytearray_field);
      Assert.assertNull("doublearray_field not null", doubleArray_field);
      Assert.assertNull("string_field not null", string_field);
      Assert.assertNull("biginteger_field not null", biginteger_field);
      Assert.assertNull("bigdecimal_field not null", bigdecimal_field);
    } else {
      Assert.assertNotNull("oboolean_field null", oboolean_field);
      Assert.assertNotNull("obyte_field null", obyte_field);
      Assert.assertNotNull("ochar_field null", ochar_field);
      Assert.assertNotNull("oshort_field null", oshort_field);
      Assert.assertNotNull("oint_field null", oint_field);
      Assert.assertNotNull("olong_field null", olong_field);
      Assert.assertNotNull("ofloat_field null", ofloat_field);
      Assert.assertNotNull("odouble_field null", odouble_field);
      Assert.assertNotNull("chararray_field null", chararray_field);
      Assert.assertNotNull("bytearray_field null", bytearray_field);
      Assert.assertNotNull("doubleArray_field null", doubleArray_field);
      Assert.assertNotNull("string_field null", string_field);
      Assert.assertNotNull("biginteger_field null", biginteger_field);
      Assert.assertNotNull("bigdecimal_field null", bigdecimal_field);

      Assert.assertEquals("oboolean_field bad value", boolean_field, oboolean_field.booleanValue());
      Assert.assertEquals("obyte_field bad value", byte_field, obyte_field.byteValue());
      Assert.assertEquals("ochar_field bad value", char_field, ochar_field.charValue());
      Assert.assertEquals("oshort_field bad value", short_field, oshort_field.shortValue());
      Assert.assertEquals("oint_field bad value", int_field, oint_field.intValue());
      Assert.assertEquals("olong_field bad value", long_field, olong_field.longValue());
      Assert.assertEquals("chararray_field bad value", 1, chararray_field.length);
      Assert.assertEquals("chararray_field bad value", char_field, chararray_field[0]);
      Assert.assertEquals("bytearray_field bad value", 1, bytearray_field.length);
      Assert.assertEquals("bytearray_field bad value", byte_field, bytearray_field[0]);
      Assert.assertEquals("doubleArray_field bad value", 1, doubleArray_field.length);
      Assert.assertEquals("string_field bad value", "str" + longval, string_field);
      Assert.assertEquals("biginteger_field bad value", new BigInteger("" + longval), biginteger_field);
      BigDecimal expected = new BigDecimal(biginteger_field);
      BigDecimal found = bigdecimal_field;
      Assert.assertTrue("bigdecimal_field bad value, expected " + expected
        + ", found: " + found,
        expected.compareTo(found)==0);
    }
  }

  public boolean retrieve_boolean_field() {
    return boolean_field;
  }

  public void assign_boolean_field(boolean boolean_field) {
    this.boolean_field = boolean_field;
  }

  public byte retrieve_byte_field() {
    return byte_field;
  }

  public void assign_byte_field(byte byte_field) {
    this.byte_field = byte_field;
  }

  public short retrieve_short_field() {
    return short_field;
  }

  public void assign_short_field(short short_field) {
    this.short_field = short_field;
  }

  public int retrieve_int_field() {
    return int_field;
  }

  public void assign_int_field(int int_field) {
    this.int_field = int_field;
  }

  public long retrieve_long_field() {
    return long_field;
  }

  public void assign_long_field(long long_field) {
    this.long_field = long_field;
  }

  public float retrieve_float_field() {
    return float_field;
  }

  public void assign_float_field(float float_field) {
    this.float_field = float_field;
  }

  public double retrieve_double_field() {
    return double_field;
  }

  public void assign_double_field(double double_field) {
    this.double_field = double_field;
  }

  public char retrieve_char_field() {
    return char_field;
  }

  public void assign_char_field(char char_field) {
    this.char_field = char_field;
  }

  public Boolean retrieve_oboolean_field() {
    return oboolean_field;
  }

  public void assign_oboolean_field(Boolean oboolean_field) {
    this.oboolean_field = oboolean_field;
  }

  public Byte retrieve_obyte_field() {
    return obyte_field;
  }

  public void assign_obyte_field(Byte obyte_field) {
    this.obyte_field = obyte_field;
  }

  public Short retrieve_oshort_field() {
    return oshort_field;
  }

  public void assign_oshort_field(Short oshort_field) {
    this.oshort_field = oshort_field;
  }

  public Integer retrieve_oint_field() {
    return oint_field;
  }

  public void assign_oint_field(Integer oint_field) {
    this.oint_field = oint_field;
  }

  public Long retrieve_olong_field() {
    return olong_field;
  }

  public void assign_olong_field(Long olong_field) {
    this.olong_field = olong_field;
  }

  public Float retrieve_Float_field() {
    return ofloat_field;
  }

  public void assign_Float_field(Float Float_field) {
    this.ofloat_field = Float_field;
  }

  public Double retrieve_Double_field() {
    return odouble_field;
  }

  public void assign_Double_field(Double Double_field) {
    this.odouble_field = Double_field;
  }

  public Character retrieve_ochar_field() {
    return ochar_field;
  }

  public void assign_ochar_field(Character ochar_field) {
    this.ochar_field = ochar_field;
  }

  public String retrieve_string_field() {
    return string_field;
  }

  public void assign_string_field(String string_field) {
    this.string_field = string_field;
  }

  public BigDecimal retrieve_bigdecimal_field() {
    return bigdecimal_field;
  }

  public void assign_bigdecimal_field(BigDecimal bigdecimal_field) {
    this.bigdecimal_field = bigdecimal_field;
  }

  public BigInteger retrieve_biginteger_field() {
    return biginteger_field;
  }

  public void assign_biginteger_field(BigInteger biginteger_field) {
    this.biginteger_field = biginteger_field;
  }

  public char[] retrieve_chararray_field() {
    return chararray_field;
  }

  public void assign_chararray_field(char[] chararray_field) {
    this.chararray_field = chararray_field;
  }

  public byte[] retrieve_bytearray_field() {
    return bytearray_field;
  }

  public void assign_bytearray_field(byte[] bytearray_field) {
    this.bytearray_field = bytearray_field;
  }

  public double[] retrieve_doublearray_field() {
    return doubleArray_field;
  }

  public void assign_doublearray_field(double[] doubleArray_field) {
    this.doubleArray_field = doubleArray_field;
  }
}
TOP

Related Classes of org.objectweb.speedo.ejb.pobjects.basic.FieldBasicType

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.