public virtual void Test4Sort() { string baseName = GetBaseName(); SetUp(baseName); int d = NeoDatis.Odb.OdbConfiguration.GetDefaultIndexBTreeDegree(); try { NeoDatis.Odb.OdbConfiguration.SetDefaultIndexBTreeDegree(40); NeoDatis.Odb.ODB odb = Open(baseName); CriteriaQuery aq = new CriteriaQuery (typeof(Function), Where .Not(Where.Or().Add(Where .Equal("name", "function 2")).Add(Where.Equal("name" , "function 3")))); aq.OrderByDesc("name"); // aq.orderByAsc("name"); NeoDatis.Odb.Objects <Function> l = odb.GetObjects <Function>(aq, true, -1, -1); odb.Close(); AssertEquals(48, l.Count); Function f = (Function)l.GetFirst (); AssertEquals("function 9", f.GetName()); } finally { NeoDatis.Odb.OdbConfiguration.SetDefaultIndexBTreeDegree(d); } }
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 Test4Sort() { NeoDatis.Odb.ODB odb = Open(BaseName); CriteriaQuery aq = new CriteriaQuery(Where.Not(Where.Or().Add(Where.Equal("string1", "test class 2")).Add(Where.Equal("string1", "test class 3")))); aq.OrderByDesc("double1,int1"); NeoDatis.Odb.Objects <TestClass> l = odb.GetObjects <TestClass> (aq, true, -1, -1); // println(l); AssertEquals(48, l.Count); TestClass testClass = l.GetFirst(); AssertEquals("test class 9", testClass.GetString1()); odb.Close(); }
public virtual void TestLike2() { string baseName = GetBaseName(); SetUp(baseName); NeoDatis.Odb.ODB odb = Open(baseName); CriteriaQuery aq = new CriteriaQuery (typeof(Function), Where .Like("name", "FuNc%")); aq.OrderByDesc("name"); NeoDatis.Odb.Objects <Function> l = odb.GetObjects <Function>(aq, true, -1, -1); AssertEquals(0, l.Count); odb.Close(); }
/// <exception cref="System.Exception"></exception> public virtual void Test6Sort() { NeoDatis.Odb.ODB odb = Open(BaseName); NeoDatis.Odb.Core.Query.Criteria.ICriterion c = Where .Or().Add(Where.Equal("string1", "test class 2" )).Add(Where.Equal("string1", "test class 3")). Add(Where.Equal("string1", "test class 4")).Add (Where.Equal("string1", "test class 5")); CriteriaQuery aq = new CriteriaQuery(c); aq.OrderByDesc("boolean1,int1"); NeoDatis.Odb.Objects <TestClass> l = odb.GetObjects <TestClass>(aq, true, -1, -1); AssertEquals(4, l.Count); TestClass testClass = l.GetFirst(); AssertEquals("test class 3", testClass.GetString1()); 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(); }