Skip to content

Commit

Permalink
add support for greendao 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yuweiguocn committed Oct 12, 2016
1 parent 27cb5d2 commit fb5f972
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 135 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ GreenDaoUpgradeHelper is a database upgrade helper for greenDao.Use GreenDaoUpgr
2.Add the dependency
```
dependencies {
compile 'com.github.yuweiguocn:GreenDaoUpgradeHelper:v1.0.1'
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.github.yuweiguocn:GreenDaoUpgradeHelper:v1.1.0'
}
```

Expand Down
3 changes: 2 additions & 1 deletion README_CH.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ GreenDaoUpgradeHelper是一个greenDao的数据库升级帮助类。使用它可
2.添加依赖
```
dependencies {
compile 'com.github.yuweiguocn:GreenDaoUpgradeHelper:v1.0.1'
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.github.yuweiguocn:GreenDaoUpgradeHelper:v1.1.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'de.greenrobot:greendao:2.0.0'
compile 'org.greenrobot:greendao:3.2.0'

// compile 'com.github.yuweiguocn:GreenDaoUpgradeHelper:v1.0.0'
compile project(':library')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,100 @@
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import de.greenrobot.dao.AbstractDaoMaster;
import de.greenrobot.dao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.AbstractDaoMaster;
import org.greenrobot.greendao.database.StandardDatabase;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseOpenHelper;
import org.greenrobot.greendao.identityscope.IdentityScopeType;


// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 10): knows all DAOs.
*/
/**
* Master of DAO (schema version 12): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 10;
public static final int SCHEMA_VERSION = 15;

/** Creates underlying database table using DAOs. */
public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
public static void createAllTables(Database db, boolean ifNotExists) {
TestDataDao.createTable(db, ifNotExists);
TestData2Dao.createTable(db, ifNotExists);
TestData3Dao.createTable(db, ifNotExists);
}

/** Drops underlying database table using DAOs. */
public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
public static void dropAllTables(Database db, boolean ifExists) {
TestDataDao.dropTable(db, ifExists);
TestData2Dao.dropTable(db, ifExists);
TestData3Dao.dropTable(db, ifExists);
}

public static abstract class OpenHelper extends SQLiteOpenHelper {

public OpenHelper(Context context, String name, CursorFactory factory) {
super(context, name, factory, SCHEMA_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
createAllTables(db, false);
}
/**
* WARNING: Drops all table on Upgrade! Use only during development.
* Convenience method using a {@link DevOpenHelper}.
*/
public static DaoSession newDevSession(Context context, String name) {
Database db = new DevOpenHelper(context, name).getWritableDb();
DaoMaster daoMaster = new DaoMaster(db);
return daoMaster.newSession();
}

public DaoMaster(SQLiteDatabase db) {
this(new StandardDatabase(db));
}

public DaoMaster(Database db) {
super(db, SCHEMA_VERSION);
registerDaoClass(TestDataDao.class);
registerDaoClass(TestData2Dao.class);
registerDaoClass(TestData3Dao.class);
}

public DaoSession newSession() {
return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
}

public DaoSession newSession(IdentityScopeType type) {
return new DaoSession(db, type, daoConfigMap);
}


/**
* Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
*/
public static abstract class OpenHelper extends DatabaseOpenHelper {
public OpenHelper(Context context, String name) {
super(context, name, SCHEMA_VERSION);
}

public OpenHelper(Context context, String name, CursorFactory factory) {
super(context, name, factory, SCHEMA_VERSION);
}

@Override
public void onCreate(Database db) {
Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
createAllTables(db, false);
}
}

/** WARNING: Drops all table on Upgrade! Use only during development. */
public static class DevOpenHelper extends OpenHelper {
public DevOpenHelper(Context context, String name) {
super(context, name);
}

public DevOpenHelper(Context context, String name, CursorFactory factory) {
super(context, name, factory);
}

@Override
public void onUpgrade(Database db, int oldVersion, int newVersion) {
Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
dropAllTables(db, true);
onCreate(db);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.github.yuweiguocn.demo.greendao.db;

import android.database.sqlite.SQLiteDatabase;

import java.util.Map;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.AbstractDaoSession;
import de.greenrobot.dao.identityscope.IdentityScopeType;
import de.greenrobot.dao.internal.DaoConfig;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.AbstractDaoSession;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.internal.DaoConfig;

import com.github.yuweiguocn.demo.greendao.db.TestData;
import com.github.yuweiguocn.demo.greendao.db.TestData2;
Expand All @@ -34,7 +33,7 @@ public class DaoSession extends AbstractDaoSession {
private final TestData2Dao testData2Dao;
private final TestData3Dao testData3Dao;

public DaoSession(SQLiteDatabase db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
daoConfigMap) {
super(db);

Expand All @@ -57,9 +56,9 @@ public DaoSession(SQLiteDatabase db, IdentityScopeType type, Map<Class<? extends
}

public void clear() {
testDataDaoConfig.getIdentityScope().clear();
testData2DaoConfig.getIdentityScope().clear();
testData3DaoConfig.getIdentityScope().clear();
testDataDaoConfig.clearIdentityScope();
testData2DaoConfig.clearIdentityScope();
testData3DaoConfig.clearIdentityScope();
}

public TestDataDao getTestDataDao() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
package com.github.yuweiguocn.demo.greendao.db;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
import org.greenrobot.greendao.annotation.*;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.

/**
* Entity mapped to table "TEST_DATA".
*/
@Entity
public class TestData {

@Id(autoincrement = true)
private Long id;
private String testString;
private Long testLong;
private java.util.Date testDate;
private Integer testInt;
private Boolean testBoolean;

@Generated
public TestData() {
}

public TestData(Long id) {
this.id = id;
}

@Generated
public TestData(Long id, String testString, Long testLong, java.util.Date testDate, Integer testInt, Boolean testBoolean) {
this.id = id;
this.testString = testString;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
package com.github.yuweiguocn.demo.greendao.db;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
import org.greenrobot.greendao.annotation.*;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.

/**
* Entity mapped to table "TEST_DATA2".
*/
@Entity
public class TestData2 {

@Id(autoincrement = true)
private Long id;
private String testString;
private Long testLong;
private java.util.Date testDate;
private Integer testInt;
private Boolean testBoolean;

@Generated
public TestData2() {
}

public TestData2(Long id) {
this.id = id;
}

@Generated
public TestData2(Long id, String testString, Long testLong, java.util.Date testDate, Integer testInt, Boolean testBoolean) {
this.id = id;
this.testString = testString;
Expand Down
Loading

0 comments on commit fb5f972

Please sign in to comment.