├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── administrator
│ │ │ │ └── lemondaodemo
│ │ │ │ ├── dataModel
│ │ │ │ ├── FileDao.java
│ │ │ │ ├── FileModel.java
│ │ │ │ ├── UserDao.java
│ │ │ │ └── User.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── administrator
│ │ │ └── lemondaodemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── administrator
│ │ └── lemondaodemo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── Logo
├── a.png
└── b.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/Logo/a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Soon-gz/LemonDaoDemo/HEAD/Logo/a.png
--------------------------------------------------------------------------------
/Logo/b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Soon-gz/LemonDaoDemo/HEAD/Logo/b.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LemonDaoDemo
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Soon-gz/LemonDaoDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Soon-gz/LemonDaoDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Soon-gz/LemonDaoDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Soon-gz/LemonDaoDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Soon-gz/LemonDaoDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Soon-gz/LemonDaoDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/administrator/lemondaodemo/dataModel/FileDao.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.lemondaodemo.dataModel;
2 |
3 |
4 | import com.example.lemonlibrary.db.DefaultBaseDao;
5 |
6 | /**
7 | * Created by ShuWen on 2017/2/12.
8 | */
9 |
10 | public class FileDao extends DefaultBaseDao {
11 | }
12 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/administrator/lemondaodemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.lemondaodemo;
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() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/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 G:\sdk/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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/administrator/lemondaodemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.lemondaodemo;
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 | * Instrumentation 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.example.administrator.lemondaodemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.example.administrator.lemondaodemo"
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.1.0'
28 | testCompile 'junit:junit:4.12'
29 | compile 'com.singleshu8:LemonDao:1.0.5'
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/administrator/lemondaodemo/dataModel/FileModel.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.lemondaodemo.dataModel;
2 |
3 |
4 | import com.example.lemonlibrary.db.annotion.DbField;
5 | import com.example.lemonlibrary.db.annotion.DbPrimaryField;
6 | import com.example.lemonlibrary.db.annotion.DbTable;
7 |
8 | /**
9 | * Created by ShuWen on 2017/2/9.
10 | */
11 | @DbTable(value = "tb_file")
12 | public class FileModel {
13 |
14 | @DbPrimaryField(value = "id")
15 | private int id;
16 | @DbField(value = "tb_filename")
17 | private String fileName;
18 | @DbField(value = "tb_filepath")
19 | private String filePath;
20 | @DbField(value = "tb_fileid")
21 | private int fileId;
22 |
23 | public String getFileName() {
24 | return fileName;
25 | }
26 |
27 | public void setFileName(String fileName) {
28 | this.fileName = fileName;
29 | }
30 |
31 | public String getFilePath() {
32 | return filePath;
33 | }
34 |
35 | public void setFilePath(String filePath) {
36 | this.filePath = filePath;
37 | }
38 |
39 | public int getFileId() {
40 | return fileId;
41 | }
42 |
43 | public void setFileId(int fileId) {
44 | this.fileId = fileId;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/administrator/lemondaodemo/dataModel/UserDao.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.lemondaodemo.dataModel;
2 |
3 |
4 | import com.example.lemonlibrary.db.DefaultBaseDao;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Created by ShuWen on 2017/2/12.
10 | */
11 |
12 | public class UserDao extends DefaultBaseDao {
13 |
14 |
15 | // @Override
16 | // public Long insert(User entity) {
17 | // List list=query(new User());
18 | // User where = null;
19 | // for (User user:list)
20 | // {
21 | // where =new User();
22 | // where.setUser_id(user.getUser_id());
23 | // user.setStatus(0);
24 | // Log.i(TAG,"用户"+user.getName()+"更改为未登录状态");
25 | // update(user,where);
26 | // }
27 | // Log.i(TAG,"用户"+entity.getName()+"登录");
28 | // entity.setStatus(1);
29 | // return super.insert(entity);
30 | // }
31 |
32 |
33 | /**
34 | * 得到当前登录的User
35 | * @return
36 | */
37 | public User getCurrentUser() {
38 | User user=new User();
39 | user.setStatus(1);
40 | List list=query(user);
41 | if(list.size()>0)
42 | {
43 | return list.get(0);
44 | }
45 | return null;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
26 |
32 |
39 |
46 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/administrator/lemondaodemo/dataModel/User.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.lemondaodemo.dataModel;
2 |
3 |
4 | import com.example.lemonlibrary.db.annotion.DbField;
5 | import com.example.lemonlibrary.db.annotion.DbPrimaryField;
6 | import com.example.lemonlibrary.db.annotion.DbTable;
7 |
8 | /**
9 | * Created by ShuWen on 2017/2/9.
10 | */
11 |
12 | @DbTable(value = "tb_user")
13 | public class User {
14 |
15 | @DbPrimaryField(value = "id")
16 | private Integer id;
17 | @DbField(value = "user_name")
18 | private String name;
19 | @DbField(value = "user_address")
20 | private String address;
21 | @DbField(value = "user_psw")
22 | private String psw;
23 | @DbField(value = "user_status")
24 | private Integer status;
25 | @DbField(value = "user_id")
26 | private String user_id;
27 | @DbField(value = "isMe")
28 | private Boolean isMe;
29 | @DbField(value = "myAge")
30 | private Double myAge;
31 | @DbField(value = "myPhone")
32 | private Long myPhone;
33 | @DbField(value = "aShort")
34 | private Short aShort;
35 |
36 | public User(String name, String address, String psw, Integer status, String user_id, Boolean isMe, Double myAge, Long myPhone, Short aShort) {
37 | this.name = name;
38 | this.address = address;
39 | this.psw = psw;
40 | this.status = status;
41 | this.user_id = user_id;
42 | this.isMe = isMe;
43 | this.myAge = myAge;
44 | this.myPhone = myPhone;
45 | this.aShort = aShort;
46 | }
47 |
48 | public User() {
49 | }
50 |
51 | public Integer getId() {
52 | return id;
53 | }
54 |
55 | public void setId(Integer id) {
56 | this.id = id;
57 | }
58 |
59 | public String getName() {
60 | return name;
61 | }
62 |
63 | public void setName(String name) {
64 | this.name = name;
65 | }
66 |
67 | public String getAddress() {
68 | return address;
69 | }
70 |
71 | public void setAddress(String address) {
72 | this.address = address;
73 | }
74 |
75 | public String getPsw() {
76 | return psw;
77 | }
78 |
79 | public void setPsw(String psw) {
80 | this.psw = psw;
81 | }
82 |
83 | public Integer getStatus() {
84 | return status;
85 | }
86 |
87 | public void setStatus(Integer status) {
88 | this.status = status;
89 | }
90 |
91 | public String getUser_id() {
92 | return user_id;
93 | }
94 |
95 | public void setUser_id(String user_id) {
96 | this.user_id = user_id;
97 | }
98 |
99 | public Boolean getMe() {
100 | return isMe;
101 | }
102 |
103 | public void setMe(Boolean me) {
104 | isMe = me;
105 | }
106 |
107 | public Double getMyAge() {
108 | return myAge;
109 | }
110 |
111 | public void setMyAge(Double myAge) {
112 | this.myAge = myAge;
113 | }
114 |
115 | public Long getMyPhone() {
116 | return myPhone;
117 | }
118 |
119 | public void setMyPhone(Long myPhone) {
120 | this.myPhone = myPhone;
121 | }
122 |
123 | public Short getaShort() {
124 | return aShort;
125 | }
126 |
127 | public void setaShort(Short aShort) {
128 | this.aShort = aShort;
129 | }
130 |
131 | @Override
132 | public String toString() {
133 | return "User{" +
134 | "id=" + id +
135 | ", name='" + name + '\'' +
136 | ", address='" + address + '\'' +
137 | ", psw='" + psw + '\'' +
138 | ", status=" + status +
139 | ", user_id='" + user_id + '\'' +
140 | ", isMe=" + isMe +
141 | ", myAge=" + myAge +
142 | ", myPhone=" + myPhone +
143 | ", aShort=" + aShort +
144 | '}';
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/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/java/com/example/administrator/lemondaodemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.lemondaodemo;
2 |
3 | import android.os.Environment;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 |
9 | import com.example.administrator.lemondaodemo.dataModel.FileDao;
10 | import com.example.administrator.lemondaodemo.dataModel.FileModel;
11 | import com.example.administrator.lemondaodemo.dataModel.User;
12 | import com.example.administrator.lemondaodemo.dataModel.UserDao;
13 | import com.example.lemonlibrary.db.BaseDaoFactory;
14 | import com.example.lemonlibrary.db.IBaseDao;
15 | import com.example.lemonlibrary.db.util.PermissionUtils;
16 |
17 | import java.util.List;
18 |
19 |
20 | @SuppressWarnings("unchecked")
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | private IBaseDao iBaseDao;
24 |
25 | String dbFile;
26 | int i = 0;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 | //数据库地址 文件夹
33 | dbFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myDb";
34 | //6.0以上动态申请权限
35 | PermissionUtils.getInstance().requestPermission(this);
36 | }
37 |
38 | public void click(View view){
39 | switch (view.getId()){
40 | //myselft.db数据库 添加用户
41 | case R.id.add_user:
42 | //建立数据库和表的链接
43 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(UserDao.class,User.class,dbFile,"myselft.db");
44 |
45 | //iBaseDao.insert("insert into tb_user(user_name,user_address,user_psw,user_status,user_id,isMe,myAge,myPhone,aShort) values('鬼刀','六极之地','123456',1,'user_90','true',1.234,457864745,1234)");
46 | //可以使用对象进行封装存入
47 |
48 | //可以使用sql语句进行存储
49 | Short si = 123;
50 | User user = new User("鬼刀","六极之地","123456",0,"user_"+i,true,1.234,457864745l,si);
51 | iBaseDao.insert(user);
52 | i++;
53 |
54 | break;
55 | case R.id.add_file:
56 | //当需要切换表存储的时候,需要重新建立链接
57 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(FileDao.class,FileModel.class,dbFile,"myselft.db");
58 | FileModel fileModel = new FileModel();
59 | fileModel.setFilePath("d/as:/");
60 | fileModel.setFileName("qq.apk");
61 | fileModel.setFileId(123);
62 | iBaseDao.insert(fileModel);
63 | break;
64 | case R.id.add_sqlite_file:
65 | //当需要切换表存储的时候,需要重新建立链接
66 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(FileDao.class,FileModel.class,dbFile,"mydownfile.db");
67 | FileModel fileModel1 = new FileModel();
68 | fileModel1.setFilePath("d/as:/");
69 | fileModel1.setFileName("qq.apk");
70 | fileModel1.setFileId(123);
71 | iBaseDao.insert(fileModel1);
72 | break;
73 | //删除用户
74 | case R.id.delete_user:
75 | //建立数据库和表的链接
76 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(UserDao.class,User.class,dbFile,"myselft.db");
77 |
78 | //使用类对象进行封装删除条件
79 | //User user2 = new User();
80 | //user2.setUser_id("user_0");
81 | //由于手机数据库无法存放布尔值,在寻找条件时,必须对布尔值进行赋值。否则默认是false!
82 | //user2.setMe(true);
83 | //iBaseDao.delete(user2);
84 |
85 | //直接使用sql语句删除
86 | //iBaseDao.delete("delete from tb_user where user_id = 'user_0'");
87 |
88 | //或者使用数组封装条件
89 | iBaseDao.delete("delete from tb_user where user_id = ?",new String[]{"user_0"});
90 | break;
91 | //查询用户
92 | case R.id.query_user:
93 | //建立数据库和表的链接
94 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(UserDao.class,User.class,dbFile,"myselft.db");
95 |
96 | User user1 = new User();
97 | user1.setName("鬼刀");
98 |
99 | //由于手机数据库无法存放布尔值,在寻找条件时,必须对布尔值进行赋值。否则默认是false!
100 | // user1.setMe(true);
101 |
102 | //也可以直接查询 当前条件
103 | List users = iBaseDao.query(user1);
104 |
105 | //可使用表字段来规定排序
106 | //List users = iBaseDao.query(user1,"user_id",0,10);
107 |
108 | //使用字符串qsl查询
109 | //Listusers = iBaseDao.query("select * from tb_user where user_name = '鬼刀'",User.class);
110 |
111 | // 可以用数组装条件
112 | // Listusers = iBaseDao.query("select * from tb_user where user_name = ?",User.class,new String[]{"鬼刀"});
113 |
114 | for (User user3:users) {
115 | Log.i("tag00",user3.toString());
116 | Log.i("tag00","================================");
117 | }
118 | break;
119 | //更新用户
120 | case R.id.update_user:
121 | //建立数据库和表的链接 若是表没有换,那么就不用建立新的链接
122 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(UserDao.class,User.class,dbFile,"myselft.db");
123 |
124 | //更新数据 使用对象进行封装 建议使用这种 非常方便,当然有特殊的需求,就是用sql语句拼接
125 | User newUser = new User();
126 | newUser.setName("天南之剑");
127 | User where = new User();
128 | where.setMe(true);
129 | where.setUser_id("user_1");
130 | iBaseDao.update(newUser,where);
131 |
132 | //用sql语句进行更新
133 | //iBaseDao.update("update tb_user set user_name = '血天使-奥斯丁' where user_name = '天南之剑'");
134 |
135 | //用数组存放条件语句
136 | // iBaseDao.update("update tb_user user_name = '天南之剑' where user_name = '血天使-奥斯丁'");
137 |
138 | break;
139 | }
140 | }
141 |
142 | @Override
143 | protected void onDestroy() {
144 | super.onDestroy();
145 | //最后关闭数据库,避免内存泄露
146 | iBaseDao.close();
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## [我的博客](http://blog.csdn.net/sw5131899/article/details/57415572)
2 |
3 |
4 | 数据库在某些特定需求下是很重要的,像持久化数据,一些不需要实时或者长时间不变的数据,
5 | 可以放在数据库中做缓存,这样就算用户网络不好或者断网的情况下,依然是可以查看一些以前的数据。像新闻或者咨询类。
6 | 这样做是不可避免的。提高用户的体验。谷歌为我们开发者提供了最基础的数据库操作类,
7 | 同时也提供了SqliteDatabase直接创建修改数据库和表。但是只是这样不能满足我们平时的敏捷开发。
8 | 作为一个应用层程序员,很多时候只是想去关心存储和读取数据,数据处理等问题的解决。
9 | 而不是花时间和精力在如何去存,如何去取数据库数据。这就是架构出现的前提。
10 | 将一些面向过程的算法或者业务逻辑封装,可再次调用。易扩展、高灵敏。让程序猿专心的去整理项目需求和逻辑。
11 | 解放大脑,提高工作效率。
12 |
13 | 现在数据库有很多三方框架,比如GreenDao,Afinal、xUtils、ThinkAndroid、volley等等。但是这些三方导入后,文件数太大了。而且很多都集成了网络加载框架,图片加载框架。这样就有了一定的耦合性。比如我只喜欢xUtils的数据库框架,不喜欢它的网络加载,想用Volley的网络加载框架。咋办呢?两个都导入?是的,可以这样,但是项目的文件数就太大了。编译时压力大。而且一些公司想让程序猿写自己的框架,不使用别人发布的框架,这样代码是可以高扩展的。出现什么问题也是可以及时修改。如果导入的三方库在项目成熟阶段出现问题。那是不是要推翻这个库,重新去导入一个,重新在写一遍逻辑,而且又有谁能保证,再次导入的库不会出错呢?
14 |
15 | 我把大致的封装思路,以图片的形式展示出来。
16 |
17 | 
18 |
19 | 对应的UML逻辑图
20 |
21 | 
22 |
23 | 使用起来也非常方便,这里的映射逻辑和GreenDao的底层源码使用的是一个原理。采用表和类属性映射,并对其进行了缓存。只有在切换表的链接时,会重新建立链接。
24 |
25 | 优点:
26 |
27 | 1、支持sql语句自拼接。数据库直接执行sql语句。
28 |
29 | 2、支持传入类对象进行增删改查,比如User,在insert的时候,插入User的实例,属性都封装在user中。通过反射获取它的属性值,存入数据库。
30 |
31 | 3、高扩展,每个新建的存储类型。直接继承DefaultBaseDao即可。可以在这里做一些该类独有的操作。
32 |
33 | 4、支持多数据库切换,多数据库操作。同时支持数据库分库管理,多数据库多版本多用户同时升级,采取XML脚本升级。这里的脚本语句没有封装。
34 |
35 | 5、支持boolean、byte、short、int、long、float、double数据类型的存储和读取。
36 |
37 |
38 |
39 | 使用注意事项:
40 |
41 | 1、创建存储数据类时,需要使用注解去标注类名(表名@DbTable)、类属性(表字段@DbField)。若是有主键(@DbPrimaryField)也需要标注。
42 |
43 | 2、需要创建一个相应的Dao层类和数据库的链接。
44 |
45 |
46 | 使用时导入gandle: compile 'com.singleshu8:LemonDao:1.0.4'
47 |
48 | 创建一个Dao层,这里可以操作数据库,像多数据升级时,这里可以做一些特定处理。对外扩展
49 | ```Java
50 | public class FileDao extends DefaultBaseDao {
51 | }
52 | ```
53 | ```Java
54 | @DbTable(value = "tb_file")
55 | public class FileModel {
56 |
57 | @DbPrimaryField(value = "id")
58 | private int id;
59 | @DbField(value = "tb_filename")
60 | private String fileName;
61 | @DbField(value = "tb_filepath")
62 | private String filePath;
63 | @DbField(value = "tb_fileid")
64 | private int fileId;
65 |
66 | public String getFileName() {
67 | return fileName;
68 | }
69 |
70 | public void setFileName(String fileName) {
71 | this.fileName = fileName;
72 | }
73 |
74 | public String getFilePath() {
75 | return filePath;
76 | }
77 |
78 | public void setFilePath(String filePath) {
79 | this.filePath = filePath;
80 | }
81 |
82 | public int getFileId() {
83 | return fileId;
84 | }
85 |
86 | public void setFileId(int fileId) {
87 | this.fileId = fileId;
88 | }
89 | }
90 | ```
91 | ```Java
92 | @DbTable(value = "tb_user")
93 | public class User {
94 |
95 | @DbPrimaryField(value = "id")
96 | private Integer id;
97 | @DbField(value = "user_name")
98 | private String name;
99 | @DbField(value = "user_address")
100 | private String address;
101 | @DbField(value = "user_psw")
102 | private String psw;
103 | @DbField(value = "user_status")
104 | private Integer status;
105 | @DbField(value = "user_id")
106 | private String user_id;
107 | @DbField(value = "isMe")
108 | private Boolean isMe;
109 | @DbField(value = "myAge")
110 | private Double myAge;
111 | @DbField(value = "myPhone")
112 | private Long myPhone;
113 | @DbField(value = "aShort")
114 | private Short aShort;
115 |
116 | public User(String name, String address, String psw, Integer status, String user_id, Boolean isMe, Double myAge, Long myPhone, Short aShort) {
117 | this.name = name;
118 | this.address = address;
119 | this.psw = psw;
120 | this.status = status;
121 | this.user_id = user_id;
122 | this.isMe = isMe;
123 | this.myAge = myAge;
124 | this.myPhone = myPhone;
125 | this.aShort = aShort;
126 | }
127 |
128 | public User() {
129 | }
130 |
131 | public Integer getId() {
132 | return id;
133 | }
134 |
135 | public void setId(Integer id) {
136 | this.id = id;
137 | }
138 |
139 | public String getName() {
140 | return name;
141 | }
142 |
143 | public void setName(String name) {
144 | this.name = name;
145 | }
146 |
147 | public String getAddress() {
148 | return address;
149 | }
150 |
151 | public void setAddress(String address) {
152 | this.address = address;
153 | }
154 |
155 | public String getPsw() {
156 | return psw;
157 | }
158 |
159 | public void setPsw(String psw) {
160 | this.psw = psw;
161 | }
162 |
163 | public Integer getStatus() {
164 | return status;
165 | }
166 |
167 | public void setStatus(Integer status) {
168 | this.status = status;
169 | }
170 |
171 | public String getUser_id() {
172 | return user_id;
173 | }
174 |
175 | public void setUser_id(String user_id) {
176 | this.user_id = user_id;
177 | }
178 |
179 | public Boolean getMe() {
180 | return isMe;
181 | }
182 |
183 | public void setMe(Boolean me) {
184 | isMe = me;
185 | }
186 |
187 | public Double getMyAge() {
188 | return myAge;
189 | }
190 |
191 | public void setMyAge(Double myAge) {
192 | this.myAge = myAge;
193 | }
194 |
195 | public Long getMyPhone() {
196 | return myPhone;
197 | }
198 |
199 | public void setMyPhone(Long myPhone) {
200 | this.myPhone = myPhone;
201 | }
202 |
203 | public Short getaShort() {
204 | return aShort;
205 | }
206 |
207 | public void setaShort(Short aShort) {
208 | this.aShort = aShort;
209 | }
210 |
211 | @Override
212 | public String toString() {
213 | return "User{" +
214 | "id=" + id +
215 | ", name='" + name + '\'' +
216 | ", address='" + address + '\'' +
217 | ", psw='" + psw + '\'' +
218 | ", status=" + status +
219 | ", user_id='" + user_id + '\'' +
220 | ", isMe=" + isMe +
221 | ", myAge=" + myAge +
222 | ", myPhone=" + myPhone +
223 | ", aShort=" + aShort +
224 | '}';
225 | }
226 | }
227 | ```
228 | ```Java
229 | public class UserDao extends DefaultBaseDao {
230 |
231 |
232 | // @Override
233 | // public Long insert(User entity) {
234 | // List list=query(new User());
235 | // User where = null;
236 | // for (User user:list)
237 | // {
238 | // where =new User();
239 | // where.setUser_id(user.getUser_id());
240 | // user.setStatus(0);
241 | // Log.i(TAG,"用户"+user.getName()+"更改为未登录状态");
242 | // update(user,where);
243 | // }
244 | // Log.i(TAG,"用户"+entity.getName()+"登录");
245 | // entity.setStatus(1);
246 | // return super.insert(entity);
247 | // }
248 |
249 |
250 | /**
251 | * 得到当前登录的User
252 | * @return
253 | */
254 | public User getCurrentUser() {
255 | User user=new User();
256 | user.setStatus(1);
257 | List list=query(user);
258 | if(list.size()>0)
259 | {
260 | return list.get(0);
261 | }
262 | return null;
263 | }
264 | }
265 | ```
266 | 具体使用
267 | ```Java
268 | public class MainActivity extends AppCompatActivity {
269 |
270 | private IBaseDao iBaseDao;
271 |
272 | String dbFile;
273 | int i = 0;
274 |
275 | @Override
276 | protected void onCreate(Bundle savedInstanceState) {
277 | super.onCreate(savedInstanceState);
278 | setContentView(R.layout.activity_main);
279 | //数据库地址 文件夹
280 | dbFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myDb";
281 | //6.0以上动态申请权限
282 | PermissionUtils.getInstance().requestPermission(this);
283 | }
284 |
285 | public void click(View view){
286 | switch (view.getId()){
287 | //myselft.db数据库 添加用户
288 | case R.id.add_user:
289 | //建立数据库和表的链接
290 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(UserDao.class,User.class,dbFile,"myselft.db");
291 |
292 | //iBaseDao.insert("insert into tb_user(user_name,user_address,user_psw,user_status,user_id,isMe,myAge,myPhone,aShort) values('鬼刀','六极之地','123456',1,'user_90','true',1.234,457864745,1234)");
293 | //可以使用对象进行封装存入
294 |
295 | //可以使用sql语句进行存储
296 | Short si = 123;
297 | User user = new User("鬼刀","六极之地","123456",0,"user_"+i,true,1.234,457864745l,si);
298 | iBaseDao.insert(user);
299 | i++;
300 |
301 | break;
302 | case R.id.add_file:
303 | //当需要切换表存储的时候,需要重新建立链接
304 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(FileDao.class,FileModel.class,dbFile,"myselft.db");
305 | FileModel fileModel = new FileModel();
306 | fileModel.setFilePath("d/as:/");
307 | fileModel.setFileName("qq.apk");
308 | fileModel.setFileId(123);
309 | iBaseDao.insert(fileModel);
310 | break;
311 | case R.id.add_sqlite_file:
312 | //当需要切换表存储的时候,需要重新建立链接
313 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(FileDao.class,FileModel.class,dbFile,"mydownfile.db");
314 | FileModel fileModel1 = new FileModel();
315 | fileModel1.setFilePath("d/as:/");
316 | fileModel1.setFileName("qq.apk");
317 | fileModel1.setFileId(123);
318 | iBaseDao.insert(fileModel1);
319 | break;
320 | //删除用户
321 | case R.id.delete_user:
322 | //建立数据库和表的链接
323 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(UserDao.class,User.class,dbFile,"myselft.db");
324 |
325 | //使用类对象进行封装删除条件
326 | //User user2 = new User();
327 | //user2.setUser_id("user_0");
328 | //由于手机数据库无法存放布尔值,在寻找条件时,必须对布尔值进行赋值。否则默认是false!
329 | //user2.setMe(true);
330 | //iBaseDao.delete(user2);
331 |
332 | //直接使用sql语句删除
333 | //iBaseDao.delete("delete from tb_user where user_id = 'user_0'");
334 |
335 | //或者使用数组封装条件
336 | iBaseDao.delete("delete from tb_user where user_id = ?",new String[]{"user_0"});
337 | break;
338 | //查询用户
339 | case R.id.query_user:
340 | //建立数据库和表的链接
341 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(UserDao.class,User.class,dbFile,"myselft.db");
342 |
343 | User user1 = new User();
344 | user1.setName("鬼刀");
345 |
346 | //由于手机数据库无法存放布尔值,在寻找条件时,必须对布尔值进行赋值。否则默认是false!
347 | // user1.setMe(true);
348 |
349 | //也可以直接查询 当前条件
350 | List users = iBaseDao.query(user1);
351 |
352 | //可使用表字段来规定排序
353 | //List users = iBaseDao.query(user1,"user_id",0,10);
354 |
355 | //使用字符串qsl查询
356 | //Listusers = iBaseDao.query("select * from tb_user where user_name = '鬼刀'",User.class);
357 |
358 | // 可以用数组装条件
359 | // Listusers = iBaseDao.query("select * from tb_user where user_name = ?",User.class,new String[]{"鬼刀"});
360 |
361 | for (User user3:users) {
362 | Log.i("tag00",user3.toString());
363 | Log.i("tag00","================================");
364 | }
365 | break;
366 | //更新用户
367 | case R.id.update_user:
368 | //建立数据库和表的链接 若是表没有换,那么就不用建立新的链接
369 | iBaseDao = BaseDaoFactory.getInstance().getSqliteComponent(UserDao.class,User.class,dbFile,"myselft.db");
370 |
371 | //更新数据 使用对象进行封装 建议使用这种 非常方便,当然有特殊的需求,就是用sql语句拼接
372 | User newUser = new User();
373 | newUser.setName("天南之剑");
374 | User where = new User();
375 | where.setMe(true);
376 | where.setUser_id("user_1");
377 | iBaseDao.update(newUser,where);
378 |
379 | //用sql语句进行更新
380 | //iBaseDao.update("update tb_user set user_name = '血天使-奥斯丁' where user_name = '天南之剑'");
381 |
382 | //用数组存放条件语句
383 | // iBaseDao.update("update tb_user user_name = '天南之剑' where user_name = '血天使-奥斯丁'");
384 |
385 | break;
386 | }
387 | }
388 |
389 | @Override
390 | protected void onDestroy() {
391 | super.onDestroy();
392 | //最后关闭数据库,避免内存泄露
393 | iBaseDao.close();
394 | }
395 | }
396 | ```
397 | 有关于数据库分库和多版本多用户脚本升级,这个在小项目用的很少。小项目一般是几张表就搞定了。查询是加个userId,但是当
398 | 数据量过大时,这样做会很难受。数据库升级在表少的时候,可以直接拼接字符串。但是当表多了之后,这样做无疑是不正确的。
399 | 若是对数据库分库和多版本多用户升级感兴趣的朋友。可以联系我,794918578@qq.com;
400 |
401 | #觉得有用的朋友请给个star,谢谢
402 |
403 |
404 |
405 |
406 |
--------------------------------------------------------------------------------