Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.persist.impl;
  
 
Widens a value returned by another input when any readXxx method is called. Used to cause an Accessor to read a widened value. For non-key fields we support all Java primitive widening: - byte to short, int, long, float, double, BigInteger and BigDecimal - short to int, long, float, double, BigInteger and BigDecimal - char to int, long, float, double, BigInteger and BigDecimal - int to long, float, double, BigInteger and BigDecimal - long to float, double, BigInteger and BigDecimal - float to double For non-key fields we also support: - Java reference widening - primitive to primitive wrapper - Java primitive widening to corresponding primitive wrappers - Java widening of primitive wrapper to primitive wrapper For secondary keys fields we ONLY support: - primitive to primitive wrapper But for primary keys and composite key fields we ONLY support: - primitive to primitive wrapper - primitive wrapper to primitive These conversions don't require any converter, since the stored format is not changed. A WidenerInput is not used for these changes.

Author(s):
Mark Hayes
 
 class WidenerInput extends AbstractInput {
 
     private EntityInput input;
     private int fromFormatId;
     private int toFormatId;

    
Returns whether widening is supported by this class. If false is returned by this method, then widening is disallowed and a field converter or deleter is necessary.
 
     static boolean isWideningSupported(Format fromFormat,
                                        Format toFormat,
                                        boolean isSecKeyField) {
         int fromFormatId = fromFormat.getId();
         int toFormatId = toFormat.getId();
 
         switch (fromFormatId) {
         case .:
             switch (toFormatId) {
             case .:
                 return true;
             default:
                 return false;
             }
         case .:
             switch (toFormatId) {
             case .:
                 return true;
             case .:
             case .:
             case .:
             case .:
             case .:
             case .:
             case .:
             case .:
             case .:
             case .:
             case .:
                 return !isSecKeyField;
             default:
                 return false;
             }
         case .:
             switch (toFormatId) {
             case .:
             case .:
             case .:
             case .:
             case .:
             case .:
                 return !isSecKeyField;
             default:
                 return false;
             }
        case .:
            switch (toFormatId) {
            case .:
                return true;
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
            case .:
            case .:
            case .:
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
                return true;
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
            case .:
            case .:
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
                return true;
            case .:
            case .:
            case .:
            case .:
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
            case .:
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
                return true;
            case .:
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
                return true;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
                return true;
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
            case .:
            case .:
            case .:
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        case .:
            switch (toFormatId) {
            case .:
                return !isSecKeyField;
            default:
                return false;
            }
        default:
            return false;
        }
    }
    WidenerInput(EntityInput inputint fromFormatIdint toFormatId) {
        super(input.getCatalog(), input.isRawAccess());
        this. = input;
        this. = fromFormatId;
        this. = toFormatId;
    }
    public void registerPriKeyObject(Object o) {
        .registerPriKeyObject(o);
    }
    public void registerPriStringKeyObject(Object o) {
    }
    public int readArrayLength() {
        throw DbCompat.unexpectedState();
    }
    public int readEnumConstant(String[] names) {
        throw DbCompat.unexpectedState();
    }
    public void skipField(Format declaredFormat) {
        throw DbCompat.unexpectedState();
    }
    public String readString() {
        throw DbCompat.unexpectedState();
    }
    public Object readKeyObject(Format fromFormat)
        throws RefreshException {
        return readObject();
    }
    public Object readObject()
        throws RefreshException {
        switch () {
        case .:
            checkToFormat(.);
            return .readBoolean();
        case .:
            return byteToObject(.readByte());
        case .:
            Byte b = (Byte.readObject();
            return (b != null) ? byteToObject(b) : null;
        case .:
            return shortToObject(.readShort());
        case .:
            Short s = (Short.readObject();
            return (s != null) ? shortToObject(s) : null;
        case .:
            return intToObject(.readInt());
        case .:
            Integer i = (Integer.readObject();
            return (i != null) ? intToObject(i) : null;
        case .:
            return longToObject(.readLong());
        case .:
            Long l = (Long.readObject();
            return (l != null) ? longToObject(l) : null;
        case .:
            return floatToObject(.readSortedFloat());
        case .:
            Float f = (Float.readObject();
            return (f != null) ? floatToObject(f) : null;
        case .:
            checkToFormat(.);
            return .readSortedDouble();
        case .:
            return charToObject(.readChar());
        case .:
            Character c = (Character.readObject();
            return (c != null) ? charToObject(c) : null;
        case .:
            checkToFormat(.);
            return .readStringObject();
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    private Object byteToObject(byte v) {
        switch () {
        case .:
        case .:
            return Byte.valueOf(v);
        case .:
        case .:
            return Short.valueOf(v);
        case .:
        case .:
            return Integer.valueOf(v);
        case .:
        case .:
            return Long.valueOf(v);
        case .:
        case .:
            return Float.valueOf(v);
        case .:
        case .:
            return Double.valueOf(v);
        case .:
            return BigInteger.valueOf(v);
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    private Object shortToObject(short v) {
        switch () {
        case .:
        case .:
            return Short.valueOf(v);
        case .:
        case .:
            return Integer.valueOf(v);
        case .:
        case .:
            return Long.valueOf(v);
        case .:
        case .:
            return Float.valueOf(v);
        case .:
        case .:
            return Double.valueOf(v);
        case .:
            return BigInteger.valueOf(v);
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    private Object intToObject(int v) {
        switch () {
        case .:
        case .:
            return Integer.valueOf(v);
        case .:
        case .:
            return Long.valueOf(v);
        case .:
        case .:
            return Float.valueOf(v);
        case .:
        case .:
            return Double.valueOf(v);
        case .:
            return BigInteger.valueOf(v);
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    private Object longToObject(long v) {
        switch () {
        case .:
        case .:
            return Long.valueOf(v);
        case .:
        case .:
            return Float.valueOf(v);
        case .:
        case .:
            return Double.valueOf(v);
        case .:
            return BigInteger.valueOf(v);
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    private Object floatToObject(float v) {
        switch () {
        case .:
        case .:
            return Float.valueOf(v);
        case .:
        case .:
            return Double.valueOf(v);
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    private Object charToObject(char v) {
        switch () {
        case .:
        case .:
            return Character.valueOf(v);
        case .:
        case .:
            return Integer.valueOf(v);
        case .:
        case .:
            return Long.valueOf(v);
        case .:
        case .:
            return Float.valueOf(v);
        case .:
        case .:
            return Double.valueOf(v);
        case .:
            return BigInteger.valueOf(v);
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    public char readChar() {
        throw DbCompat.unexpectedState(String.valueOf());
    }
    public boolean readBoolean() {
        throw DbCompat.unexpectedState(String.valueOf());
    }
    public byte readByte() {
        throw DbCompat.unexpectedState(String.valueOf());
    }
    public short readShort()
        throws RefreshException {
        checkToFormat(.);
        switch () {
        case .:
            return .readByte();
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    public int readInt()
        throws RefreshException {
        checkToFormat(.);
        switch () {
        case .:
            return .readByte();
        case .:
            return .readShort();
        case .:
            return .readChar();
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    public long readLong()
        throws RefreshException {
        checkToFormat(.);
        switch () {
        case .:
            return .readByte();
        case .:
            return .readShort();
        case .:
            return .readInt();
        case .:
            return .readChar();
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    public float readSortedFloat()
        throws RefreshException {
        checkToFormat(.);
        switch () {
        case .:
            return .readByte();
        case .:
            return .readShort();
        case .:
            return .readInt();
        case .:
            return .readLong();
        case .:
            return .readChar();
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    public double readSortedDouble()
        throws RefreshException {
        switch () {
        case .:
            return .readByte();
        case .:
            return .readShort();
        case .:
            return .readInt();
        case .:
            return .readLong();
        case .:
            return .readSortedFloat();
        case .:
            return .readChar();
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    public BigInteger readBigInteger()
        throws RefreshException {
        switch () {
        case .:
            return BigInteger.valueOf(.readByte());
        case .:
            return BigInteger.valueOf(.readShort());
        case .:
            return BigInteger.valueOf(.readInt());
        case .:
            return BigInteger.valueOf(.readLong());
        case .:
            return BigInteger.valueOf(.readChar());
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    
    public BigDecimal readSortedBigDecimal() 
        throws RefreshException {
        switch () {
        case .:
            return BigDecimal.valueOf(.readByte());
        case .:
            return BigDecimal.valueOf(.readShort());
        case .:
            return BigDecimal.valueOf(.readInt());
        case .:
            return BigDecimal.valueOf(.readLong());
        case .:
            return BigDecimal.valueOf(.readChar());
        default:
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    private void checkToFormat(int id) {
        if ( != id) {
            throw DbCompat.unexpectedState(String.valueOf());
        }
    }
    public Object readStringObject(){
        throw DbCompat.unexpectedState();
    }
New to GrepCode? Check out our FAQ X