private void BuildFields(StringBuilder sb, DocEntity docEntity, Dictionary<string, DocObject> map)
{
#if true //... make configurable... -- for now all classes are mapped as separate tables, where lookup must join each
// super
DocObject docSuper = null;
if(docEntity.BaseDefinition != null && map.TryGetValue(docEntity.BaseDefinition, out docSuper) && docSuper is DocEntity)
{
BuildFields(sb, (DocEntity)docSuper, map);
}
#endif
foreach (DocAttribute docAttr in docEntity.Attributes)
{
if (docAttr.GetAggregation() == DocAggregationEnum.NONE && docAttr.Inverse == null) // don't deal with lists -- separate tables
{
sb.Append(", ");
sb.AppendLine();
sb.Append("\t");
sb.Append(docAttr.Name);
sb.Append(" ");
DocObject docRef = null;
if (docAttr.DefinedType == null || !map.TryGetValue(docAttr.DefinedType, out docRef) || docRef is DocDefined)
{
string deftype = docAttr.DefinedType;
if(docRef is DocDefined)
{
DocDefined docDef = (DocDefined)docRef;
deftype = docDef.DefinedType;
}
switch (deftype)
{
case "BOOLEAN":
sb.Append(" BIT");
break;
case "INTEGER":
sb.Append(" INTEGER");
break;
case "REAL":
sb.Append(" FLOAT");
break;
case "BINARY":
sb.Append(" TEXT");
break;
case "STRING":
default:
sb.Append(" TEXT");
break;
}
}
else if (docRef is DocEntity) //... docselect...
{
// if non-rooted, then embed as XML...
sb.Append(" INTEGER"); // oid
}
else if (docRef is DocSelect)
{
sb.Append(" INTEGER"); // oid... and type...
}
else if (docRef is DocEnumeration)
{
sb.Append(" VARCHAR");
}
}
}
}