Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation based entities #129

Merged
merged 4 commits into from
Aug 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions example/src/com/example/AddNoteActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import static com.orm.SugarRecord.save;


public class AddNoteActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -39,8 +41,8 @@ public void onCreate(Bundle savedInstanceState) {
save.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Tag tag = new Tag(tagBox.getText().toString());
tag.save();
new Note( 10, titleBox.getText().toString(), descBox.getText().toString(),tag).save();
save(tag);
save(new Note(10 + (int) (10 * Math.random()), titleBox.getText().toString(), descBox.getText().toString(), tag));
Intent intent = new Intent(AddNoteActivity.this, NoteListActivity.class);
startActivity(intent);
}
Expand Down
11 changes: 11 additions & 0 deletions example/src/com/example/NewNote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example;

import com.orm.dsl.Table;

@Table(name = "new_note")
public class NewNote {

public long id;
public String name;

}
21 changes: 12 additions & 9 deletions example/src/com/example/Note.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.example;

import com.orm.SugarRecord;
import com.orm.dsl.Column;
import com.orm.dsl.Table;

public class Note extends SugarRecord<Note>{
@Table(name = "Note")
public class Note {

private long id;

@Column(name = "noteId", unique = true, notNull = true)
private int noteId;
Expand Down Expand Up @@ -42,25 +45,25 @@ public String getTitle() {
return title;
}

public String getDescription() {
return description;
public void setTitle(String title) {
this.title = title;
}

public Tag getTag() {
return tag;
public String getDescription() {
return description;
}

public void setDescription(String description){
this.description = description;
}

public void setTitle(String title) {
this.title = title;
public Tag getTag() {
return tag;
}

@Override
public String toString() {
return title + "id: " + id + " - " + tag + " " + tag.getId();
return title + "id: " + noteId;

}
}
5 changes: 3 additions & 2 deletions example/src/com/example/NoteListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;

import com.orm.SugarRecord;
import com.orm.query.Condition;
import com.orm.query.Select;

Expand All @@ -19,8 +19,9 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.notelist);

List<Note> notes = Select.from(Note.class).orderBy("title").list();//Note.listAll(Note.class);
List<NewNote> list = SugarRecord.listAll(NewNote.class);

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

findViewById(R.id.Button01).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Expand Down
5 changes: 3 additions & 2 deletions example/src/com/example/NoteRelation.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.example;

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

public class NoteRelation extends SugarRecord<Note> {
@Table(name = "note_relation")
public class NoteRelation {
String name;
int noteId;

Expand Down
42 changes: 22 additions & 20 deletions example/src/com/example/SugarActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import com.orm.Database;
import com.orm.SugarApp;
import com.orm.SugarRecord;

import static com.orm.SugarRecord.save;

public class SugarActivity extends Activity
{
Expand All @@ -16,9 +15,10 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Note.deleteAll(Note.class);
TextNote.deleteAll(TextNote.class);
Tag.deleteAll(Tag.class);
SugarRecord.deleteAll(Note.class);
SugarRecord.deleteAll(TextNote.class);
SugarRecord.deleteAll(Tag.class);
SugarRecord.deleteAll(NewNote.class);
initDb();
Intent intent = new Intent(this, NoteListActivity.class);
startActivity(intent);
Expand All @@ -28,8 +28,8 @@ private void initDb() {

Tag t1 = new Tag("tag1");
Tag t2 = new Tag("tag2");
t1.save();
t2.save();
save(t1);
save(t2);

Note n1 = new Note( 10, "note1", "description1", t1);
Note n2 = new Note(11, "note12", "description2", t1);
Expand All @@ -39,23 +39,25 @@ private void initDb() {
TextNote textNote = new TextNote();
textNote.desc = "Test";

textNote.save();
n1.save();
n2.save();
n3.save();
n4.save();
save(textNote);
save(n1);
save(n2);
save(n3);
save(n4);

n1.setDescription("matrix");
n1.setTitle("atrix");
n1.save();
save(n1);
n2.setDescription("matrix");
n2.setTitle("satrix");
n2.save();
save(n2);
n3.setDescription("matrix");
n3.setTitle("batrix");
n3.save();


save(n3);

}
NewNote newNote = new NewNote();
newNote.name = "name";
save(newNote);

}
}
6 changes: 3 additions & 3 deletions example/src/com/example/Tag.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.example;

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

public class Tag extends SugarRecord<Tag>{
@Table(name = "tag")
public class Tag {
private String name;

public Tag(String name) {
Expand Down
3 changes: 3 additions & 0 deletions example/src/com/example/TextNote.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example;

import com.orm.dsl.Table;

@Table(name = "text_note")
public class TextNote extends Note {

public String desc;
Expand Down
24 changes: 0 additions & 24 deletions library/src/com/orm/Database.java

This file was deleted.

Loading