├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_second.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── assets
│ │ │ └── 数据库操作指南
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── xsm
│ │ │ │ └── easydb
│ │ │ │ ├── SecondActivity.java
│ │ │ │ ├── bean
│ │ │ │ ├── Dog.java
│ │ │ │ ├── People.java
│ │ │ │ └── User.java
│ │ │ │ ├── MyApplication.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── xsm
│ │ │ └── easydb
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── xsm
│ │ └── easydb
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── db
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── xsm
│ │ │ └── db
│ │ │ ├── db
│ │ │ ├── assist
│ │ │ │ ├── IDaoAssist.java
│ │ │ │ ├── Condition.java
│ │ │ │ └── DaoAssist.java
│ │ │ ├── IBaseDao.java
│ │ │ ├── BaseDaoFactory.java
│ │ │ └── BaseDao.java
│ │ │ ├── utils
│ │ │ └── Utils.java
│ │ │ ├── annotation
│ │ │ ├── DbFiled.java
│ │ │ └── DbTable.java
│ │ │ └── EasyDB.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── xsm
│ │ │ └── db
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── xsm
│ │ └── db
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
└── vcs.xml
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/db/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':chargingview-release', ':db'
2 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/db/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | db
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | EasyDB
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/db/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/EasyDB/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #4259A6
4 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/assets/数据库操作指南:
--------------------------------------------------------------------------------
1 | ### 首先确保手机已ROOT
2 | 第一步:adb shell
3 | 第二部:cd /data/data/com.example.xuyushi.loadertest/databases
4 | 第三步:sqlite3 数据库名
5 | 第四部:.table (查看已建的表格)
6 | 第五步:select * from tablename; (后面的分号记得加)
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Mar 08 10:51:45 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/db/assist/IDaoAssist.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db.db.assist;
2 |
3 | /**
4 | * Author: 夏胜明
5 | * Date: 2018/7/31 0031
6 | * Email: xiasem@163.com
7 | * Github:https://github.com/Xiasm
8 | * Description:
9 | */
10 | public interface IDaoAssist {
11 |
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db.utils;
2 |
3 | import android.text.TextUtils;
4 |
5 | /**
6 | * Author: 夏胜明
7 | * Date: 2018/7/31 0031
8 | * Email: xiasem@163.com
9 | * Github:https://github.com/Xiasm
10 | * Description:
11 | */
12 | public class Utils {
13 | public static boolean isEmpty(String string) {
14 | return TextUtils.isEmpty(string);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xsm/easydb/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package com.xsm.easydb;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | public class SecondActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_second);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xsm/easydb/bean/Dog.java:
--------------------------------------------------------------------------------
1 | package com.xsm.easydb.bean;
2 |
3 | /**
4 | * Author: 夏胜明
5 | * Date: 2018/3/8 0008
6 | * Email: xiasem@163.com
7 | * Description:
8 | */
9 |
10 | public class Dog {
11 | private float weight;
12 |
13 | public float getWeight() {
14 | return weight;
15 | }
16 |
17 | public void setWeight(float weight) {
18 | this.weight = weight;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xsm/easydb/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.xsm.easydb;
2 |
3 | import android.app.Application;
4 |
5 | import com.xsm.db.EasyDB;
6 |
7 | /**
8 | * Author: 夏胜明
9 | * Date: 2018/7/31 0031
10 | * Email: xiasem@163.com
11 | * Description:
12 | */
13 | public class MyApplication extends Application {
14 | @Override
15 | public void onCreate() {
16 | super.onCreate();
17 | EasyDB.init(this);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/db/src/test/java/com/xsm/db/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/xsm/easydb/bean/People.java:
--------------------------------------------------------------------------------
1 | package com.xsm.easydb.bean;
2 |
3 | /**
4 | * Author: 夏胜明
5 | * Date: 2018/3/8 0008
6 | * Email: xiasem@163.com
7 | * Description:
8 | */
9 |
10 | public class People {
11 | public People(int sex) {
12 | this.sex = sex;
13 | }
14 |
15 | private int sex;
16 |
17 | public int getSex() {
18 | return sex;
19 | }
20 |
21 | public void setSex(int sex) {
22 | this.sex = sex;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Intellij IDEA
2 | .idea/
3 | *.iml
4 | *.ipr
5 | *.iws
6 | out/
7 |
8 | # Gradle build folder
9 | build/
10 | .gradle/
11 |
12 | # Android
13 | local.properties
14 | bin/
15 | gen/
16 |
17 | # JNI compile files
18 | *.o
19 | *.o.d
20 |
21 | # OS autogen folder information
22 | .DS_Store
23 | Thumbs.db
24 |
25 | # Temp files
26 | *.bak
27 | *.tmp
28 | *.temp
29 | *.swp
30 | *.*~
31 | ~*.*
32 |
33 | # Eclipse project files
34 | .classpath
35 | .settings/
36 | .project
37 |
38 | #Android 2.2 C/C++ compile
39 | .externalNativeBuild/
40 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/db/IBaseDao.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db.db;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Author: 夏胜明
7 | * Date: 2018/3/8 0008
8 | * Email: xiasem@163.com
9 | * Github:https://github.com/Xiasm
10 | * Description:
11 | */
12 |
13 | public interface IBaseDao {
14 |
15 | long insert(T entity);
16 |
17 | long update(T entity, T where);
18 |
19 | int delete(T where);
20 |
21 | List query(T where);
22 |
23 | List query(T where, String orderBy, Integer startIndex, Integer limit);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/annotation/DbFiled.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Author: 夏胜明
10 | * Date: 2018/3/8 0008
11 | * Email: xiasem@163.com
12 | * Github:https://github.com/Xiasm
13 | * Description: 此注解用来修饰表字段,如果没有加此注解,默认用字段名作为列名
14 | */
15 | @Target(ElementType.FIELD)
16 | @Retention(RetentionPolicy.RUNTIME)
17 | public @interface DbFiled {
18 | String value();
19 | }
20 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/annotation/DbTable.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Author: 夏胜明
10 | * Date: 2018/3/8 0008
11 | * Email: xiasem@163.com
12 | * Github:https://github.com/Xiasm
13 | * Description: 此注解用来定义表名,如果没有添加此注解,默认以类名作为表名
14 | */
15 | @Target(ElementType.TYPE)
16 | @Retention(RetentionPolicy.RUNTIME)
17 | public @interface DbTable {
18 | String value();
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/test/java/com/xsm/easydb/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xsm.easydb;
2 |
3 | import android.util.Log;
4 | import android.widget.Toast;
5 |
6 | import com.xsm.easydb.bean.People;
7 | import com.xsm.easydb.db.BaseDao;
8 | import com.xsm.easydb.db.BaseDaoFactory;
9 |
10 | import org.junit.Test;
11 |
12 | import static org.junit.Assert.*;
13 |
14 | /**
15 | * Example local unit test, which will execute on the development machine (host).
16 | *
17 | * @see Testing documentation
18 | */
19 | public class ExampleUnitTest {
20 | private static final String TAG = "ExampleUnitTest";
21 | @Test
22 | public void addition_isCorrect() throws Exception {
23 | assertEquals(4, 2 + 2);
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/db/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/db/src/androidTest/java/com/xsm/db/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.xsm.db.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/xsm/easydb/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.xsm.easydb;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.xsm.easydb", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/db/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'com.android.support:appcompat-v7:26.1.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
34 | }
35 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/EasyDB.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Author: 夏胜明
7 | * Date: 2018/7/31 0031
8 | * Email: xiasem@163.com
9 | * Github:https://github.com/Xiasm
10 | * Description:
11 | */
12 | public class EasyDB {
13 | private static Context mApplicationContext;
14 | private static String mPackageName;
15 | private static boolean init = false;
16 |
17 | public static void init(Context context) {
18 | if (context == null) {
19 | throw new RuntimeException("init context is null");
20 | }
21 | mApplicationContext = context.getApplicationContext();
22 | mPackageName = mApplicationContext.getPackageName();
23 | init = true;
24 | }
25 |
26 | public static Context getApplicationContext() {
27 | return mApplicationContext;
28 | }
29 |
30 | public static String getPackageName() {
31 | return mPackageName;
32 | }
33 |
34 | public static boolean isInit() {
35 | return init;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.xsm.easydb"
7 | minSdkVersion 14
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28 | implementation project(':db')
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xsm/easydb/bean/User.java:
--------------------------------------------------------------------------------
1 | package com.xsm.easydb.bean;
2 |
3 |
4 | import com.xsm.db.annotation.DbFiled;
5 | import com.xsm.db.annotation.DbTable;
6 |
7 | /**
8 | * Author: 夏胜明
9 | * Date: 2018/3/8 0008
10 | * Email: xiasem@163.com
11 | * Description:
12 | */
13 | @DbTable("tb_user")
14 | public class User {
15 | private Integer id;
16 | @DbFiled("userName")
17 | private String name;
18 | private String phone;
19 |
20 | public int getId() {
21 | return id;
22 | }
23 |
24 | public void setId(int id) {
25 | this.id = id;
26 | }
27 |
28 | public String getName() {
29 | return name;
30 | }
31 |
32 | public void setName(String name) {
33 | this.name = name;
34 | }
35 |
36 | public String getPhone() {
37 | return phone;
38 | }
39 |
40 | public void setPhone(String phone) {
41 | this.phone = phone;
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return "User{" +
47 | "id=" + id +
48 | ", name='" + name + '\'' +
49 | ", phone='" + phone + '\'' +
50 | '}';
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/db/assist/Condition.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db.db.assist;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Iterator;
5 | import java.util.Map;
6 | import java.util.Set;
7 |
8 | /**
9 | * Author: 夏胜明
10 | * Date: 2018/7/31 0031
11 | * Email: xiasem@163.com
12 | * Github:https://github.com/Xiasm
13 | * Description:
14 | */
15 | public class Condition {
16 | public String whereCause;
17 | public String[] whereArgs;
18 |
19 | public Condition(Map whereCause) {
20 | ArrayList list = new ArrayList<>();
21 | StringBuilder builder = new StringBuilder();
22 | builder.append("1=1");
23 | Set keys = whereCause.keySet();
24 | Iterator iterator = keys.iterator();
25 | while (iterator.hasNext()) {
26 | String key = iterator.next();
27 | String value = whereCause.get(key);
28 | if (value != null) {
29 | builder.append(" and " + key + "=?");
30 | list.add(value);
31 | }
32 | }
33 | this.whereCause = builder.toString();
34 | this.whereArgs = list.toArray(new String[list.size()]);
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
21 |
26 |
31 |
36 |
37 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/db/BaseDaoFactory.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db.db;
2 |
3 | import android.database.sqlite.SQLiteDatabase;
4 |
5 | import com.xsm.db.EasyDB;
6 |
7 | /**
8 | * Author: 夏胜明
9 | * Date: 2018/3/8 0008
10 | * Email: xiasem@163.com
11 | * Github:https://github.com/Xiasm
12 | * Description:
13 | */
14 |
15 | public class BaseDaoFactory {
16 | private static BaseDaoFactory instance = null;
17 |
18 | public static BaseDaoFactory getInstance() {
19 | if (instance == null) {
20 | synchronized (BaseDaoFactory.class) {
21 | if (instance == null) {
22 | instance = new BaseDaoFactory();
23 | }
24 | }
25 | }
26 | return instance;
27 | }
28 |
29 | private SQLiteDatabase mSQLiteDatabase;
30 |
31 | private BaseDaoFactory() {
32 | if (!EasyDB.isInit()) {
33 | throw new RuntimeException("easy db not init !");
34 | }
35 | String dbPath = "data/data/" + EasyDB.getPackageName() + "/easydb.db";
36 | mSQLiteDatabase = SQLiteDatabase.openOrCreateDatabase(dbPath, null);
37 | }
38 |
39 | public , V> T getDao(Class daoClass, Class entityClass) {
40 | BaseDao baseDao = null;
41 | try {
42 | baseDao = daoClass.newInstance();
43 | baseDao.init(mSQLiteDatabase, entityClass);
44 | } catch (InstantiationException e) {
45 | e.printStackTrace();
46 | } catch (IllegalAccessException e) {
47 | e.printStackTrace();
48 | }
49 | return (T) baseDao;
50 | }
51 |
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### EasyDB是一款轻量级的ORM框架
2 |
3 | EasyDB是从项目里抽离出来的一款数据库操作框架,可以方便的实现将java对象映射到SQLite数据库中,并且提供了快捷的增删改查功能,同时你也可以很方便的扩展出基于EasyDB的数据库功能操作。
4 |
5 | #### 如何使用
6 |
7 | * 初始化
8 | 初始化操作不会损耗任何性能,只是为了拿到包名,方便在使用的时候建立或打开数据库表,因此建议在application的onCreate()方法里进行初始化。
9 | ```
10 | public class MyApplication extends Application {
11 | @Override
12 | public void onCreate() {
13 | super.onCreate();
14 | EasyDB.init(this);
15 | }
16 | }
17 | ```
18 |
19 | * 插入操作
20 | ```
21 | public void insert(View view) {
22 | User user = new User();
23 | user.setId(new Random().nextInt(1000));
24 | user.setName("李四");
25 | user.setPhone("123456789");
26 | BaseDao dao = BaseDaoFactory.getInstance().getDao(BaseDao.class, User.class);
27 | long insert = dao.insert(user);
28 | }
29 | ```
30 |
31 | * 更新操作
32 | ```
33 | public void update(View view) {
34 | BaseDao dao = BaseDaoFactory.getInstance().getDao(BaseDao.class, User.class);
35 | User user = new User();
36 | user.setPhone("15514087661");
37 | User where = new User();
38 | where.setName("张三");
39 | long update = dao.update(user, where);
40 | }
41 | ```
42 |
43 | * 删除操作
44 | ```
45 | public void delete(View view) {
46 | BaseDao dao = BaseDaoFactory.getInstance().getDao(BaseDao.class, User.class);
47 | User user = new User();
48 | user.setName("李四");
49 | int delete = dao.delete(user);
50 | }
51 | ```
52 |
53 | * 查询操作
54 | ```
55 | public void query(View view) {
56 | BaseDao dao = BaseDaoFactory.getInstance().getDao(BaseDao.class, User.class);
57 | User where = new User();
58 | where.setName("张三");
59 | List query = dao.query(where);
60 | }
61 | ```
62 |
63 | #### 关于我
64 |
65 | email:xiasem@163.com
66 |
67 | 如果对你有收获,欢迎点击star。
68 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xsm/easydb/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.xsm.easydb;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.Toast;
9 |
10 | import com.xsm.db.db.BaseDao;
11 | import com.xsm.db.db.BaseDaoFactory;
12 | import com.xsm.db.utils.Utils;
13 | import com.xsm.easydb.bean.User;
14 |
15 | import java.util.List;
16 | import java.util.Random;
17 |
18 | public class MainActivity extends AppCompatActivity {
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | String packageCodePath = getPackageName();
25 | if (Utils.isEmpty(packageCodePath) ) {
26 |
27 | }
28 | }
29 |
30 | public void insert(View view) {
31 | User user = new User();
32 | user.setId(new Random().nextInt(1000));
33 | user.setName("李四");
34 | user.setPhone("123456789");
35 | BaseDao dao = BaseDaoFactory.getInstance().getDao(BaseDao.class, User.class);
36 | long insert = dao.insert(user);
37 | }
38 |
39 | public void update(View view) {
40 | BaseDao dao = BaseDaoFactory.getInstance().getDao(BaseDao.class, User.class);
41 | User user = new User();
42 | user.setPhone("15514087661");
43 | User where = new User();
44 | where.setName("张三");
45 | long update = dao.update(user, where);
46 | }
47 |
48 | public void delete(View view) {
49 | BaseDao dao = BaseDaoFactory.getInstance().getDao(BaseDao.class, User.class);
50 | User user = new User();
51 | user.setName("李四");
52 | int delete = dao.delete(user);
53 | }
54 |
55 | public void query(View view) {
56 | BaseDao dao = BaseDaoFactory.getInstance().getDao(BaseDao.class, User.class);
57 | User where = new User();
58 | where.setName("张三");
59 | List query = dao.query(where);
60 | }
61 |
62 | private static final String TAG = "MainActivity";
63 |
64 | public void nextActivity(View view) {
65 | startActivity(new Intent(MainActivity.this, SecondActivity.class));
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/db/BaseDao.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db.db;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import com.xsm.db.db.assist.Condition;
7 | import com.xsm.db.db.assist.DaoAssist;
8 |
9 | import java.util.HashMap;
10 | import java.util.List;
11 |
12 | /**
13 | * Author: 夏胜明
14 | * Date: 2018/3/8 0008
15 | * Email: xiasem@163.com
16 | * Github:https://github.com/Xiasm
17 | * Description:完成自动建表的功能
18 | */
19 |
20 | public class BaseDao extends DaoAssist implements IBaseDao {
21 |
22 | @Override
23 | public long insert(T entity) {
24 | HashMap map = getEntityKeyValues(entity);
25 | ContentValues values = getContentValues(map);
26 | return mSQLiteDatabase.insert(mTableName, null, values);
27 | }
28 |
29 | @Override
30 | public long update(T entity, T where) {
31 | //sqLiteDatabase.update(tableName,contentValues,"name=",new String[]{"jett"});
32 | HashMap map = getEntityKeyValues(entity);
33 | ContentValues contentValues = getContentValues(map);
34 | HashMap whereCause = getEntityKeyValues(where);
35 | Condition condition = new Condition(whereCause);
36 | return mSQLiteDatabase.update(mTableName, contentValues, condition.whereCause, condition.whereArgs);
37 | }
38 |
39 | @Override
40 | public int delete(T where) {
41 | HashMap map = getEntityKeyValues(where);
42 | Condition condition = new Condition(map);
43 | return mSQLiteDatabase.delete(mTableName, condition.whereCause, condition.whereArgs);
44 | }
45 |
46 | @Override
47 | public List query(T where) {
48 | return query(where, null, null, null);
49 | }
50 |
51 | @Override
52 | public List query(T where, String orderBy, Integer startIndex, Integer limit) {
53 | // sqLiteDatabase.query(tableName,null,"id=?",new String[],null,null,orderBy,"1,5");
54 | HashMap map = getEntityKeyValues(where);
55 | String limitString = null;
56 | if (startIndex != null && limit != null) {
57 | limitString = startIndex + " , " + limit;
58 | }
59 | Condition condition = new Condition(map);
60 | Cursor cursor = mSQLiteDatabase.query(mTableName, null, condition.whereCause, condition.whereArgs, null, null, orderBy, limitString);
61 | return getResult(cursor, where);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/db/src/main/java/com/xsm/db/db/assist/DaoAssist.java:
--------------------------------------------------------------------------------
1 | package com.xsm.db.db.assist;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 | import android.database.sqlite.SQLiteDatabase;
6 | import android.text.TextUtils;
7 | import android.util.Log;
8 |
9 | import com.xsm.db.annotation.DbFiled;
10 | import com.xsm.db.annotation.DbTable;
11 | import com.xsm.db.db.assist.IDaoAssist;
12 | import com.xsm.db.utils.Utils;
13 |
14 | import java.lang.reflect.Field;
15 | import java.util.ArrayList;
16 | import java.util.HashMap;
17 | import java.util.Iterator;
18 | import java.util.List;
19 | import java.util.Map;
20 | import java.util.Set;
21 |
22 | /**
23 | * Author: 夏胜明
24 | * Date: 2018/7/31 0031
25 | * Email: xiasem@163.com
26 | * Github:https://github.com/Xiasm
27 | * Description:
28 | */
29 | public class DaoAssist implements IDaoAssist {
30 | protected SQLiteDatabase mSQLiteDatabase;
31 | protected Class mEntityClass;
32 | protected String mTableName;
33 | protected boolean isInit = false;
34 |
35 | /**
36 | * 为了避免多次调用反射损耗性能,这里定义一个缓存空间
37 | *
38 | * (key—表的列字段名,value—成员变量)
39 | */
40 | protected HashMap mCacheMap;
41 |
42 | public boolean init(SQLiteDatabase sqLiteDatabase, Class entityClass) {
43 | this.mSQLiteDatabase = sqLiteDatabase;
44 | this.mEntityClass = entityClass;
45 | if (!isInit) {
46 | DbTable dbTable = mEntityClass.getAnnotation(DbTable.class);
47 | if (dbTable != null && !Utils.isEmpty(dbTable.value())) {
48 | mTableName = dbTable.value();
49 | } else {
50 | mTableName = mEntityClass.getSimpleName();
51 | }
52 | if (!mSQLiteDatabase.isOpen()) {
53 | return false;
54 | }
55 | //执行建表操作
56 | String createTableSql = getCreateTableSql();
57 | mSQLiteDatabase.execSQL(createTableSql);
58 | initCacheMap();
59 | isInit = true;
60 | }
61 | return isInit;
62 | }
63 |
64 | /**
65 | * 反射获取表的列名和实体类字段名映射关系并缓存
66 | */
67 | protected void initCacheMap() {
68 | if (mCacheMap == null) {
69 | mCacheMap = new HashMap<>();
70 | }
71 | //取到所有的列名
72 | String sql = "select * from " + mTableName + " limit 1,0";
73 | Cursor cursor = mSQLiteDatabase.rawQuery(sql, null);
74 | String[] columnNames = cursor.getColumnNames();
75 | cursor.close();
76 | //取到所有的成员变量
77 | Field[] columnFields = mEntityClass.getDeclaredFields();
78 | for (Field columnField : columnFields) {
79 | columnField.setAccessible(true);
80 | }
81 | //进行映射
82 | for (String columnName : columnNames) {
83 | Field field = null;
84 | for (Field columnField : columnFields) {
85 | String fieldName = null;
86 | DbFiled dbFiled = columnField.getAnnotation(DbFiled.class);
87 | if (dbFiled != null && !Utils.isEmpty(dbFiled.value())) {
88 | fieldName = dbFiled.value();
89 | } else {
90 | fieldName = columnField.getName();
91 | }
92 | if (columnName.equals(fieldName)) {
93 | field = columnField;
94 | break;
95 | }
96 | }
97 | if (field != null) {
98 | mCacheMap.put(columnName, field);
99 | }
100 | }
101 | }
102 |
103 | /**
104 | * 根据Class字节码文件获取创建表的语句
105 | * @return
106 | */
107 | protected String getCreateTableSql() {
108 | //create table if not exists tb_user(_id INTEGER,name TEXT,password TEXT)
109 | StringBuffer buffer = new StringBuffer();
110 | buffer.append("create table if not exists ");
111 | buffer.append(mTableName + "(");
112 | Field[] fields = mEntityClass.getDeclaredFields();
113 | for (Field field : fields) {
114 | Class> type = field.getType();
115 | String columnName = field.getName();
116 | DbFiled dbFiled = field.getAnnotation(DbFiled.class);
117 | if (dbFiled != null && !TextUtils.isEmpty(dbFiled.value())) {
118 | columnName = dbFiled.value();
119 | }
120 | if (type == String.class) {
121 | buffer.append(columnName + " TEXT,");
122 | } else if (type == Integer.class || type == int.class) {
123 | buffer.append(columnName + " INTEGER,");
124 | } else if (type == Long.class || type == long.class) {
125 | buffer.append(columnName + " BIGINT,");
126 | } else if (type == Double.class || type == double.class) {
127 | buffer.append(columnName + " DOUBLE,");
128 | } else if (type == Float.class || type == float.class) {
129 | buffer.append(columnName + " DOUBLE,");
130 | } else if (type == byte[].class) {
131 | buffer.append(columnName + " BLOB,");
132 | } else {
133 | //不支持的类型
134 | Log.e(TAG, "getCreateTableSql: 不支持的类型 ClassName=" + mEntityClass.getSimpleName() + ", columnName=" + columnName);
135 | continue;
136 | }
137 | }
138 | if (buffer.charAt(buffer.length() - 1) == ',') {
139 | buffer.deleteCharAt(buffer.length() - 1);
140 | }
141 | buffer.append(")");
142 | return buffer.toString();
143 | }
144 |
145 | /**
146 | * 获取对象不为空的成员变量和成员变量的值
147 | * @param entity 实体类
148 | * @return 实体类entity的字段名和值的集合
149 | */
150 | protected HashMap getEntityKeyValues(T entity) {
151 | HashMap map = new HashMap<>();
152 | for (Field field : mCacheMap.values()) {
153 | field.setAccessible(true);
154 | try {
155 | Object object = field.get(entity);
156 | if (object == null) {
157 | continue;
158 | }
159 | String value = object.toString();
160 | String key = null;
161 | DbFiled dbFiled = field.getAnnotation(DbFiled.class);
162 | if (dbFiled != null && !Utils.isEmpty(dbFiled.value())) {
163 | key = dbFiled.value();
164 | } else {
165 | key = field.getName();
166 | }
167 | if (!Utils.isEmpty(key) && !Utils.isEmpty(value)) {
168 | map.put(key, value);
169 | }
170 | } catch (IllegalAccessException e) {
171 | e.printStackTrace();
172 | }
173 | }
174 | return map;
175 | }
176 |
177 | /**
178 | * 根据map里字段的键值对添加ContentValues
179 | * @param map key=字段名 value=字段值
180 | * @return
181 | */
182 | protected ContentValues getContentValues(HashMap map) {
183 | ContentValues contentValues = new ContentValues();
184 | Set keys = map.keySet();
185 | Iterator iterator = keys.iterator();
186 | while (iterator.hasNext()) {
187 | String key = iterator.next();
188 | String value = map.get(key);
189 | if (value != null) {
190 | contentValues.put(key, value);
191 | }
192 | }
193 | return contentValues;
194 | }
195 |
196 | /**
197 | * 取得cursor里查询到的数据,组装成实体类list
198 | * @param cursor
199 | * @param obj
200 | * @return 返回实体类List
201 | */
202 | protected List getResult(Cursor cursor, T obj) {
203 | ArrayList list = new ArrayList<>();
204 | Object item = null;
205 | while (cursor.moveToNext()) {
206 | try {
207 | item = obj.getClass().newInstance();
208 | //表字段-成员变量
209 | Iterator> iterator = mCacheMap.entrySet().iterator();
210 | while (iterator.hasNext()) {
211 | Map.Entry entry = iterator.next();
212 | //取列名
213 | String columnName = entry.getKey();
214 | int columnIndex = cursor.getColumnIndex(columnName);
215 | if (columnIndex == -1) {
216 | continue;
217 | }
218 | Field field = entry.getValue();
219 | Class> type = field.getType();
220 | if (type == String.class) {
221 | field.set(item, cursor.getString(columnIndex));
222 | } else if (type == Double.class || type == double.class) {
223 | field.set(item, cursor.getDouble(columnIndex));
224 | } else if (type == Integer.class || type == int.class) {
225 | field.set(item, cursor.getInt(columnIndex));
226 | } else if (type == Long.class || type == long.class) {
227 | field.set(item, cursor.getLong(columnIndex));
228 | } else if (type == byte[].class) {
229 | field.set(item, cursor.getBlob(columnIndex));
230 | } else {
231 | continue;
232 | }
233 | }
234 | list.add(item);
235 | } catch (InstantiationException e) {
236 | e.printStackTrace();
237 | } catch (IllegalAccessException e) {
238 | e.printStackTrace();
239 | }
240 | }
241 | cursor.close();
242 | return list;
243 | }
244 |
245 | private static final String TAG = "DaoAssist";
246 | }
247 |
--------------------------------------------------------------------------------