-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from fffej/broker-priority
Broker priority
- Loading branch information
Showing
8 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE GADTs #-} | ||
|
||
module Database.SqlServer.Definition.BrokerPriority | ||
( | ||
BrokerPriority | ||
) where | ||
|
||
import Database.SqlServer.Definition.Service (Service) | ||
import Database.SqlServer.Definition.Contract (Contract) | ||
import Database.SqlServer.Definition.Identifier hiding (unwrap) | ||
import Database.SqlServer.Definition.Entity | ||
|
||
import Test.QuickCheck | ||
import Text.PrettyPrint | ||
import Data.DeriveTH | ||
|
||
data PriorityLevel = PriorityLevel Int | ||
|
||
instance Arbitrary PriorityLevel where | ||
arbitrary = do | ||
x <- choose (1,10) | ||
return (PriorityLevel x) | ||
|
||
data BrokerPriority = BrokerPriority | ||
{ | ||
priorityName :: RegularIdentifier | ||
, contractName :: Maybe Contract | ||
, localServiceName :: Maybe Service | ||
, remoteServiceName :: Maybe RegularIdentifier | ||
, priorityLevel :: Maybe PriorityLevel | ||
} | ||
|
||
derive makeArbitrary ''BrokerPriority | ||
|
||
renderMaybeOrAny :: Maybe RegularIdentifier -> Doc | ||
renderMaybeOrAny = maybe (text "ANY") (quotes . renderRegularIdentifier) | ||
|
||
renderName' :: Entity a => Maybe a -> Doc | ||
renderName' = maybe (text "ANY") renderName | ||
|
||
renderPriorityLevel :: Maybe PriorityLevel -> Doc | ||
renderPriorityLevel = maybe (text "DEFAULT") (\(PriorityLevel z) -> int z) | ||
|
||
renderOptions :: BrokerPriority -> Doc | ||
renderOptions b = vcat $ punctuate comma | ||
[ | ||
text "CONTRACT_NAME =" <+> renderName' (contractName b) | ||
, text "LOCAL_SERVICE_NAME =" <+> renderName' (localServiceName b) | ||
, text "REMOTE_SERVICE_NAME =" <+> renderMaybeOrAny (remoteServiceName b) | ||
, text "PRIORITY_LEVEL =" <+> renderPriorityLevel (priorityLevel b) | ||
] | ||
|
||
renderPrerequisites :: Entity a => Maybe a -> Doc | ||
renderPrerequisites = maybe empty toDoc | ||
|
||
instance Entity BrokerPriority where | ||
name = priorityName | ||
toDoc b = renderPrerequisites (contractName b) $+$ | ||
renderPrerequisites (localServiceName b) $+$ | ||
text "GO" $+$ | ||
text "CREATE BROKER PRIORITY" <+> renderName b $+$ | ||
text "FOR CONVERSATION" $+$ | ||
text "SET" <+> parens (renderOptions b) <> text ";" $+$ | ||
text "GO\n" | ||
|
||
instance Show BrokerPriority where | ||
show = show . toDoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE GADTs #-} | ||
|
||
module Database.SqlServer.Definition.Service | ||
( | ||
Service | ||
) where | ||
|
||
import Database.SqlServer.Definition.Queue (Queue) | ||
import Database.SqlServer.Definition.Contract (Contract) | ||
import Database.SqlServer.Definition.Identifier hiding (unwrap) | ||
import Database.SqlServer.Definition.Entity | ||
|
||
import Test.QuickCheck | ||
import Text.PrettyPrint | ||
import Data.DeriveTH | ||
|
||
-- An entity of type service cannot be owned by | ||
-- a role, a group, or by principals mapped to | ||
-- certificates or asymmetric keys. | ||
data Service = Service | ||
{ | ||
serviceName :: RegularIdentifier | ||
, queue :: Queue | ||
, contracts :: [Contract] | ||
} | ||
|
||
-- TODO Owner | ||
|
||
derive makeArbitrary ''Service | ||
|
||
renderContracts :: [Contract] -> Doc | ||
renderContracts [] = empty | ||
renderContracts xs = parens (vcat $ punctuate comma (map renderName xs)) $+$ | ||
text "GO\n" | ||
|
||
renderPreRequisites :: Service -> Doc | ||
renderPreRequisites s = toDoc (queue s) $+$ | ||
vcat (punctuate (text "GO") (map toDoc (contracts s))) $+$ | ||
text "GO\n" | ||
|
||
instance Entity Service where | ||
name = serviceName | ||
toDoc s = renderPreRequisites s $+$ | ||
text "CREATE SERVICE" <+> renderName s $+$ | ||
text "ON QUEUE" <+> renderName (queue s) $+$ | ||
renderContracts (contracts s) $+$ | ||
text "GO\n" | ||
|
||
instance Show Service where | ||
show = show . toDoc |