Inheritance: SqlType, IDbObject
Example #1
0
        public UserType GetUserType(ObjectName typeName)
        {
            UserType userType;
            if (!typesCache.TryGetValue(typeName, out userType)) {
                var typeTable = Transaction.GetTable(TypeTableName);
                var membersTable = Transaction.GetTable(TypeMemberTableName);

                var schemaName = typeName.ParentName;
                var name = typeName.Name;

                var schemaColumn = typeTable.GetResolvedColumnName(1);
                var nameColumn = typeTable.GetResolvedColumnName(2);

                var idColumn = membersTable.GetResolvedColumnName(0);

                UserTypeInfo typeInfo;

                using (var session = new SystemSession(Transaction)) {
                    using (var query = session.CreateQuery()) {
                        var t = typeTable.SimpleSelect(query, schemaColumn, SqlExpressionType.Equal, SqlExpression.Constant(schemaName));

                        t = t.ExhaustiveSelect(query,
                            SqlExpression.Equal(SqlExpression.Reference(nameColumn), SqlExpression.Constant(name)));

                        if (t.RowCount == 0)
                            return null;

                        var id = t.GetValue(0, 0);

                        var parentField = t.GetValue(0, 3);
                        ObjectName parentType = null;
                        if (!Field.IsNullField(parentField)) {
                            parentType = ObjectName.Parse(parentField.Value.ToString());
                        }

                        typeInfo = new UserTypeInfo(typeName, parentType);

                        var isSealedField = t.GetValue(0, 4);
                        var isAbstractField = t.GetValue(0, 5);

                        if (!Field.IsNullField(isSealedField)) {
                            typeInfo.IsSealed = (SqlBoolean) isSealedField.AsBoolean().Value;
                        }

                        if (!Field.IsNullField(isAbstractField)) {
                            typeInfo.IsAbstract = (SqlBoolean) isAbstractField.AsBoolean().Value;
                        }

                        var owner = t.GetValue(0, 6).Value.ToString();

                        typeInfo.Owner = owner;

                        var t2 = membersTable.SimpleSelect(query, idColumn, SqlExpressionType.Equal, SqlExpression.Constant(id));

                        foreach (var row in t2) {
                            var memberName = row.GetValue(1).Value.ToString();
                            var memberTypeString = row.GetValue(2).Value.ToString();

                            var memberType = SqlType.Parse(Transaction.Context, memberTypeString);

                            if (memberType == null)
                                throw new InvalidOperationException(String.Format("Cannot find the type '{0}' for member '{1}' of type '{2}'.",
                                    memberTypeString, memberName, typeName));

                            typeInfo.AddMember(memberName, memberType);
                        }
                    }
                }

                userType = new UserType(typeInfo);

                typesCache[typeName] = userType;
            }

            return userType;
        }
Example #2
0
 public InitFunction(UserType type, IDictionary<string, SqlType> members)
 {
     FunctionInfo = CreateFunctionInfo(type.FullName, members);
     Type = type;
 }
Example #3
0
 public static void TestSetUp()
 {
     var typeInfo = new UserTypeInfo(ObjectName.Parse("APP.test_type"));
     typeInfo.AddMember("a", PrimitiveTypes.Integer());
     Type = new UserType(typeInfo);
 }