diff --git a/example/src/com/example/AddNoteActivity.java b/example/src/com/example/AddNoteActivity.java index c0c960b9..4302c7ae 100755 --- a/example/src/com/example/AddNoteActivity.java +++ b/example/src/com/example/AddNoteActivity.java @@ -40,7 +40,7 @@ public void onCreate(Bundle savedInstanceState) { public void onClick(View view) { Tag tag = new Tag(AddNoteActivity.this, tagBox.getText().toString()); tag.save(); - new Note(AddNoteActivity.this, titleBox.getText().toString(), descBox.getText().toString(),tag).save(); + new Note(AddNoteActivity.this, 10, titleBox.getText().toString(), descBox.getText().toString(),tag).save(); Intent intent = new Intent(AddNoteActivity.this, NoteListActivity.class); startActivity(intent); } diff --git a/example/src/com/example/Note.java b/example/src/com/example/Note.java index 1e811ed3..e1ce8807 100755 --- a/example/src/com/example/Note.java +++ b/example/src/com/example/Note.java @@ -4,7 +4,7 @@ import com.orm.SugarRecord; public class Note extends SugarRecord{ - + private int noteId; private String title; private String description; private Tag tag; @@ -13,13 +13,22 @@ public Note(Context context){ super(context); } - public Note(Context context, String title, String description, Tag tag) { + public Note(Context context, int noteId, String title, String description, Tag tag) { super(context); + this.noteId = noteId; this.title = title; this.description = description; this.tag = tag; } + public int getNoteId() { + return noteId; + } + + public void setNoteId(int noteId) { + this.noteId = noteId; + } + public String getTitle() { return title; } diff --git a/example/src/com/example/NoteListActivity.java b/example/src/com/example/NoteListActivity.java index 5200954b..029a1e0c 100755 --- a/example/src/com/example/NoteListActivity.java +++ b/example/src/com/example/NoteListActivity.java @@ -1,24 +1,22 @@ package com.example; -import android.app.Activity; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; -import com.orm.SugarRecord; +import com.orm.query.Select; import java.util.List; -import static com.orm.dsl.Collection.list; - public class NoteListActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notelist); - List notes = Note.listAll(Note.class); + List notes = Select.from(Note.class).orderBy("title").limit("2").list();//Note.listAll(Note.class); + setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, notes)); findViewById(R.id.Button01).setOnClickListener(new View.OnClickListener() { diff --git a/example/src/com/example/NoteRelation.java b/example/src/com/example/NoteRelation.java new file mode 100644 index 00000000..84b5be2a --- /dev/null +++ b/example/src/com/example/NoteRelation.java @@ -0,0 +1,38 @@ +package com.example; + +import android.content.Context; +import com.orm.SugarRecord; + +public class NoteRelation extends SugarRecord { + String name; + int noteId; + + + public NoteRelation(Context context) { + super(context); + } + + public NoteRelation(Context context, String name, int noteId) { + super(context); + this.name = name; + this.noteId = noteId; + + } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getNoteId() { + return noteId; + } + + public void setNoteId(int noteId) { + this.noteId = noteId; + } + + +} diff --git a/example/src/com/example/SugarActivity.java b/example/src/com/example/SugarActivity.java index c8fbf024..26114525 100755 --- a/example/src/com/example/SugarActivity.java +++ b/example/src/com/example/SugarActivity.java @@ -26,10 +26,10 @@ private void initDb() { t1.save(); t2.save(); - Note n1 = new Note(this, "note1", "description1", t1); - Note n2 = new Note(this, "note2", "description2", t1); - Note n3 = new Note(this, "note3", "description3", t2); - Note n4 = new Note(this, "note4", "description4", t2); + Note n1 = new Note(this, 10, "note1", "description1", t1); + Note n2 = new Note(this, 10, "note2", "description2", t1); + Note n3 = new Note(this, 10, "note3", "description3", t2); + Note n4 = new Note(this, 10, "note4", "description4", t2); n1.save(); n2.save(); @@ -37,13 +37,13 @@ private void initDb() { n4.save(); n1.setDescription("matrix"); - n1.setTitle("matrix"); + n1.setTitle("atrix"); n1.save(); n2.setDescription("matrix"); - n2.setTitle("matrix"); + n2.setTitle("satrix"); n2.save(); n3.setDescription("matrix"); - n3.setTitle("matrix"); + n3.setTitle("batrix"); n3.save(); } diff --git a/library/src/com/orm/query/Select.java b/library/src/com/orm/query/Select.java index c7aa2751..1176781f 100644 --- a/library/src/com/orm/query/Select.java +++ b/library/src/com/orm/query/Select.java @@ -11,6 +11,7 @@ public class Select { private String[] arguments; private String whereClause = ""; private String orderBy; + private String groupBy; private String limit; private String offset; @@ -24,6 +25,23 @@ public static Select from(Class record) { return new Select(record); } + public Select orderBy(String prop) { + this.orderBy = prop; + return this; + } + + public Select groupBy(String prop) { + this.groupBy = prop; + return this; + } + + public Select limit(String limit) { + this.limit = limit; + return this; + } + + + public Select where(String whereClause) { this.whereClause = whereClause; return this; @@ -81,7 +99,7 @@ public List list() { if(arguments == null) arguments = convertArgs(args); - return T.find(record, whereClause, arguments); + return T.find(record, whereClause, arguments,groupBy,orderBy,limit); }