(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Data.ObjectSpaces / System.Data.ObjectSpaces / ObjectSpace.cs
blob45f8d471c1d31294248bc69485942bcf68daddf8
1 //
2 // System.Data.ObjectSpaces.ObjectSpace.cs : Handles high-level object persistence interactions with a data source.
3 //
4 // Authors:
5 // Mark Easton (mark.easton@blinksoftware.co.uk)
6 // Tim Coleman (tim@timcoleman.com)
7 //
8 // (C) BLiNK Software Ltd. http://www.blinksoftware.co.uk
9 // Copyright (C) Tim Coleman, 2003
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #if NET_2_0
35 using System.Collections;
36 using System.Data;
37 using System.Data.Mapping;
38 using System.Data.ObjectSpaces.Query;
39 using System.Data.ObjectSpaces.Schema;
41 namespace System.Data.ObjectSpaces
43 public class ObjectSpace
45 #region Fields
47 MappingSchema map;
48 ObjectSources sources;
49 ObjectSchema os;
50 CommonObjectContext context;
52 #endregion // Fields
54 #region Constructors
56 private ObjectSpace ()
57 : base ()
59 os = new ObjectSchema ();
60 context = new CommonObjectContext (os);
63 [MonoTODO]
64 public ObjectSpace (MappingSchema map, ObjectSources sources)
65 : this ()
67 this.map = map;
68 this.sources = sources;
71 [MonoTODO ("Figure out correct name")]
72 public ObjectSpace (string mapFile, IDbConnection con)
73 : this ()
75 map = new MappingSchema (mapFile);
76 sources = new ObjectSources ();
77 sources.Add (map.DataSources [0].Name, con);
80 public ObjectSpace (string mapFile, ObjectSources sources)
81 : this ()
83 map = new MappingSchema (mapFile);
84 this.sources = sources;
87 [MonoTODO ("Figure out correct name")]
88 public ObjectSpace (MappingSchema map, IDbConnection con)
89 : this ()
91 this.map = map;
92 sources = new ObjectSources ();
93 sources.Add (map.DataSources [0].Name, con);
96 #endregion // Constructors
98 #region Properties
100 internal ObjectContext ObjectContext {
101 get { return context; }
104 #endregion // Properties
106 #region Methods
108 public object GetObject (ObjectQuery query, object[] parameters)
110 return GetObject (GetObjectReader (query, parameters));
113 public object GetObject (Type type, string queryString)
115 return GetObject (GetObjectReader (type, queryString));
118 public object GetObject (Type type, string queryString, string relatedSpan)
120 return GetObject (GetObjectReader (type, queryString));
123 private object GetObject (ObjectReader reader)
125 reader.Read ();
126 object result = reader.Current;
127 reader.Close ();
128 return result;
131 public ObjectReader GetObjectReader (ObjectQuery query, object[] parameters)
133 ObjectExpression oe = OPath.Parse (query, os);
134 CompiledQuery cq = oe.Compile (map);
135 return ObjectEngine.GetObjectReader (sources, context, cq, parameters);
138 public ObjectReader GetObjectReader (Type type, string queryString)
140 return GetObjectReader (new ObjectQuery (type, queryString), null);
143 public ObjectReader GetObjectReader (Type type, string queryString, string relatedSpan)
145 return GetObjectReader (new ObjectQuery (type, queryString, relatedSpan), null);
148 public ObjectSet GetObjectSet (ObjectQuery query, object[] parameters)
150 return GetObjectSet (GetObjectReader (query, parameters));
153 public ObjectSet GetObjectSet (Type type, string queryString)
155 return GetObjectSet (GetObjectReader (type, queryString));
158 public ObjectSet GetObjectSet (Type type, string queryString, string relatedSpan)
160 return GetObjectSet (GetObjectReader (type, queryString, relatedSpan));
163 private ObjectSet GetObjectSet (ObjectReader reader)
165 ObjectSet result = new ObjectSet ();
166 foreach (object o in reader)
167 result.Add (o);
168 reader.Close ();
169 return result;
172 public void MarkForDeletion (object obj)
174 MarkForDeletion (new object[] {obj});
177 [MonoTODO]
178 public void MarkForDeletion (ICollection objs) {}
180 public void PersistChanges (object obj)
182 PersistChanges (new object[] {obj}, new PersistenceOptions ());
185 public void PersistChanges (object obj, PersistenceOptions options)
187 PersistChanges (new object[] {obj}, options);
190 public void PersistChanges (ICollection objs)
192 PersistChanges (objs, new PersistenceOptions ());
195 public void PersistChanges (ICollection objs, PersistenceOptions options)
197 ObjectEngine.PersistChanges (map, sources, context, objs, options);
200 public void Resync (object obj, Depth depth)
202 Resync (new object[] {obj}, depth);
205 public void Resync (ICollection objs, Depth depth)
207 ObjectEngine.Resync (map, sources, context, objs, depth);
210 public void StartTracking (object obj, InitialState state)
212 StartTracking (new object[] {obj}, state);
215 [MonoTODO]
216 public void StartTracking (ICollection objs, InitialState state)
220 #endregion // Methods
224 #endif