├── library ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── android │ │ │ └── sqlite │ │ │ └── orm │ │ │ ├── OnDBUpgrade.java │ │ │ ├── IDColumn.java │ │ │ ├── DBFile.java │ │ │ ├── OpenHelper.java │ │ │ ├── DBContextUse.java │ │ │ ├── DBContext.java │ │ │ ├── OpenHelperProxy.java │ │ │ ├── ClassInfo.java │ │ │ └── DBProxy.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── sanders │ │ └── db │ │ └── sanders │ │ └── com │ │ └── library │ │ └── ApplicationTest.java ├── build.gradle ├── proguard-rules.pro └── gradle.properties ├── sample ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ └── layout │ │ │ │ └── activity_simple.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── sanders │ │ │ │ └── db │ │ │ │ └── simple │ │ │ │ ├── TableBean.java │ │ │ │ ├── TableModel.java │ │ │ │ └── SimpleActivity.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── com │ │ └── sanders │ │ └── db │ │ └── sanders │ │ └── com │ │ └── dbproject │ │ └── ApplicationTest.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── .gitignore ├── gradle.properties ├── README.md └── LICENSE /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':library' 2 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | local.properties 3 | .idea 4 | .DS_Store 5 | build 6 | *.iml 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DBProject 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sopage/android-orm/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sopage/android-orm/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sopage/android-orm/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sopage/android-orm/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/sanders/db/sanders/com/library/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.sanders.db.sanders.com.library; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/sanders/db/sanders/com/dbproject/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.sanders.db.sanders.com.dbproject; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /library/src/main/java/android/sqlite/orm/OnDBUpgrade.java: -------------------------------------------------------------------------------- 1 | package android.sqlite.orm; 2 | 3 | import android.database.sqlite.SQLiteDatabase; 4 | 5 | /** 6 | * 数据库升级操作类 7 | * Created by sanders on 15/5/9. 8 | */ 9 | public interface OnDBUpgrade { 10 | 11 | /** 12 | * 数据库升级调用此方法 13 | * 14 | * @param db 15 | * @param oldVersion 16 | * @param newVersion 17 | * @return true是手动升级,false是自动升级 18 | */ 19 | boolean onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /sample/src/main/java/com/sanders/db/simple/TableBean.java: -------------------------------------------------------------------------------- 1 | package com.sanders.db.simple; 2 | 3 | import android.sqlite.orm.IDColumn; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * Created by sanders on 15/3/30. 9 | */ 10 | public class TableBean extends IDColumn { 11 | 12 | private String fieldString; 13 | private short fieldShort; 14 | private int fieldInt; 15 | private long fieldLong; 16 | private double fieldDouble; 17 | private float fieldFloat; 18 | private byte[] fieldBytes; 19 | private boolean fieldBoolean; 20 | private Date fieldDate; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | android { 3 | compileSdkVersion 15 4 | buildToolsVersion "22.0.1" 5 | defaultConfig { 6 | minSdkVersion 15 7 | targetSdkVersion 22 8 | versionCode 1 9 | versionName "1.0" 10 | } 11 | buildTypes { 12 | release { 13 | minifyEnabled false 14 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 15 | } 16 | } 17 | productFlavors { 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | } -------------------------------------------------------------------------------- /library/src/main/java/android/sqlite/orm/IDColumn.java: -------------------------------------------------------------------------------- 1 | package android.sqlite.orm; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 所有数据库表对应的实体类都要继承自此类 7 | * 此类只统一主键为primary_key而不是_id,这样以防ID冲突 8 | */ 9 | public abstract class IDColumn implements Serializable { 10 | 11 | /** 12 | * 主键ID 自增长类型 13 | */ 14 | public static final String PRIMARY_ID = "_id"; 15 | 16 | /** 17 | * 主键ID 自增长类型 18 | */ 19 | private long _id; 20 | 21 | public long getPrimaryId() { 22 | return _id; 23 | } 24 | 25 | public void setPrimaryId(long id) { 26 | this._id = id; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 15 5 | buildToolsVersion '22.0.1' 6 | 7 | defaultConfig { 8 | applicationId "com.sanders.db.simple" 9 | minSdkVersion 15 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation project(':library') 25 | } 26 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/sanders/Developer/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/sanders/Developer/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=1.0-SNAPSHOT 2 | 3 | POM_GROUP=com.github.supersanders 4 | POM_ARTIFACT_ID=sqlite-orm 5 | POM_PACKAGING=aar 6 | 7 | POM_NAME=Android SQLite ORM 8 | POM_DESCRIPTION=Android SQLite ORM. 9 | 10 | POM_URL=https://github.com/SuperSanders/cube-orm 11 | POM_SCM_URL=https://github.com/SuperSanders/cube-orm 12 | POM_SCM_CONNECTION=scm:https://github.com/SuperSanders/cube-orm.git 13 | POM_SCM_DEV_CONNECTION=scm:https://github.com/SuperSanders/cube-orm.git 14 | 15 | POM_LICENCE_NAME=MIT 16 | POM_LICENCE_URL=http://opensource.org/licenses/MIT 17 | POM_LICENCE_DIST=repo 18 | POM_DEVELOPER_ID=Mr. Sanders 19 | POM_DEVELOPER_NAME=Mr. Sanders 20 | 21 | POM_ISSUE_SYSTEM=GitHub Issues 22 | POM_ISSUE_URL=https://github.com/SuperSanders/cube-orm/issues 23 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /library/src/main/java/android/sqlite/orm/DBFile.java: -------------------------------------------------------------------------------- 1 | package android.sqlite.orm; 2 | 3 | import android.database.sqlite.SQLiteDatabase; 4 | 5 | import java.io.File; 6 | 7 | /** 8 | * Created by sanders on 15/5/17. 9 | */ 10 | public class DBFile { 11 | 12 | private File dbFile; 13 | 14 | public DBFile(File dbFile) { 15 | this.dbFile = dbFile; 16 | } 17 | 18 | public DBFile(String dbFilePath) { 19 | this.dbFile = new File(dbFilePath); 20 | } 21 | 22 | public DBProxy buildDBProxy() { 23 | DBProxy proxy = new DBProxy() { 24 | private SQLiteDatabase database; 25 | 26 | @Override 27 | public SQLiteDatabase getCreateDatabase() { 28 | if (database == null || !database.isOpen()) { 29 | database = SQLiteDatabase.openOrCreateDatabase(dbFile, null); 30 | } 31 | return database; 32 | } 33 | }; 34 | return proxy; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /library/src/main/java/android/sqlite/orm/OpenHelper.java: -------------------------------------------------------------------------------- 1 | package android.sqlite.orm; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | import android.database.sqlite.SQLiteOpenHelper; 6 | 7 | import java.util.Collection; 8 | 9 | /** 10 | * Created by sanders on 15/6/20. 11 | */ 12 | public class OpenHelper extends SQLiteOpenHelper { 13 | 14 | private OnDBUpgrade mUpgrade; 15 | private Collection mSql; 16 | 17 | public OpenHelper(Context context, String name, int version) { 18 | super(context, name, null, version); 19 | } 20 | 21 | public void addCreateTableSqlList(Collection sql) { 22 | this.mSql = sql; 23 | } 24 | 25 | public void setOnUpgrade(OnDBUpgrade upgrade) { 26 | this.mUpgrade = upgrade; 27 | } 28 | 29 | @Override 30 | public void onCreate(SQLiteDatabase db) { 31 | for (String sql : mSql) { 32 | db.execSQL(sql); 33 | } 34 | } 35 | 36 | @Override 37 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 38 | if (mUpgrade != null) { 39 | mUpgrade.onUpgrade(db, oldVersion, newVersion); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /library/src/main/java/android/sqlite/orm/DBContextUse.java: -------------------------------------------------------------------------------- 1 | package android.sqlite.orm; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | 6 | import java.util.Collection; 7 | import java.util.LinkedHashSet; 8 | 9 | /** 10 | * Created by sanders on 15/6/20. 11 | */ 12 | public class DBContextUse { 13 | private String name; 14 | private int version; 15 | private OnDBUpgrade upgrade; 16 | private Collection mSqlList = new LinkedHashSet(); 17 | 18 | public DBContextUse(String name, int version, OnDBUpgrade upgrade) { 19 | this.name = name; 20 | this.version = version; 21 | this.upgrade = upgrade; 22 | } 23 | 24 | public DBContextUse addCreateTableSql(String sql) { 25 | this.mSqlList.add(sql); 26 | return this; 27 | } 28 | 29 | public DBProxy buildDBProxy(Context context) { 30 | final OpenHelper helper = new OpenHelper(context, name, version); 31 | helper.addCreateTableSqlList(mSqlList); 32 | helper.setOnUpgrade(upgrade); 33 | DBProxy proxy = new DBProxy() { 34 | @Override 35 | public SQLiteDatabase getCreateDatabase() { 36 | return helper.getWritableDatabase(); 37 | } 38 | }; 39 | return proxy; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /library/src/main/java/android/sqlite/orm/DBContext.java: -------------------------------------------------------------------------------- 1 | package android.sqlite.orm; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | 6 | import java.util.Collection; 7 | import java.util.LinkedHashSet; 8 | 9 | /** 10 | * Created by sanders on 15/5/17. 11 | */ 12 | public class DBContext { 13 | 14 | private String name; 15 | private int version; 16 | private OnDBUpgrade upgrade; 17 | private Collection tableBeans = new LinkedHashSet(); 18 | 19 | public DBContext(String name, int version, OnDBUpgrade upgrade) { 20 | this.name = name; 21 | this.version = version; 22 | this.upgrade = upgrade; 23 | } 24 | 25 | public DBContext addTableBean(Class clazz) { 26 | this.tableBeans.add(clazz); 27 | return this; 28 | } 29 | 30 | public DBProxy buildDBProxy(Context context) { 31 | final OpenHelperProxy helper = new OpenHelperProxy(context, name, version); 32 | helper.addTableBeans(tableBeans); 33 | helper.setOnUpgrade(upgrade); 34 | DBProxy proxy = new DBProxy() { 35 | @Override 36 | public SQLiteDatabase getCreateDatabase() { 37 | return helper.getWritableDatabase(); 38 | } 39 | }; 40 | helper.setDBProxy(proxy); 41 | return proxy; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_simple.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 |