Skip to content
Open
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
3 changes: 2 additions & 1 deletion app/src/main/java/com/jayway/ormlite/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {

public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
sDatabaseHelper = this;
}

@Override
Expand Down Expand Up @@ -134,4 +135,4 @@ public void close() {
public static DatabaseHelper getInstance() {
return sDatabaseHelper;
}
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/jayway/ormlite/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_main);
}

private void example() throws SQLException {
Expand Down Expand Up @@ -50,14 +50,14 @@ private void example() throws SQLException {
userDao.create(user);

// Obtain the role
user = userDao.queryForId(0);
user = userDao.queryForId(user.getId());
Role role = user.getRole();

// One-to-many
user = new User().setName("Clause");
userDao.create(user); // Without creating the object this won't work.

final Dao<Email, Integer> emailsDao = DatabaseHelper.getInstance().getEmailDao();
final Dao<Email, Integer> emailsDao = helper.getEmailDao();
emailsDao.create(new Email(user).setEmail("my@example.com"));
emailsDao.create(new Email(user).setEmail("my2@example.com"));

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/jayway/ormlite/model/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
@DatabaseTable(tableName = Role.TABLE_NAME_ROLES)
public class Role {

public Role() {
// Don't forget the empty constructor, needed by ORMLite.
}

public static final String TABLE_NAME_ROLES = "roles";

public static final String FIELD_NAME_ID = "id";
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/jayway/ormlite/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
@DatabaseTable(tableName = User.TABLE_NAME_USERS, daoClass = CustomDao.class)
public class User {

public User() {
// Don't forget the empty constructor, needed by ORMLite.
}

public static final String TABLE_NAME_USERS = "users";

public static final String FIELD_NAME_ID = "id";
Expand Down