⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlimporter.cs

📁 Perst开源实时数据库
💻 CS
📖 第 1 页 / 共 5 页
字号:
                        dst = buf.packBool(dst, Int32.Parse(val) != 0);
                        break;

                    case ClassDescriptor.FieldType.tpByte:
                    case ClassDescriptor.FieldType.tpSByte:
                        dst = buf.packI1(dst, Int32.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpChar:
                    case ClassDescriptor.FieldType.tpShort:
                    case ClassDescriptor.FieldType.tpUShort:
                        dst = buf.packI2(dst, Int32.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpInt:
                        dst = buf.packI4(dst, Int32.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpEnum:
                    case ClassDescriptor.FieldType.tpUInt:
                        dst = buf.packI4(dst, (int)UInt32.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpObject:
                    case ClassDescriptor.FieldType.tpOid:
                        dst = buf.packI4(dst, mapId((int)UInt32.Parse(val)));
                        break;

                    case ClassDescriptor.FieldType.tpLong:
                        dst = buf.packI8(dst, Int64.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpULong:
                        dst = buf.packI8(dst, (long)UInt64.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpDate:
                        dst = buf.packDate(dst, DateTime.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpFloat:
                        dst = buf.packF4(dst, Single.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpDouble:
                        dst = buf.packF8(dst, Double.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpDecimal: 
                        dst = buf.packDecimal(dst, Decimal.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpGuid: 
                        dst = buf.packGuid(dst, new Guid(val));
                        break;

                    case ClassDescriptor.FieldType.tpString:
                        dst = buf.packString(dst, val);
                        break;

                    case ClassDescriptor.FieldType.tpArrayOfByte:
                        buf.extend(dst + 4 + (val.Length >> 1));
                        Bytes.pack4(buf.arr, dst, val.Length >> 1);
                        dst += 4;
                        for (int j = 0, n = val.Length; j < n; j+=2) 
                        { 
                            buf.arr[dst++] = (byte)((getHexValue(val[j]) << 4) | getHexValue(val[j+1]));
                        }
                        break;
                    default:
                        throwException("Bad key type");
                        break;
                }
            }
            return new Key(buf.toArray());
        }

        Key createKey(ClassDescriptor.FieldType type, String val)
        {
            switch (type)
            {
                case ClassDescriptor.FieldType.tpBoolean: 
                    return new Key(Int32.Parse(val) != 0);
					
                case ClassDescriptor.FieldType.tpByte: 
                    return new Key(Byte.Parse(val));
					
                case ClassDescriptor.FieldType.tpSByte: 
                    return new Key(SByte.Parse(val));
					
                case ClassDescriptor.FieldType.tpChar: 
                    return new Key((char)Int32.Parse(val));
					
                case ClassDescriptor.FieldType.tpShort: 
                    return new Key(Int16.Parse(val));
					
                case ClassDescriptor.FieldType.tpUShort: 
                    return new Key(UInt16.Parse(val));
					
                case ClassDescriptor.FieldType.tpInt: 
                    return new Key(Int32.Parse(val));
					
                case ClassDescriptor.FieldType.tpUInt: 
                case ClassDescriptor.FieldType.tpEnum:
                    return new Key(UInt32.Parse(val));
					
                case ClassDescriptor.FieldType.tpOid: 
                    return new Key(ClassDescriptor.FieldType.tpOid, mapId((int)UInt32.Parse(val)));
                case ClassDescriptor.FieldType.tpObject: 
                    return new Key(new PersistentStub(storage, mapId((int)UInt32.Parse(val))));
					
                case ClassDescriptor.FieldType.tpLong: 
                    return new Key(Int64.Parse(val));
					
                case ClassDescriptor.FieldType.tpULong: 
                    return new Key(UInt64.Parse(val));
					
                case ClassDescriptor.FieldType.tpFloat: 
                    return new Key(Single.Parse(val));
					
                case ClassDescriptor.FieldType.tpDouble: 
                    return new Key(Double.Parse(val));
					
                case ClassDescriptor.FieldType.tpDecimal: 
                    return new Key(Decimal.Parse(val));

                case ClassDescriptor.FieldType.tpGuid: 
                    return new Key(new Guid(val));

                case ClassDescriptor.FieldType.tpString: 
                    return new Key(val);
					
                case ClassDescriptor.FieldType.tpArrayOfByte:
                {
                    byte[] buf = new byte[val.Length >> 1];
                    for (int i = 0; i < buf.Length; i++) 
                    { 
                        buf[i] = (byte)((getHexValue(val[i*2]) << 4) | getHexValue(val[i*2+1]));
                    }
                    return new Key(buf);
                }

                case ClassDescriptor.FieldType.tpDate: 
                    return new Key(DateTime.Parse(val));
					
                default: 
                    throwException("Bad key type");
                    break;
					
            }
            return null;
        }
		
        internal int parseInt(String str)
        {
            return Int32.Parse(str);
        }
		
        internal Type findClassByName(String className) 
        {
            Type type = (Type)classMap[className];
            if (type == null) 
            {
                type = ClassDescriptor.lookup(storage, className);
                classMap[className] = type;
            }
            return type;
        }

        internal void  createIndex(String indexType)
        {
            XMLScanner.Token tkn;
            int oid = 0;
            bool     unique = false;
            String   className = null;
            String   fieldName = null;
            String[] fieldNames = null;
            long     autoinc = 0;
            String   type = null;
            ClassDescriptor.FieldType[] types = null;

            while ((tkn = scanner.scan()) == XMLScanner.Token.IDENT)
            {
                System.String attrName = scanner.Identifier;
                if (scanner.scan() != XMLScanner.Token.EQ || scanner.scan() != XMLScanner.Token.SCONST)
                {
                    throwException("Attribute value expected");
                }
                System.String attrValue = scanner.String;
                if (attrName.Equals("id"))
                {
                    oid = mapId(parseInt(attrValue));
                }
                else if (attrName.Equals("unique"))
                {
                    unique = parseInt(attrValue) != 0;
                }
                else if (attrName.Equals("class"))
                {
                    className = attrValue;
                }
                else if (attrName.Equals("type"))
                {
                    type = attrValue;
                }
                else if (attrName.Equals("autoinc"))
                {
                    autoinc = parseInt(attrValue);
                }
                else if (attrName.Equals("field"))
                {
                    fieldName = attrValue;
                }
                else if (attrName.StartsWith("field"))
                {
                    int fieldNo = Int32.Parse(attrName.Substring(5));
                    if (fieldNames == null || fieldNames.Length <= fieldNo) 
                    { 
                        String[] newFieldNames = new String[fieldNo+1];
                        if (fieldNames != null) 
                        { 
                            Array.Copy(fieldNames, 0, newFieldNames, 0, fieldNames.Length);
                        }
                        fieldNames = newFieldNames;
                     }
                     fieldNames[fieldNo] = attrValue;
                }
                else if (attrName.StartsWith("type"))
                {
                    int typeNo = Int32.Parse(attrName.Substring(4));
                    if (types == null || types.Length <= typeNo) 
                    { 
                        ClassDescriptor.FieldType[] newTypes = new ClassDescriptor.FieldType[typeNo+1];
                        if (types != null) 
                        { 
                            Array.Copy(types, 0, newTypes, 0, types.Length);
                        }
                        types = newTypes;
                     }
                     types[typeNo] = mapType(attrValue);
                }
            }
            if (tkn != XMLScanner.Token.GT)
            {
                throwException("Unclosed element tag");
            }
            if (oid == 0)
            {
                throwException("ID is not specified or index");
            }
#if USE_GENERICS
            ClassDescriptor desc = storage.getClassDescriptor(findClassByName(indexType));
            Btree btree = (Btree)desc.newInstance();
#else
            Btree btree = null;
#endif            
            if (className != null)
            {
                Type cls = findClassByName(className);
                if (fieldName != null) 
                { 
#if USE_GENERICS
                    btree.init(cls, null, new string[]{fieldName}, unique, autoinc);
#else
                    btree = new BtreeFieldIndex(cls, fieldName, unique, autoinc);
#endif
                } 
                else if (fieldNames != null) 
                { 
#if USE_GENERICS
                    btree.init(cls, null, fieldNames, unique, autoinc);
#else
                    btree = new BtreeMultiFieldIndex(cls, fieldNames, unique);
#endif
                } 
                else
                {
                    throwException("Field name is not specified for field index");
                }
            }
            else
            {
                if (types != null) 
                { 
#if USE_GENERICS
                    btree.init(null, types, null, unique, autoinc);
#else
                    btree = new BtreeCompoundIndex(types, unique);
#endif
                } 
                else if (type == null)
                {
                    if (indexType.StartsWith("Perst.Impl.PersistentSet")) 
                    { 
#if !USE_GENERICS
                        btree = new PersistentSet();
#endif
                    } 
                    else 
                    {
                        throwException("Key type is not specified for index");
                    }
                } 
                else 
                {
                    if (indexType.StartsWith("org.garret.perst.impl.BitIndexImpl")) 
                    { 
#if !USE_GENERICS
                        btree = new BitIndexImpl();
#endif
                    } 
                    else 
                    { 
#if USE_GENERICS
                        btree.init(null, new ClassDescriptor.FieldType[]{mapType(type)}, null, unique, autoinc);
#else
                        btree = new Btree(mapType(type), unique);
#endif
                    }
                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -