protected override void ExecuteStatement(ExecutionContext context)
{
//if (!context.User.CanCreateInSchema(TypeName.ParentName))
// throw new SecurityException(String.Format("The user '{0}' has no rights to create in schema '{1}'.",
// context.User.Name, TypeName.ParentName));
if (ParentTypeName != null) {
if (!context.DirectAccess.TypeExists(ParentTypeName))
throw new StatementException(String.Format("The type '{0}' inherits from the type '{1}' that does not exist.",
TypeName, ParentTypeName));
if (context.DirectAccess.IsTypeSealed(ParentTypeName))
throw new StatementException(String.Format("The type '{0}' is sealed and cannot be inherited by '{1}'.",
ParentTypeName, TypeName));
}
if (context.DirectAccess.TypeExists(TypeName)) {
if (!ReplaceIfExists)
throw new StatementException(String.Format("The type '{0}' already exists.", TypeName));
context.DirectAccess.DropType(TypeName);
}
var typeInfo = new UserTypeInfo(TypeName, ParentTypeName) {
IsAbstract = IsAbstract,
IsSealed = IsSealed
};
foreach (var member in Members) {
typeInfo.AddMember(member);
}
typeInfo.Owner = context.User.Name;
context.DirectAccess.CreateType(typeInfo);
context.DirectAccess.GrantOn(DbObjectType.Type, TypeName, context.User.Name, PrivilegeSets.TableAll, true);
}