Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
satya committed Nov 24, 2012
2 parents 81b1984 + 79a659d commit 54ba13e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 16 deletions.
2 changes: 1 addition & 1 deletion example/src/com/example/AddNoteActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 11 additions & 2 deletions example/src/com/example/Note.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.orm.SugarRecord;

public class Note extends SugarRecord<Note>{

private int noteId;
private String title;
private String description;
private Tag tag;
Expand All @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions example/src/com/example/NoteListActivity.java
Original file line number Diff line number Diff line change
@@ -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<Note> notes = Note.listAll(Note.class);
List<Note> notes = Select.from(Note.class).orderBy("title").limit("2").list();//Note.listAll(Note.class);

setListAdapter(new ArrayAdapter<Note>(this,android.R.layout.simple_list_item_1, notes));

findViewById(R.id.Button01).setOnClickListener(new View.OnClickListener() {
Expand Down
38 changes: 38 additions & 0 deletions example/src/com/example/NoteRelation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example;

import android.content.Context;
import com.orm.SugarRecord;

public class NoteRelation extends SugarRecord<Note> {
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;
}


}
14 changes: 7 additions & 7 deletions example/src/com/example/SugarActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ 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();
n3.save();
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();

}
Expand Down
20 changes: 19 additions & 1 deletion library/src/com/orm/query/Select.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Select<T extends SugarRecord> {
private String[] arguments;
private String whereClause = "";
private String orderBy;
private String groupBy;
private String limit;
private String offset;

Expand All @@ -24,6 +25,23 @@ public static <T extends SugarRecord> Select from(Class<T> record) {
return new Select<T>(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;
Expand Down Expand Up @@ -81,7 +99,7 @@ public List<T> list() {

if(arguments == null) arguments = convertArgs(args);

return T.find(record, whereClause, arguments);
return T.find(record, whereClause, arguments,groupBy,orderBy,limit);

}

Expand Down

0 comments on commit 54ba13e

Please sign in to comment.