Package org.h2.test.jaqu

Source Code of org.h2.test.jaqu.SupportedTypes

/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: James Moger
*/
package org.h2.test.jaqu;

import java.math.BigDecimal;
import java.util.List;
import java.util.Random;
import org.h2.jaqu.Table.JQColumn;
import org.h2.jaqu.Table.JQTable;
import org.h2.util.New;

/**
* A data class that contains a column for each data type.
*/
@JQTable(strictTypeMapping = true, version = 1)
public class SupportedTypes {

    static final SupportedTypes SAMPLE = new SupportedTypes();

    @JQColumn(primaryKey = true, autoIncrement = true)
    public Integer id;

    @JQColumn
    private Boolean myBool = false;

    @JQColumn
    private Byte myByte = 2;

    @JQColumn
    private Short myShort;

    @JQColumn
    private Integer myInteger;

    @JQColumn
    private Long myLong;

    @JQColumn
    private Float myFloat = 1.0f;

    @JQColumn
    private Double myDouble;

    @JQColumn
    private BigDecimal myBigDecimal;

    @JQColumn
    private String myString;

    @JQColumn
    private java.util.Date myUtilDate;

    @JQColumn
    private java.sql.Date mySqlDate;

    @JQColumn
    private java.sql.Time mySqlTime;

    @JQColumn
    private java.sql.Timestamp mySqlTimestamp;

    static List<SupportedTypes> createList() {
        List<SupportedTypes> list = New.arrayList();
        for (int i = 0; i < 10; i++) {
            list.add(randomValue());
        }
        return list;
    }

    static SupportedTypes randomValue() {
        Random rand = new Random();
        SupportedTypes s = new SupportedTypes();
        s.myBool = new Boolean(rand.nextBoolean());
        s.myByte = new Byte((byte) rand.nextInt(Byte.MAX_VALUE));
        s.myShort = new Short((short) rand.nextInt(Short.MAX_VALUE));
        s.myInteger = new Integer(rand.nextInt());
        s.myLong = new Long(rand.nextLong());
        s.myFloat = new Float(rand.nextFloat());
        s.myDouble = new Double(rand.nextDouble());
        s.myBigDecimal = new BigDecimal(rand.nextDouble());
        s.myString = Long.toHexString(rand.nextLong());
        s.myUtilDate = new java.util.Date(rand.nextLong());
        s.mySqlDate = new java.sql.Date(rand.nextLong());
        s.mySqlTime = new java.sql.Time(rand.nextLong());
        s.mySqlTimestamp = new java.sql.Timestamp(rand.nextLong());
        return s;
    }

    public boolean equivalentTo(SupportedTypes s) {
        boolean same = true;
        same &= myBool.equals(s.myBool);
        same &= myByte.equals(s.myByte);
        same &= myShort.equals(s.myShort);
        same &= myInteger.equals(s.myInteger);
        same &= myLong.equals(s.myLong);
        same &= myFloat.equals(s.myFloat);
        same &= myDouble.equals(s.myDouble);
        same &= myBigDecimal.equals(s.myBigDecimal);
        same &= myUtilDate.getTime() == s.myUtilDate.getTime();
        same &= mySqlTimestamp.getTime() == s.mySqlTimestamp.getTime();
        same &= mySqlDate.toString().equals(s.mySqlDate.toString());
        same &= mySqlTime.toString().equals(s.mySqlTime.toString());
        same &= myString.equals(s.myString);
        return same;
    }

    /**
     * This class demonstrates the table upgrade.
     */
    @JQTable(name = "SupportedTypes", version = 2, inheritColumns = true, strictTypeMapping = true)
    public static class SupportedTypes2 extends SupportedTypes {

        public SupportedTypes2() {
            // nothing to do
        }
    }
}
TOP

Related Classes of org.h2.test.jaqu.SupportedTypes

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.