Ejemplo n.º 1
4
        /// <summary>Returns the host representation of the given native value.  This is a by-reference operation.</summary>
        public static IDataValue FromNative(IValueManager manager, Schema.IDataType dataType, object tempValue)
        {
            // This code is duplicated in the Copy method and the FromNative overloads for performance
            Schema.IScalarType scalarType = dataType as Schema.IScalarType;
            if (scalarType != null)
            {
                if (tempValue is StreamID)
                {
                    return(new Scalar(manager, scalarType, (StreamID)tempValue));
                }
                if (scalarType.IsGeneric)
                {
                    return(new Scalar(manager, (Schema.ScalarType)manager.GetRuntimeType(tempValue.GetType()), tempValue));
                }
                return(new Scalar(manager, scalarType, tempValue));
            }

            if (tempValue == null)
            {
                return(null);
            }

            Schema.IRowType rowType = dataType as Schema.IRowType;
            if (rowType != null)
            {
                return(new Row(manager, rowType, (NativeRow)tempValue));
            }

            Schema.IListType listType = dataType as Schema.IListType;
            if (listType != null)
            {
                return(new ListValue(manager, listType, (NativeList)tempValue));
            }

            Schema.ITableType tableType = dataType as Schema.ITableType;
            if (tableType != null)
            {
                return(new TableValue(manager, tableType, (NativeTable)tempValue));
            }

            Schema.ICursorType cursorType = dataType as Schema.ICursorType;
            if (cursorType != null)
            {
                return(new CursorValue(manager, cursorType, (int)tempValue));
            }

            var runtimeType = manager.GetRuntimeType(tempValue);

            if (runtimeType != null)
            {
                return(FromNative(manager, runtimeType, tempValue));
            }

            throw new RuntimeException(RuntimeException.Codes.InvalidValueType, dataType == null ? "<null>" : dataType.GetType().Name);
        }
Ejemplo n.º 2
0
        /// <summary>Disposes the given native value.</summary>
        public static void DisposeNative(IValueManager manager, Schema.IDataType dataType, object tempValue)
        {
            if (tempValue == null)
            {
                return;
            }

            Schema.IScalarType scalarType = dataType as Schema.IScalarType;
            if (scalarType != null)
            {
                if (tempValue is StreamID)
                {
                    manager.StreamManager.Deallocate((StreamID)tempValue);
                }

                if (scalarType.IsCompound)
                {
                    DisposeNative(manager, scalarType.CompoundRowType, tempValue);
                }

                return;
            }

            using (IDataValue dataValue = DataValue.FromNative(manager, dataType, tempValue))
            {
                dataValue.ValuesOwned = true;
            }
        }
Ejemplo n.º 3
0
        public IConveyor GetConveyor(Schema.IScalarType scalarType)
        {
            IConveyor conveyor;

            if (!_conveyors.TryGetValue(scalarType.Name, out conveyor))
            {
                conveyor = (IConveyor)_serverProcessInterface.CreateObject(scalarType.ClassDefinition, null);
                _conveyors.Add(scalarType.Name, conveyor);
            }
            return(conveyor);
        }
Ejemplo n.º 4
0
        /// <summary>Returns the host representation of the given native value.  This is a by-reference operation.</summary>
        public static IDataValue FromNativeRow(IValueManager manager, Schema.IRowType rowType, NativeRow nativeRow, int nativeRowIndex)
        {
            // This code is duplicated in the Copy method and the FromNative overloads for performance
                        #if USEDATATYPESINNATIVEROW
            Schema.IDataType dataType = nativeRow.DataTypes[nativeRowIndex];
            if (dataType == null)
            {
                dataType = rowType.Columns[nativeRowIndex].DataType;
            }
                        #else
            Schema.IDataType dataType = ARowType.Columns[ANativeRowIndex].DataType;
                        #endif

            Schema.IScalarType scalarType = dataType as Schema.IScalarType;
            if (scalarType != null)
            {
                return(new RowInternedScalar(manager, scalarType, nativeRow, nativeRowIndex));
            }

            Schema.IRowType localRowType = dataType as Schema.IRowType;
            if (localRowType != null)
            {
                return(new Row(manager, localRowType, (NativeRow)nativeRow.Values[nativeRowIndex]));
            }

            Schema.IListType listType = dataType as Schema.IListType;
            if (listType != null)
            {
                return(new ListValue(manager, listType, (NativeList)nativeRow.Values[nativeRowIndex]));
            }

            Schema.ITableType tableType = dataType as Schema.ITableType;
            if (tableType != null)
            {
                return(new TableValue(manager, tableType, (NativeTable)nativeRow.Values[nativeRowIndex]));
            }

            Schema.ICursorType cursorType = dataType as Schema.ICursorType;
            if (cursorType != null)
            {
                return(new CursorValue(manager, cursorType, (int)nativeRow.Values[nativeRowIndex]));
            }

            var runtimeType = manager.GetRuntimeType(nativeRow.Values[nativeRowIndex]);
            if (runtimeType != null)
            {
                return(new RowInternedScalar(manager, (Schema.IScalarType)runtimeType, nativeRow, nativeRowIndex));
            }

            throw new RuntimeException(RuntimeException.Codes.InvalidValueType, dataType == null ? "<null>" : dataType.GetType().Name);
        }
Ejemplo n.º 5
0
        public IDataValue Copy()
        {
            // This code is duplicated in the FromNative and CopyAs methods for performance...
            object tempValue = CopyNative();

            Schema.IScalarType scalarType = DataType as Schema.IScalarType;

            if (scalarType != null)
            {
                if (tempValue is StreamID)
                {
                    Scalar scalar = new Scalar(Manager, scalarType, (StreamID)tempValue);
                    scalar.ValuesOwned = true;
                    return(scalar);
                }
                return(new Scalar(Manager, scalarType, tempValue));
            }

            Schema.IRowType rowType = DataType as Schema.IRowType;
            if (rowType != null)
            {
                Row row = new Row(Manager, rowType, (NativeRow)tempValue);
                row.ValuesOwned = true;
                return(row);
            }

            Schema.IListType listType = DataType as Schema.IListType;
            if (listType != null)
            {
                ListValue list = new ListValue(Manager, listType, (NativeList)tempValue);
                list.ValuesOwned = true;
                return(list);
            }

            Schema.ITableType tableType = DataType as Schema.ITableType;
            if (tableType != null)
            {
                TableValue table = new TableValue(Manager, tableType, (NativeTable)tempValue);
                table.ValuesOwned = true;
                return(table);
            }

            Schema.ICursorType cursorType = DataType as Schema.ICursorType;
            if (cursorType != null)
            {
                return(new CursorValue(Manager, cursorType, (int)tempValue));
            }

            throw new RuntimeException(RuntimeException.Codes.InvalidValueType, DataType == null ? "<null>" : DataType.GetType().Name);
        }
Ejemplo n.º 6
0
        /// <summary>Returns the host representation of the given native value.  This is a by-reference operation.</summary>
        public static IDataValue FromNativeList(IValueManager manager, Schema.IListType listType, NativeList nativeList, int nativeListIndex)
        {
            // This code is duplicated in the Copy method and the FromNative overloads for performance
            Schema.IDataType dataType = nativeList.DataTypes[nativeListIndex];
            if (dataType == null)
            {
                dataType = listType.ElementType;
            }

            Schema.IScalarType scalarType = dataType as Schema.IScalarType;
            if (scalarType != null)
            {
                return(new ListInternedScalar(manager, scalarType, nativeList, nativeListIndex));
            }

            Schema.IRowType rowType = dataType as Schema.IRowType;
            if (rowType != null)
            {
                return(new Row(manager, rowType, (NativeRow)nativeList.Values[nativeListIndex]));
            }

            Schema.IListType localListType = dataType as Schema.IListType;
            if (localListType != null)
            {
                return(new ListValue(manager, localListType, (NativeList)nativeList.Values[nativeListIndex]));
            }

            Schema.ITableType tableType = dataType as Schema.ITableType;
            if (tableType != null)
            {
                return(new TableValue(manager, tableType, (NativeTable)nativeList.Values[nativeListIndex]));
            }

            Schema.ICursorType cursorType = dataType as Schema.ICursorType;
            if (cursorType != null)
            {
                return(new CursorValue(manager, cursorType, (int)nativeList.Values[nativeListIndex]));
            }

            var runtimeType = manager.GetRuntimeType(nativeList.Values[nativeListIndex]);

            if (runtimeType != null)
            {
                return(new ListInternedScalar(manager, (Schema.IScalarType)runtimeType, nativeList, nativeListIndex));
            }

            throw new RuntimeException(RuntimeException.Codes.InvalidValueType, nativeList.DataTypes[nativeListIndex] == null ? "<null>" : nativeList.DataTypes[nativeListIndex].GetType().Name);
        }
Ejemplo n.º 7
0
        /// <summary>Returns the host representation of the given physical value.</summary>
        public static IDataValue FromPhysical(IValueManager manager, Schema.IDataType dataType, byte[] buffer, int offset)
        {
            Schema.IScalarType scalarType = dataType as Schema.IScalarType;
            if (scalarType != null)
            {
                Scalar scalar = new Scalar(manager, scalarType, null);
                scalar.ReadFromPhysical(buffer, offset);
                return(scalar);
            }

            Schema.IRowType rowType = dataType as Schema.IRowType;
            if (rowType != null)
            {
                Row row = new Row(manager, rowType);
                row.ReadFromPhysical(buffer, offset);
                return(row);
            }

            Schema.IListType listType = dataType as Schema.IListType;
            if (listType != null)
            {
                ListValue list = new ListValue(manager, listType);
                list.ReadFromPhysical(buffer, offset);
                return(list);
            }

            Schema.ITableType tableType = dataType as Schema.ITableType;
            if (tableType != null)
            {
                TableValue table = new TableValue(manager, tableType, null);
                table.ReadFromPhysical(buffer, offset);
                return(table);
            }

            Schema.ICursorType cursorType = dataType as Schema.ICursorType;
            if (cursorType != null)
            {
                CursorValue cursor = new CursorValue(manager, cursorType, -1);
                cursor.ReadFromPhysical(buffer, offset);
                return(cursor);
            }

            throw new RuntimeException(RuntimeException.Codes.InvalidValueType, dataType == null ? "<null>" : dataType.GetType().Name);
        }
Ejemplo n.º 8
0
 public Scalar(IValueManager manager, Schema.IScalarType dataType, StreamID streamID) : base(manager, dataType)
 {
     _streamID   = streamID;
     ValuesOwned = false;
 }
Ejemplo n.º 9
0
 public Scalar(IValueManager manager, Schema.IScalarType dataType) : base(manager, dataType)
 {
     _streamID   = manager.StreamManager.Allocate();
     ValuesOwned = true;
 }
Ejemplo n.º 10
0
 public Scalar(IValueManager manager, Schema.IScalarType dataType, object tempValue) : base(manager, dataType)
 {
     _value    = tempValue;
     _isNative = true;
 }
Ejemplo n.º 11
0
 public ListInternedScalar(IValueManager manager, Schema.IScalarType dataType, NativeList nativeList, int index) : base(manager, dataType)
 {
     _nativeList = nativeList;
     _index      = index;
 }
Ejemplo n.º 12
0
 public RowInternedScalar(IValueManager manager, Schema.IScalarType dataType, NativeRow nativeRow, int index) : base(manager, dataType)
 {
     _nativeRow = nativeRow;
     _index     = index;
 }
Ejemplo n.º 13
0
 public InternedScalar(IValueManager manager, Schema.IScalarType dataType) : base(manager, dataType, null)
 {
     ValuesOwned = false;
 }
Ejemplo n.º 14
0
        public static object CopyNative(IValueManager manager, Schema.IDataType dataType, object tempValue)
        {
            // This code is duplicated in the descendent CopyNative methods for performance
            if (tempValue == null)
            {
                return(tempValue);
            }

            Schema.IScalarType scalarType = dataType as Schema.IScalarType;
            if (scalarType != null)
            {
                if (tempValue is StreamID)
                {
                    return(manager.StreamManager.Reference((StreamID)tempValue));
                }

                ICloneable cloneable = tempValue as ICloneable;
                if (cloneable != null)
                {
                    return(cloneable.Clone());
                }

                if (scalarType.IsCompound)
                {
                    return(CopyNative(manager, scalarType.CompoundRowType, tempValue));
                }

                return(tempValue);
            }

            Schema.IRowType rowType = dataType as Schema.IRowType;
            if (rowType != null)
            {
                NativeRow nativeRow = (NativeRow)tempValue;
                NativeRow newRow    = new NativeRow(rowType.Columns.Count);
                for (int index = 0; index < rowType.Columns.Count; index++)
                {
                                        #if USEDATATYPESINNATIVEROW
                    newRow.DataTypes[index] = nativeRow.DataTypes[index];
                    newRow.Values[index]    = CopyNative(manager, nativeRow.DataTypes[index], nativeRow.Values[index]);
                                        #else
                    newRow.Values[index] = CopyNative(AManager, rowType.Columns[index].DataType, nativeRow.Values[index]);
                                        #endif
                }
                return(newRow);
            }

            Schema.IListType listType = dataType as Schema.IListType;
            if (listType != null)
            {
                NativeList nativeList = (NativeList)tempValue;
                NativeList newList    = new NativeList();
                for (int index = 0; index < nativeList.DataTypes.Count; index++)
                {
                    newList.DataTypes.Add(nativeList.DataTypes[index]);
                    newList.Values.Add(CopyNative(manager, nativeList.DataTypes[index], nativeList.Values[index]));
                }
                return(newList);
            }

            Schema.ITableType tableType = dataType as Schema.ITableType;
            if (tableType != null)
            {
                NativeTable nativeTable = (NativeTable)tempValue;
                NativeTable newTable    = new NativeTable(manager, nativeTable.TableVar);
                using (Scan scan = new Scan(manager, nativeTable, nativeTable.ClusteredIndex, ScanDirection.Forward, null, null))
                {
                    scan.Open();
                    while (scan.Next())
                    {
                        using (IRow row = scan.GetRow())
                        {
                            newTable.Insert(manager, row);
                        }
                    }
                }
                return(newTable);
            }

            Schema.ICursorType cursorType = dataType as Schema.ICursorType;
            if (cursorType != null)
            {
                return(tempValue);
            }

            var runtimeType = manager.GetRuntimeType(tempValue);
            if (runtimeType != null)
            {
                return(CopyNative(manager, runtimeType, tempValue));
            }

            throw new RuntimeException(RuntimeException.Codes.InvalidValueType, dataType == null ? "<null>" : dataType.GetType().Name);
        }