1 2 12 package com.versant.core.jdbc.sql.conv; 13 14 import com.versant.core.jdbc.JdbcConverter; 15 16 22 public class LongArrayConverter extends TypeAsBytesConverterBase { 23 24 public static class Factory extends TypeAsBytesConverterBase.Factory { 25 26 protected JdbcConverter createConverter(JdbcConverter nested) { 27 return new LongArrayConverter(nested); 28 } 29 30 } 31 32 public LongArrayConverter(JdbcConverter nested) { 33 super(nested); 34 } 35 36 39 protected Object fromByteArray(byte[] buf) { 40 int n = buf.length / 8; 41 long[] a = new long[n]; 42 int i = 0, j = 0; 43 for (; i < n; ) { 44 a[i++] = ((long)(buf[j++] & 0xFF) << 56) 45 + ((long)(buf[j++] & 0xFF) << 48) 46 + ((long)(buf[j++] & 0xFF) << 40) 47 + ((long)(buf[j++] & 0xFF) << 32) 48 + ((long)(buf[j++] & 0xFF) << 24) 49 + ((buf[j++] & 0xFF) << 16) 50 + ((buf[j++] & 0xFF) << 8) 51 + (buf[j++] & 0xFF); 52 } 53 return a; 54 } 55 56 59 protected byte[] toByteArray(Object value) { 60 if (value == null) return null; 61 long[] a = (long[])value; 62 int n = a.length; 63 byte[] buf = new byte[n * 8]; 64 int i = 0, j = 0; 65 for (; i < n; ) { 66 long x = a[i++]; 67 buf[j++] = (byte)((x >>> 56) & 0xFF); 68 buf[j++] = (byte)((x >>> 48) & 0xFF); 69 buf[j++] = (byte)((x >>> 40) & 0xFF); 70 buf[j++] = (byte)((x >>> 32) & 0xFF); 71 buf[j++] = (byte)((x >>> 24) & 0xFF); 72 buf[j++] = (byte)((x >>> 16) & 0xFF); 73 buf[j++] = (byte)((x >>> 8) & 0xFF); 74 buf[j++] = (byte)(x & 0xFF); 75 } 76 return buf; 77 } 78 79 83 public Class getValueType() { 84 return long[].class; 85 } 86 87 } 88 89 | Popular Tags |