definition:
|
tuple2Entity :: ViewGenerator
tuple2Entity erdname (Entity entityName attrlist) relationships allEntities =
let
manyToManyEntities = manyToMany allEntities (Entity entityName attrlist)
manyToOneEntities = manyToOne (Entity entityName attrlist) relationships
in
stCmtFunc
("Transformation from data of a WUI form to entity type "++entityName++".")
(viewModuleName entityName, "tuple2"++entityName) 2 Public
(
foldr CFuncType
(if null manyToManyEntities
then baseType (model erdname, entityName)
else tupleType ([ctvar entityName] ++
map (\ (ename,_) -> listType (ctvar ename))
manyToManyEntities)
)
([ctvar entityName] ++
[entityInterface (filter notKey attrlist)
manyToOneEntities manyToManyEntities])
)
[simpleRule
(
[ CPVar (1, lowerFirst entityName ++ "ToUpdate"),
tuplePattern
(
(map (\ ((Attribute name _ _ _), varId) ->
CPVar (varId,lowerFirst name)))
(zip (filter notKey attrlist) [1..]) ++
(map (\ (name, varId) -> CPVar(varId,lowerFirst name))
(zip manyToOneEntities [1..])) ++
(map (\ ((ename,erel), varId) ->
CPVar (varId, lowerFirst $ erel ++ ename ++ "s"))
(zip manyToManyEntities [1..]))
)
]
)
(tupleExpr $
(foldr (\ (Attribute aname domain _ _) expr ->
case domain of
KeyDom rel ->
applyF (model erdname, "set" ++ entityName ++ aname)
[expr,
applyF (model erdname, lowerFirst rel ++ "Key")
[CVar (1, lowerFirst rel)]]
_ -> applyF (model erdname, "set" ++ entityName ++ aname)
[expr, CVar (1, lowerFirst aname)] )
(CVar (0, lowerFirst $ entityName++"ToUpdate"))
attrlist )
: (map (\ (ename,erel) -> cvar (lowerFirst $ erel ++ ename ++ "s"))
manyToManyEntities))]
|