public virtual void Test4() { string baseName = GetBaseName(); NeoDatis.Odb.ODB odb = Open(baseName); int size = 5; for (int i = 0; i < size; i++) { odb.Store(new Function("f" + (i + 1))); } odb.Close(); odb = Open(baseName); NeoDatis.Odb.Core.Query.IQuery q = new CriteriaQuery(); // q.orderByAsc("name"); NeoDatis.Odb.Objects <Function> objects = odb.GetObjects <Function>(q, true, 0, 2); AssertEquals(2, objects.Count); odb.Close(); odb = Open(baseName); q = new CriteriaQuery(); q.OrderByAsc("name"); objects = odb.GetObjects <Function>(q, true, 0, 2); AssertEquals(2, objects.Count); odb.Close(); odb = Open(baseName); q = new CriteriaQuery(); q.OrderByDesc("name"); objects = odb.GetObjects <Function>(q, true, 0, 2); AssertEquals(2, objects.Count); odb.Close(); }
/// <exception cref="System.Exception"></exception> public virtual void Test1() { NeoDatis.Odb.ODB odb = Open(BaseName); CriteriaQuery aq = new CriteriaQuery(Where.Or().Add(Where.Equal("string1", "test class 1")).Add(Where.Equal("string1", "test class 3"))); aq.OrderByAsc("string1"); NeoDatis.Odb.Objects <TestClass> l = odb.GetObjects <TestClass>(aq, true, -1, -1); AssertEquals(2, l.Count); TestClass testClass = l.GetFirst(); AssertEquals("test class 1", testClass.GetString1()); odb.Close(); }
/// <exception cref="System.Exception"></exception> public virtual void Test1() { DeleteBase("sict"); NeoDatis.Odb.ODB odb = Open("sict"); NeoDatis.Odb.Test.Update.Nullobject.User user = Popula(odb); AT at = CreateAT(user); odb.Store(at); odb.Store(CreateSensor(user, at, 1)); odb.Store(CreateSensor(user, at, 2)); odb.Store(CreateSensor(user, at, 3)); odb.Store(CreateSensor(user, at, 4)); odb.Close(); odb = Open("sict"); NeoDatis.Odb.Objects <AT> ats = odb.GetObjects <AT>(); int nbAts = ats.Count; at = (AT)ats.GetFirst(); AT newAT = null; SensorAT newSensor = null; NeoDatis.Odb.Core.Query.IQuery query = new CriteriaQuery(Where.Equal("at.name", at.GetName())); query.OrderByAsc("lane"); NeoDatis.Odb.Objects <SensorAT> sensors = odb.GetObjects <SensorAT>(query); Println("Duplicando AT " + at.GetName()); for (int i = 0; i < 10; i++) { newAT = DuplicateAT(at, nbAts + i + 1); odb.Store(newAT); sensors.Reset(); while (sensors.HasNext()) { newSensor = DuplicateSensor((SensorAT)sensors .Next(), newAT); odb.Store(newSensor); } } // println("AT " + newAT.getName()+" created"); odb.Close(); }
/// <summary> /// How to retrieve objects using Native queries /// </summary> /// /* * public void step8() { * ODB odb = null; * * try { * // Open the database * odb = ODBFactory.Open(ODB_NAME); * IQuery query = new SimpleNativeQuery() { public boolean match(Player player) { * return player.getFavoriteSport().getName().toLowerCase().startsWith("volley"); * } * }; * * Objects<Player> players = odb.GetObjects<Player>(query); * * Console.WriteLine("\nStep 8 bis: Players that play Volley-ball"); * * int i = 1; * // display each object * while (players.HasNext()) { * Console.WriteLine((i++) + "\t: " + players.Next()); * } * * } finally { * if (odb != null) { * // Close the database * odb.Close(); * } * } * } */ /** * Native query with Objects, * * * /// <summary> * /// How to retrieve objects using Criteria queries using object * /// </summary> * public void step9() { * ODB odb = null; * * try { * // Open the database * odb = ODBFactory.Open(ODB_NAME); * * // first retrieve the player Minh * IQuery query = new CriteriaQuery(typeof(Player), Where.Equal("name", "minh")); * Player minh = (Player) odb.GetObjects(query).getFirst(); * * // builds a query to get all teams where mihn plays * query = new CriteriaQuery(typeof(Team), Where.contain("players", minh)); * Objects teams = odb.GetObjects(query); * * Console.WriteLine("\nStep 9: Team where minh plays"); * * int i = 1; * // display each object * while (teams.HasNext()) { * Console.WriteLine((i++) + "\t: " + teams.Next()); * } * * } finally { * if (odb != null) { * // Close the database * odb.Close(); * } * } * }*/ /// <summary> /// How to retrieve objects using order by /// </summary> public void Step10() { ODB odb = null; try { // Open the database odb = ODBFactory.Open(ODB_NAME); IQuery query = new CriteriaQuery(typeof(Player)); query.OrderByAsc("name"); Objects <Player> players = odb.GetObjects <Player>(query); Console.WriteLine("\nStep 10: Players ordered by name asc"); int i = 1; // display each object while (players.HasNext()) { Console.WriteLine((i++) + "\t: " + players.Next()); } query.OrderByDesc("name"); players = odb.GetObjects <Player>(query); Console.WriteLine("\nStep 10: Players ordered by name desc"); i = 1; // display each object while (players.HasNext()) { Console.WriteLine((i++) + "\t: " + players.Next()); } } finally { if (odb != null) { odb.Close(); } } }
public virtual void Test6() { string baseName = GetBaseName(); NeoDatis.Odb.ODB odb = Open(baseName); int size = 5; for (int i = 0; i < size; i++) { odb.Store(new Function("f1")); } odb.Store(new Function(null)); odb.Close(); odb = Open(baseName); NeoDatis.Odb.Core.Query.IQuery q = new CriteriaQuery(Where.IsNull("name")); // q.orderByAsc("name"); NeoDatis.Odb.Objects <Function> objects = odb.GetObjects <Function>(q, true, 0, 10); System.Collections.IList l = new System.Collections.Generic.List <Function >(objects); AssertEquals(1, l.Count); odb.Close(); odb = Open(baseName); q = new CriteriaQuery(Where.IsNull("name")); q.OrderByAsc("name"); objects = odb.GetObjects <Function>(q, true, 0, 10); l = new System.Collections.Generic.List <Function>(objects ); AssertEquals(1, l.Count); odb.Close(); odb = Open(baseName); q = new CriteriaQuery(Where.IsNull("name")); q.OrderByDesc("name"); objects = odb.GetObjects <Function>(q, true, 0, 10); l = new System.Collections.Generic.List <Function>(objects ); AssertEquals(1, l.Count); odb.Close(); }
public virtual void Test1() { string baseName = GetBaseName(); NeoDatis.Odb.ODB odb = Open(baseName); odb.Store(new Class1("c1")); odb.Store(new Class1("c1")); odb.Store(new Class1("c2")); odb.Store(new Class1("c2")); odb.Store(new Class1("c3")); odb.Store(new Class1("c4")); odb.Close(); odb = Open(baseName); NeoDatis.Odb.Core.Query.IQuery q = new CriteriaQuery(); q.OrderByAsc("name"); NeoDatis.Odb.Objects <Class1> objects = odb.GetObjects <Class1>(q); AssertEquals(6, objects.Count); while (objects.HasNext()) { System.Console.Out.WriteLine(objects.Next()); } // println(objects); odb.Close(); }