@@ -12,6 +12,9 @@ import GHC.Generics (Generic)
1212import qualified Data.Vector as V
1313import qualified Data.List as L
1414import qualified Data.Text as T
15+import Data.Binary
16+import Data.Vector.Binary()
17+import ProjectM36.HashSetBinary()
1518
1619type StringType = T.Text
1720
@@ -23,7 +26,9 @@ data Atom = StringAtom StringType |
2326
2427instance NFData Atom where rnf = genericRnf
2528
26−instance Hash.Hashable Atom
29+instance Hash.Hashable Atom
30+
31+instance Binary Atom
2732
2833data AtomType = StringAtomType |
2934 IntAtomType |
@@ -33,6 +38,7 @@ data AtomType = StringAtomType |
3338 deriving (Eq, Show, Generic)
3439
3540instance NFData AtomType where rnf = genericRnf
41+instance Binary AtomType
3642
3743type AttributeName = T.Text
3844
@@ -42,6 +48,8 @@ instance Hash.Hashable Attribute where
4248 hashWithSalt salt (Attribute attrName _) = Hash.hashWithSalt salt attrName
4349
4450instance NFData Attribute where rnf = genericRnf
51+
52+instance Binary Attribute
4553
4654type Attributes = V.Vector Attribute
4755
@@ -68,6 +76,8 @@ instance Hash.Hashable RelationTuple where
6876--maybe the attribute->int mapping should be stored once in the relation and then passed down when needed
6977data RelationTuple = RelationTuple Attributes (V.Vector Atom) deriving (Show, Generic)
7078
79+instance Binary RelationTuple
80+
7181instance Eq RelationTuple where
7282 (==) tuple1@(RelationTuple attrs1 _) tuple2@(RelationTuple attrs2 _) = attributesEqual attrs1 attrs2 && atomsEqual
7383 where
@@ -91,6 +101,8 @@ instance Hash.Hashable Relation where
91101 HS.toList tupSet
92102 where
93103 sortedAttrs = map snd (sortedAttributesIndices attrs)
104+
105+instance Binary Relation
94106
95107data RelationCardinality = Uncountable | Countable Int deriving (Eq, Show, Generic)
96108data RelationSizeInfinite = RelationSizeInfinite
@@ -115,17 +127,23 @@ data RelationalExpr where
115127 NotEquals :: RelationalExpr -> RelationalExpr -> RelationalExpr
116128 Extend :: TupleExpr -> RelationalExpr -> RelationalExpr
117129 --Summarize :: AtomExpr -> AttributeName -> RelationalExpr -> RelationalExpr -> RelationalExpr -- a special case of Extend
118− deriving (Show,Eq)
130+ deriving (Show,Eq, Generic)
131+
132+instance Binary RelationalExpr
119133
120134data DatabaseContext = DatabaseContext {
121135 inclusionDependencies :: M.Map IncDepName InclusionDependency,
122136 relationVariables :: M.Map RelVarName Relation,
123137 atomFunctions :: AtomFunctions
124− } deriving (Show)
138+ } deriving (Show, Generic)
139+
140+--instance Binary DatabaseContext
125141
126142type IncDepName = StringType
127143
128−data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq)
144+data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq, Generic)
145+
146+instance Binary InclusionDependency
129147
130148--Database context expressions modify the database context while relational expressions do not
131149data DatabaseExpr where
@@ -150,7 +168,9 @@ data RestrictionPredicateExpr where
150168 RelationalExprPredicate :: RelationalExpr -> RestrictionPredicateExpr --type must be same as true and false relations (no attributes)
151169 AtomExprPredicate :: AtomExpr -> RestrictionPredicateExpr --atom must evaluate to boolean
152170 AttributeEqualityPredicate :: AttributeName -> AtomExpr -> RestrictionPredicateExpr -- relationalexpr must result in relation with single tuple
153− deriving (Show, Eq)
171+ deriving (Show, Eq, Generic)
172+
173+instance Binary RestrictionPredicateExpr
154174
155175-- child + parent links
156176-- the string represents the branch name and can be used to find the named HEADs
@@ -169,10 +189,14 @@ transactionHeadsForGraph (TransactionGraph heads _) = heads
169189
170190data TransactionInfo = TransactionInfo UUID (S.Set UUID) | -- 1 parent + n children
171191 MergeTransactionInfo UUID UUID (S.Set UUID) -- 2 parents, n children
172− deriving(Show)
192+ deriving(Show, Generic)
193+
194+instance Binary TransactionInfo
173195
174196data Transaction = Transaction UUID TransactionInfo DatabaseContext -- self uuid
175− deriving (Show)
197+ deriving (Show, Generic)
198+
199+--instance Binary Transaction
176200
177201--represents an "in-progress" transaction which has not yet been added to the transaction graph
178202--one the transaction is "complete", it is committed and no longer can be changed
@@ -184,6 +208,9 @@ transactionUUID (Transaction uuid _ _) = uuid
184208
185209transactionContext :: Transaction -> DatabaseContext
186210transactionContext (Transaction _ _ context) = context
211+
212+transactionInfo :: Transaction -> TransactionInfo
213+transactionInfo (Transaction _ info _) = info
187214
188215instance Eq Transaction where
189216 (Transaction uuidA _ _) == (Transaction uuidB _ _) = uuidA == uuidB
@@ -196,11 +223,15 @@ data AtomExpr = AttributeAtomExpr AttributeName |
196223 NakedAtomExpr Atom |
197224 FunctionAtomExpr AtomFunctionName [AtomExpr] |
198225 RelationAtomExpr RelationalExpr
199− deriving (Eq,Show)
226+ deriving (Eq,Show,Generic)
227+
228+instance Binary AtomExpr
200229
201230--used to extend a relation
202231data TupleExpr = AttributeTupleExpr AttributeName AtomExpr
203− deriving (Show, Eq)
232+ deriving (Show, Eq, Generic)
233+
234+instance Binary TupleExpr
204235
205236--enumerates the list of functions available to be run as part of tuple expressions
206237type AtomFunctions = HS.HashSet AtomFunction
@@ -223,7 +254,15 @@ instance Show AtomFunction where
223254 show aFunc = T.unpack (atomFuncName aFunc) ++ "::" ++ showArgTypes
224255 where
225256 showArgTypes = concat (L.intersperse "->" $ map show (atomFuncType aFunc))
226−
257+
227258data AttributeNames = AttributeNames (S.Set AttributeName) |
228259 InvertedAttributeNames (S.Set AttributeName)
229− deriving (Eq, Show)
260+ deriving (Eq, Show, Generic)
261+
262+instance Binary AttributeNames
263+
264+--used for global dbms configuration- per-transaction flag is elsewhere
265+data PersistenceStrategy = NoPersistence | --no filesystem persistence/memory-only database
266+ MinimalPersistence FilePath --fsync off
267+ --CrashSafePersistence FilePath --full fsync- not yet implemented
268+ deriving (Show, Read)