1 package com.daffodilwoods.daffodildb.utils; 2 3 import com.daffodilwoods.daffodildb.utils.field.*; 4 import com.daffodilwoods.daffodildb.server.sql99.common.Datatypes; 5 import java.math.BigDecimal ; 6 import java.sql.Blob ; 7 import java.sql.Clob ; 8 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs; 9 import java.util.Date ; 10 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.literal; 11 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.TableKey; 12 import java.sql.Time ; 13 import java.sql.Timestamp ; 14 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.DClobUpdatable; 15 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.DBlobUpdatable; 16 import java.sql.*; 17 import java.text.Collator ; 18 19 public class FieldBaseConverter { 20 21 public FieldBaseConverter() { 22 } 23 24 public static FieldBase getFieldBase(byte[] bytes, int datatype){ 25 BufferRange buffer = bytes == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(bytes); 26 return new FieldLiteral(buffer,datatype); 27 } 28 29 public static FieldBase getFieldBase(Byte bytes, int datatype){ 30 BufferRange buffer = bytes == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(new byte[] {bytes.byteValue()}); 31 return new FieldByte(buffer,datatype); 32 } 33 34 35 public static FieldBase getFieldBase(BigDecimal bigDecimal, int datatype){ 36 BufferRange buffer = bigDecimal == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(bigDecimal)); 37 return new FieldBigDecimal(buffer,datatype); 38 } 39 40 public static FieldBase getFieldBase(Blob blob){ 41 try { 42 return blob == null ? new DBlobUpdatable(true) : new DBlobUpdatable(blob.getBinaryStream()); 43 } 44 catch (SQLException ex) { 45 return null; 46 } 47 } 48 49 public static FieldBase getFieldBase(Boolean b){ 50 BufferRange buffer = b == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(b)); 51 return new FieldBoolean(buffer,Datatypes.BOOLEAN); 52 } 53 54 public static FieldBase getFieldBase(Clob clob){ 55 try { 56 return clob == null ? new DClobUpdatable(true) : new DClobUpdatable(clob.getAsciiStream()); 57 } 58 catch (SQLException ex) { 59 return null; 60 } 61 } 62 63 public static FieldBase getFieldBase(Date date){ 64 BufferRange buffer = date == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(date)); 65 return new FieldDate(buffer,Datatypes.DATE); 66 } 67 68 public static FieldBase getFieldBase(Double d, int datatype){ 69 BufferRange buffer = d == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(d)); 70 return new FieldDouble(buffer,datatype); 71 } 72 73 public static FieldBase getFieldBase(Integer i, int datatype){ 74 BufferRange buffer = i == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(i)); 75 return new FieldInteger(buffer,datatype); 76 } 77 78 public static FieldBase getFieldBase(Long l, int datatype){ 79 BufferRange buffer = l == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(l)); 80 return new FieldLong(buffer,datatype); 81 } 82 83 public static FieldBase getFieldBase(Float f, int datatype){ 84 BufferRange buffer = f == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(f)); 85 return new FieldReal(buffer,datatype); 86 } 87 88 public static FieldBase getFieldBase(Short s, int datatype){ 89 BufferRange buffer = s == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(s)); 90 return new FieldShort(new BufferRange(CCzufDpowfsufs.getBytes(s)),datatype); 91 } 92 93 public static FieldBase getFieldBase(String str, int datatype,Collator collator){ 94 BufferRange buffer = str == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(str,str.length(),collator != null)); 95 return new FieldString(buffer,datatype,collator); 96 } 97 98 public static FieldBase getFieldBase(Time time){ 99 BufferRange buffer = time == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(time)); 100 return new FieldTime(buffer,Datatypes.TIME); 101 } 102 103 public static FieldBase getFieldBase(Timestamp times){ 104 BufferRange buffer = times == null ? FieldUtility.NULLBUFFERRANGE : new BufferRange(CCzufDpowfsufs.getBytes(times)); 105 return new FieldTimeStamp(buffer,Datatypes.TIMESTAMP); 106 } 107 } 108 | Popular Tags |