|
definition: |
updateTransaction :: ControllerGenerator
updateTransaction erdname (Entity entityName attrList) _ allEntities =
stCmtFunc
("Transaction to persist modifications of a given " ++ entityName ++
" entity\nto the database.")
(transFunctionName entityName "update")
2 Private
(tupleType ([baseType (model erdname, entityName)] ++
map (\ (name,_) -> listType (ctvar name)) manyToManyEntities)
~> applyTC (dbconn "DBAction") [unitType])
[simpleRule
[tuplePattern
([CPVar (0, lowerFirst entityName)] ++
(map (\ (param, varId) -> CPVar (varId, param))
(zip (map (\ (ename,erel) -> lowerFirst erel ++ ename ++ "s")
manyToManyEntities)
[1..])))
] -- parameter list for controller
(doExpr $
(CSExpr (applyF (model erdname, "update" ++ entityName)
[cvar (lowerFirst entityName)]) :
(concatMap (\ (ename,erel) ->
[CSPat (CPVar (0, "old" ++ erel ++ ename ++ "s"))
(applyF (controllerModuleName entityName,
"get" ++ erel ++ entityName ++ ename ++ "s")
[cvar (lowerFirst entityName)]),
CSExpr (applyF (controllerModuleName entityName,
"remove" ++ erel)
[cvar ("old"++ erel ++ ename ++ "s"),
cvar (lowerFirst entityName)])])
manyToManyEntities
) ++
(map (\ (ename,erel) -> CSExpr $
applyF (controllerModuleName entityName, "add" ++ erel)
[cvar (lowerFirst erel ++ ename ++ "s"),
cvar (lowerFirst entityName)])
manyToManyEntities)
))]
where
manyToManyEntities = manyToMany allEntities (Entity entityName attrList)
|
|
demand: |
argument 2 |
|
deterministic: |
deterministic operation |
|
documentation: |
Generates the transaction to update an entity. |
|
failfree: |
<FAILING> |
|
indeterministic: |
referentially transparent operation |
|
infix: |
no fixity defined |
|
iotype: |
{(_,{Entity},_,_) |-> _}
|
|
name: |
updateTransaction |
|
precedence: |
no precedence defined |
|
result-values: |
_ |
|
signature: |
String -> Database.ERD.Entity -> [Database.ERD.Relationship] -> [Database.ERD.Entity] -> AbstractCurry.Types.CFuncDecl |
|
solution-complete: |
operation might suspend on free variables |
|
terminating: |
possibly non-terminating |
|
totally-defined: |
possibly non-reducible on same data term |