@Override public Object getResult(CommandContext commandContext) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { return new ArrayImpl(vals); }
@Override public Object getResult(CommandContext commandContext) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException,TeiidProcessingException { if (this.result == null) { return null; } if (this.componentType == DataTypeManager.DefaultDataClasses.OBJECT) { return new ArrayImpl(this.result.toArray()); } Object array = Array.newInstance(componentType, this.result.size()); for (int i = 0; i < result.size(); i++) { Object val = result.get(i); if (val instanceof ArrayImpl) { val = ((ArrayImpl)val).getValues(); } Array.set(array, i, val); } return new ArrayImpl((Object[]) array); }
@Override public int compareTo(ArrayImpl o) { return compareTo(o, false, null); }
public int compareTo(ArrayImpl o, boolean noNulls, Comparator<Object> comparator) { if (zeroBased != o.zeroBased) { throw new TeiidRuntimeException("Incompatible types"); //$NON-NLS-1$ } try { checkValues(); o.checkValues(); } catch (SQLException e) { throw new TeiidRuntimeException(e); } Object[] values2 = o.values; return compare(noNulls, comparator, values, values2); }
@Override protected Object readObject(ObjectInput in, List<Object> cache, byte version) throws IOException, ClassNotFoundException { int length = in.readInt(); if (length == -1) { return new ArrayImpl(null); } int code = in.readByte(); Object[] vals = (Object[])java.lang.reflect.Array.newInstance(DataTypeManager.getClass(code), length); for (int i = 0; i < length;) { byte b = in.readByte(); int end = Math.min(length, i+8); for (; i < end; i++) { if (!isNullObject(i, b)) { vals[i] = this.ser.readObject(in, cache, code, version); } } } ArrayImpl result = new ArrayImpl(vals); result.setZeroBased(in.readBoolean()); return result; }
private void buildSearchRow(int i, Object match, Object value2, List<Object> toSearch) { if (toSearch.size() != i) { return; } if (value2 instanceof ArrayImpl && match instanceof int[]) { int[] indexes = (int[])match; ArrayImpl array = (ArrayImpl)value2; Object[] arrayVals = array.getValues(); for (int j = 0; j < indexes.length; j++) { int index = indexes[j]; if (index == -1) { break; } toSearch.add(arrayVals[index]); } } else { toSearch.add(value2); } }
@Test public void testZeroBasedArray() throws Exception { ArrayImpl a1 = new ArrayImpl((Object[])new Integer[] {1, 2, 3}); a1.setZeroBased(true); assertEquals(2, java.lang.reflect.Array.get(a1.getArray(1, 1), 0)); }
public static Object asPGVector(Object obj) { if (obj instanceof ArrayImpl) { ((ArrayImpl)obj).setZeroBased(true); } return obj; }
@Override public Object getArray() throws SQLException { checkValues(); return values; }
private void buildSearchRow(int i, Object match, Object value2, List<Object> toSearch) { if (toSearch.size() != i) { return; } if (value2 instanceof ArrayImpl && match instanceof int[]) { int[] indexes = (int[])match; ArrayImpl array = (ArrayImpl)value2; Object[] arrayVals = array.getValues(); for (int j = 0; j < indexes.length; j++) { int index = indexes[j]; if (index == -1) { break; } toSearch.add(arrayVals[index]); } } else { toSearch.add(value2); } }
@Override protected Object readObject(ObjectInput in, List<Object> cache, byte version) throws IOException, ClassNotFoundException { int length = in.readInt(); if (length == -1) { return new ArrayImpl(null); } int code = in.readByte(); Object[] vals = (Object[])java.lang.reflect.Array.newInstance(DataTypeManager.getClass(code), length); for (int i = 0; i < length;) { byte b = in.readByte(); int end = Math.min(length, i+8); for (; i < end; i++) { if (!isNullObject(i, b)) { vals[i] = this.ser.readObject(in, cache, code, version); } } } ArrayImpl result = new ArrayImpl(vals); result.setZeroBased(in.readBoolean()); return result; }
@Override public Object getArray() throws SQLException { checkValues(); return values; }
public int compareTo(ArrayImpl o, boolean noNulls, Comparator<Object> comparator) { if (zeroBased != o.zeroBased) { throw new TeiidRuntimeException("Incompatible types"); //$NON-NLS-1$ } try { checkValues(); o.checkValues(); } catch (SQLException e) { throw new TeiidRuntimeException(e); } Object[] values2 = o.values; return compare(noNulls, comparator, values, values2); }
@Override public Object getResult(CommandContext commandContext) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { return new ArrayImpl(vals); }
@Override public Object getResult(CommandContext commandContext) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException,TeiidProcessingException { if (this.result == null) { return null; } if (this.componentType == DataTypeManager.DefaultDataClasses.OBJECT) { return new ArrayImpl(this.result.toArray()); } Object array = Array.newInstance(componentType, this.result.size()); for (int i = 0; i < result.size(); i++) { Object val = result.get(i); if (val instanceof ArrayImpl) { val = ((ArrayImpl)val).getValues(); } Array.set(array, i, val); } return new ArrayImpl((Object[]) array); }
private void buildSearchRow(int i, Object match, Object value2, List<Object> toSearch) { if (toSearch.size() != i) { return; } if (value2 instanceof ArrayImpl && match instanceof int[]) { int[] indexes = (int[])match; ArrayImpl array = (ArrayImpl)value2; Object[] arrayVals = array.getValues(); for (int j = 0; j < indexes.length; j++) { int index = indexes[j]; if (index == -1) { break; } toSearch.add(arrayVals[index]); } } else { toSearch.add(value2); } }
@Override public int compareTo(ArrayImpl o) { return compareTo(o, false, null); }
@Override public Object getArray(long index, int count) throws SQLException { if (index > Integer.MAX_VALUE) { throw new ArrayIndexOutOfBoundsException(String.valueOf(index)); } int offset = zeroBased?0:1; int iIndex = (int)index - offset; if (iIndex >= values.length || iIndex < 0) { throw new ArrayIndexOutOfBoundsException(iIndex); } checkValues(); return Arrays.copyOfRange(values, iIndex, Math.min(iIndex + count, values.length)); }