public virtual void Querydb(IEmbeddedConfiguration config, int[] count, Type class1 , Type class2) { IEmbeddedObjectContainer database = Db4oEmbedded.OpenFile(config, TempFile()); try { IList list = database.Query(class1); Assert.AreEqual(count[0], list.Count, "Unexpected result querying for " + class1. Name); if (count[0] > 0) { } // System.out.println("Querying for " + class1.getSimpleName() + " getting " + list.get(0).getClass().getSimpleName()); IList list1 = database.Query(class2); Assert.AreEqual(count[1], list1.Count, "Unexpected result querying for " + class2 .Name); if (count[1] > 0) { } } finally { // System.out.println("Querying for " + class2.getSimpleName() + " getting " + list1.get(0).getClass().getSimpleName()); database.Close(); } }
private static void AliasesExample() { StoreTypes(); IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration(); // #example: Adding aliases // add an alias for a specific type configuration.Common.AddAlias( new TypeAlias("Db4oDoc.Code.Configuration.Alias.OldTypeInDatabase, Db4oDoc", "Db4oDoc.Code.Configuration.Alias.NewType, Db4oDoc")); // or add an alias for a whole namespace configuration.Common.AddAlias( new WildcardAlias("Db4oDoc.Code.Configuration.Alias.Old.Namespace.*, Db4oDoc", "Db4oDoc.Code.Configuration.Alias.Current.Namespace.*, Db4oDoc")); // #end example using (IEmbeddedObjectContainer container = Db4oEmbedded.OpenFile(configuration, DatabaseFileName)) { int countRenamed = container.Query <NewType>().Count; AssertFoundEntries(countRenamed); int countInOtherPackage = container .Query <Current.Namespace.Car>().Count; AssertFoundEntries(countInOtherPackage); } }
public ImageInfo[] Read() { ImageInfo[] result; var res = db.Query <ImageInfo> (typeof(ImageInfo)); result = res.ToArray(); return(result); }
public virtual void TestQuery() { CreateData(); IEmbeddedObjectContainer database = Db4oEmbedded.OpenFile(AliasConfig(), TempFile ()); database.Query(typeof(AliasesQueryingTestCase.B)); database.Query(typeof(AliasesQueryingTestCase.A)); database.Close(); Querydb(Db4oEmbedded.NewConfiguration(), new int[] { 1, 0 }, typeof(AliasesQueryingTestCase.A ), typeof(AliasesQueryingTestCase.B)); }
public IEnumerable <DtoLicensePlateInfo> GetLicensePlatesBetween(int cameraId, DateTimeRange dateTimeRange) { return(_db4oContainer.Query <DtoLicensePlateInfo>(l => { var match = l.CaptureTime >= dateTimeRange.From && l.CaptureTime <= dateTimeRange.To; if (cameraId != -1) { match = match && l.CapturedFrom == cameraId; } ; return match; })); }
/// <exception cref="System.Exception"></exception> public virtual void Test() { Db4oLibraryEnvironment originalEnv = EnvironmentForVersion("6.0"); originalEnv.InvokeInstanceMethod(typeof(MigrationHopsTestCase.Tester), "createDatabase" , new object[] { TempFile() }); string[] hopArray = new string[] { "6.4", "7.4", CurrentVersion() }; for (int hopIndex = 0; hopIndex < hopArray.Length; ++hopIndex) { string hop = hopArray[hopIndex]; Db4oLibraryEnvironment hopEnvironment = EnvironmentForVersion(hop); Assert.AreEqual(originalEnv.Version(), InvokeTesterMethodOn(hopEnvironment, "currentVersion" )); } IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration(); config.Common.ReflectWith(new ExcludingReflector(new Type[] { typeof(MigrationHopsTestCase.Item ) })); IEmbeddedObjectContainer container = Db4oEmbedded.OpenFile(config, TempFile()); try { IQuery query = container.Query(); query.Constrain(typeof(MigrationHopsTestCase.Item)); object item = query.Execute()[0]; Assert.AreEqual(originalEnv.Version(), ((GenericObject)item).Get(0)); } finally { container.Close(); } }
internal static void GetAndWriteSurrogates(IEmbeddedObjectContainer db, XmlWriter outfile) { // These two lines code uses the CachedProjectInformation to accumulate the raw data from Db4o to a manageable form var results = db.Query <CmObjectSurrogate>(); var asBytes = results.ToArray(); // And this line causes all the data to be available. Not putting this statement in causes the follow reads to hit // a premature end of the data CMOSTHandler.CachedProjectInformation.Compressor.Dispose(); byte[] compressedBytes = CMOSTHandler.CachedProjectInformation.CompressedMemoryStream.ToArray(); using (var stream = new GZipStream(new MemoryStream(compressedBytes), CompressionMode.Decompress)) { var temp = new byte[16]; var unicoding = new UnicodeEncoding(); var xml = ReadNextSurrogateXml(stream, unicoding); while (xml != null) { // just copy from in to out outfile.WriteRaw(xml); xml = ReadNextSurrogateXml(stream, unicoding); } } }
private void AssertExtentSize(int expectedCount, Type extent, IEmbeddedObjectContainer db) { IQuery query = db.Query(); query.Constrain(db.Ext().Reflector().ForName(extent.FullName)); IObjectSet result = query.Execute(); Assert.AreEqual(expectedCount, result.Count); }
public IList <T> Get <T>() { if (_db == null) { BeginTransaction(); } return(_db.Query <T>().ToList <T>()); }
public static void Delete <T>(this IEmbeddedObjectContainer db, Type t) { var result = db.Query <T>(t); foreach (var r in result) { db.Delete(r); } }
// Just gets the version from the opened db40 file internal static int GetModelVersionNumber(IEmbeddedObjectContainer db) { var result = db.Query <ModelVersionNumber>(); if (result.Count > 0) { return(result[0].m_modelVersionNumber); } else { return(0); } }
private void AssertVersionAfterDefrag(long version, IEmbeddedConfiguration afterDefragConfig ) { IEmbeddedObjectContainer db = OpenContainer(afterDefragConfig); CommitTimestampDefragmentTestCase.Item retrievedItem = ((CommitTimestampDefragmentTestCase.Item )db.Query(typeof(CommitTimestampDefragmentTestCase.Item)).Next()); long retrievedVersion = db.Ext().GetObjectInfo(retrievedItem).GetCommitTimestamp( ); Assert.AreEqual(version, retrievedVersion); db.Close(); }
public virtual void QueryDb(IEmbeddedConfiguration config, Type clazz, int count) { IEmbeddedObjectContainer database = Db4oEmbedded.OpenFile(config, TempFile()); try { IList list = database.Query(clazz); Assert.AreEqual(count, list.Count); } finally { database.Close(); } }
internal static void GetAndWriteCustomFieldInfo(IEmbeddedObjectContainer db, XmlWriter writer) { var customfields = new List <CustomFieldInfo>(); foreach (CustomFieldInfo cfi in db.Query <CustomFieldInfo>().ToArray()) { customfields.Add(cfi); } if (customfields.Count > 0) { writer.WriteStartElement("AdditionalFields"); foreach (CustomFieldInfo customFieldInfo in customfields) { writer.WriteStartElement("CustomField"); writer.WriteAttributeString("name", customFieldInfo.m_fieldname); writer.WriteAttributeString("class", customFieldInfo.m_classname); if (customFieldInfo.m_destinationClass != 0) { writer.WriteAttributeString("destclass", customFieldInfo.m_destinationClass.ToString()); } writer.WriteAttributeString("type", GetFlidTypeAsString(customFieldInfo.m_fieldType)); if (customFieldInfo.m_fieldWs != 0) { writer.WriteAttributeString("wsSelector", customFieldInfo.m_fieldWs.ToString()); } if (!String.IsNullOrEmpty(customFieldInfo.m_fieldHelp)) { writer.WriteAttributeString("helpString", customFieldInfo.m_fieldHelp); } if (customFieldInfo.m_fieldListRoot != Guid.Empty) { writer.WriteAttributeString("listRoot", customFieldInfo.m_fieldListRoot.ToString()); } if (customFieldInfo.Label != customFieldInfo.m_fieldname) { writer.WriteAttributeString("label", customFieldInfo.Label); } writer.WriteEndElement(); } writer.WriteEndElement(); } }
public virtual void TestEmbedded() { IList missingClasses = new ArrayList(); IEmbeddedConfiguration excludingConfig = Db4oEmbedded.NewConfiguration(); PrepareHost(excludingConfig.File, excludingConfig.Common, missingClasses); ExcludeClasses(excludingConfig.Common, new Type[] { typeof(MissingClassDiagnosticsTestCase.Pilot ), typeof(MissingClassDiagnosticsTestCase.Car) }); IEmbeddedObjectContainer excludingContainer = Db4oEmbedded.OpenFile(excludingConfig , DbUri); try { excludingContainer.Query(new MissingClassDiagnosticsTestCase.AcceptAllPredicate() ); } finally { excludingContainer.Close(); } AssertPilotAndCarMissing(missingClasses); }
// Just gets the version from the opened db40 file internal static int GetModelVersionNumber(IEmbeddedObjectContainer db) { var result = db.Query<ModelVersionNumber>(); if (result.Count > 0) return result[0].m_modelVersionNumber; else return 0; }
internal static void GetAndWriteSurrogates(IEmbeddedObjectContainer db, XmlWriter outfile) { // These two lines code uses the CachedProjectInformation to accumulate the raw data from Db4o to a manageable form var results = db.Query<CmObjectSurrogate>(); var asBytes = results.ToArray(); // And this line causes all the data to be available. Not putting this statement in causes the follow reads to hit // a premature end of the data CMOSTHandler.CachedProjectInformation.Compressor.Dispose(); byte[] compressedBytes = CMOSTHandler.CachedProjectInformation.CompressedMemoryStream.ToArray(); using (var stream = new GZipStream(new MemoryStream(compressedBytes), CompressionMode.Decompress)) { var temp = new byte[16]; var unicoding = new UnicodeEncoding(); var xml = ReadNextSurrogateXml(stream, unicoding); while (xml != null) { // just copy from in to out outfile.WriteRaw(xml); xml = ReadNextSurrogateXml(stream, unicoding); } } }
internal static void GetAndWriteCustomFieldInfo(IEmbeddedObjectContainer db, XmlWriter writer) { var customfields = new List<CustomFieldInfo>(); foreach (CustomFieldInfo cfi in db.Query<CustomFieldInfo>().ToArray()) { customfields.Add(cfi); } if (customfields.Count > 0) { writer.WriteStartElement("AdditionalFields"); foreach (CustomFieldInfo customFieldInfo in customfields) { writer.WriteStartElement("CustomField"); writer.WriteAttributeString("name", customFieldInfo.m_fieldname); writer.WriteAttributeString("class", customFieldInfo.m_classname); if (customFieldInfo.m_destinationClass != 0) writer.WriteAttributeString("destclass", customFieldInfo.m_destinationClass.ToString()); writer.WriteAttributeString("type", GetFlidTypeAsString(customFieldInfo.m_fieldType)); if (customFieldInfo.m_fieldWs != 0) writer.WriteAttributeString("wsSelector", customFieldInfo.m_fieldWs.ToString()); if (!String.IsNullOrEmpty(customFieldInfo.m_fieldHelp)) writer.WriteAttributeString("helpString", customFieldInfo.m_fieldHelp); if (customFieldInfo.m_fieldListRoot != Guid.Empty) writer.WriteAttributeString("listRoot", customFieldInfo.m_fieldListRoot.ToString()); if (customFieldInfo.Label != customFieldInfo.m_fieldname) writer.WriteAttributeString("label", customFieldInfo.Label); writer.WriteEndElement(); } writer.WriteEndElement(); } }
public IEnumerable <Person> GetAll() { return(_context.Query <Person>().ToArray()); }