
|
If you were logged in you would be able to see more operations.
|
|
|
db4o Core
Created: 23/Nov/07 05:28 AM
Updated: 02/Jan/08 03:31 PM
|
|
| Component/s: |
Client/Server
|
| Affects Version/s: |
7.0 - Development Release
|
| Fix Version/s: |
None
|
|
|
Time Tracking:
|
|
Original Estimate:
|
Not Specified
|
|
|
Remaining Estimate:
|
0h
|
|
|
Time Spent:
|
5h
|
|
|
|
|
Environment:
|
Java
|
|
Issue Links:
|
Similar
|
|
This issue is similar to:
|
|
|
COR-18 Multiple sorts in SODA queries is broken
|
|
|
|
|
|
|
|
| Order: |
4
|
| Iteration: |
23
|
| Resolution Date: |
02/Jan/08 03:31 PM
|
| First Response Date: |
31/Dec/07 11:34 AM
|
| PSC Recommendation: |
A7
|
| Labels: |
|
| Participants: |
Glaz Glazz@mail.ru and Norberto Goussies
|
| Number of Attachments: |
0
|
| Number of Comments: |
1
|
|
import java.io.File;
import com.db4o.*;
import com.db4o.query.Query;
public class SoringTest {
public static final String db_file="test.db4o";
public static void main(String[] args) {
ObjectContainer db=null;
ObjectServer server=null;
try{
File file=new File(db_file);
file.delete();
server=Db4o.openServer(db_file,1080);
server.grantAccess("SA","");
db=Db4o.openClient("127.0.0.1",1080,"SA" ,"");
runTest(db);
}catch(Exception e){e.printStackTrace();}finally{
if(db!=null)
db.close();
if(server!=null)
server.close();
}
}
public static void runTest(ObjectContainer db)throws Exception{
Pilot pilot=null;
Person person=null;
person=new Person("Alexandr","Pimanov",30);
pilot=new Pilot(person,5);
db.set(pilot);
person=new Person("Cris","Ivanov",30);
pilot=new Pilot(person,5);
db.set(pilot);
person=new Person("Boris","Ivanov",30);
pilot=new Pilot(person,5);
db.set(pilot);
person=new Person("Helen","Pit",25);
pilot=new Pilot(person,3);
db.set(pilot);
person=new Person("Zeus","Pit",25);
pilot=new Pilot(person,3);
db.set(pilot);
person=new Person("Alexsandra","Ivanova",25);
pilot=new Pilot(person,3);
db.set(pilot);
person=new Person("Liza","Pit",26);
pilot=new Pilot(person,4);
db.set(pilot);
person=new Person("Bred","Ivanov",26);
pilot=new Pilot(person,4);
db.set(pilot);
person=new Person("Gregory","Avsienko",26);
pilot=new Pilot(person,4);
db.set(pilot);
db.commit();
Query query=db.query();
query.constrain(Pilot.class);
query.descend("seniority").orderAscending();
query.descend("person").descend("age").orderAscending();
query.descend("person").descend("fist_name").orderAscending();
ObjectSet result=query.execute();
System.out.println("seniority age first_name");
while(result.hasNext()){
pilot=(Pilot)result.next();
System.out.println(pilot.seniority+" "+pilot.person.age+" "+pilot.person.first_name);
}
}
}
//*******************************************************************
public class Person {
public String first_name;
public String last_name;
public int age;
public Person(String first_name,String last_name, int age){
this.first_name=first_name;
this.last_name=last_name;
this.age=age;
}
}
//*******************************************************************
public class Pilot {
public Person person;
public int seniority;
public Pilot(Person person, int seniority){
this.person=person;
this.seniority=seniority;
}
}
//*******************************************************************
System.out:
seniority age first_name
3 25 Helen
3 25 Zeus
3 25 Alexsandra
4 26 Liza
4 26 Bred
4 26 Gregory
5 30 Alexandr
5 30 Cris
5 30 Boris
|
|
Description
|
import java.io.File;
import com.db4o.*;
import com.db4o.query.Query;
public class SoringTest {
public static final String db_file="test.db4o";
public static void main(String[] args) {
ObjectContainer db=null;
ObjectServer server=null;
try{
File file=new File(db_file);
file.delete();
server=Db4o.openServer(db_file,1080);
server.grantAccess("SA","");
db=Db4o.openClient("127.0.0.1",1080,"SA" ,"");
runTest(db);
}catch(Exception e){e.printStackTrace();}finally{
if(db!=null)
db.close();
if(server!=null)
server.close();
}
}
public static void runTest(ObjectContainer db)throws Exception{
Pilot pilot=null;
Person person=null;
person=new Person("Alexandr","Pimanov",30);
pilot=new Pilot(person,5);
db.set(pilot);
person=new Person("Cris","Ivanov",30);
pilot=new Pilot(person,5);
db.set(pilot);
person=new Person("Boris","Ivanov",30);
pilot=new Pilot(person,5);
db.set(pilot);
person=new Person("Helen","Pit",25);
pilot=new Pilot(person,3);
db.set(pilot);
person=new Person("Zeus","Pit",25);
pilot=new Pilot(person,3);
db.set(pilot);
person=new Person("Alexsandra","Ivanova",25);
pilot=new Pilot(person,3);
db.set(pilot);
person=new Person("Liza","Pit",26);
pilot=new Pilot(person,4);
db.set(pilot);
person=new Person("Bred","Ivanov",26);
pilot=new Pilot(person,4);
db.set(pilot);
person=new Person("Gregory","Avsienko",26);
pilot=new Pilot(person,4);
db.set(pilot);
db.commit();
Query query=db.query();
query.constrain(Pilot.class);
query.descend("seniority").orderAscending();
query.descend("person").descend("age").orderAscending();
query.descend("person").descend("fist_name").orderAscending();
ObjectSet result=query.execute();
System.out.println("seniority age first_name");
while(result.hasNext()){
pilot=(Pilot)result.next();
System.out.println(pilot.seniority+" "+pilot.person.age+" "+pilot.person.first_name);
}
}
}
//*******************************************************************
public class Person {
public String first_name;
public String last_name;
public int age;
public Person(String first_name,String last_name, int age){
this.first_name=first_name;
this.last_name=last_name;
this.age=age;
}
}
//*******************************************************************
public class Pilot {
public Person person;
public int seniority;
public Pilot(Person person, int seniority){
this.person=person;
this.seniority=seniority;
}
}
//*******************************************************************
System.out:
seniority age first_name
3 25 Helen
3 25 Zeus
3 25 Alexsandra
4 26 Liza
4 26 Bred
4 26 Gregory
5 30 Alexandr
5 30 Cris
5 30 Boris |
Show » |
|
q.descend("person").descend("fist_name").orderAscending();
should say:
q.descend("person").descend("first_name").orderAscending();
after this change the code works as expected.