Free as in Freedom: Codeberg.org. Create your repos!
Browse Source

Work towards using greenDAO #206

tags/0.12.2
cpfeiffer 3 years ago
parent
commit
3513a902ae

+ 2
- 0
GBDaoGenerator/.gitignore View File

@@ -0,0 +1,2 @@
1
+/bin
2
+/build

+ 28
- 0
GBDaoGenerator/build.gradle View File

@@ -0,0 +1,28 @@
1
+apply plugin: 'java'
2
+//apply plugin: 'maven'
3
+apply plugin:'application'
4
+
5
+archivesBaseName = 'gadgetbridge-daogenerator'
6
+//version = '0.9.2-SNAPSHOT'
7
+
8
+dependencies {
9
+    compile 'de.greenrobot:greendao-generator:2.1.0'
10
+}
11
+
12
+sourceSets {
13
+    main {
14
+        java {
15
+            srcDir 'src'
16
+            srcDir 'src-gen'
17
+        }
18
+    }
19
+}
20
+
21
+task (genSources, type: JavaExec) {
22
+    main = "nodomain.freeyourgadget.gadgetbridge.daogen.GBDaoGenerator"
23
+    classpath = sourceSets.main.runtimeClasspath
24
+}
25
+
26
+artifacts {
27
+    archives jar
28
+}

+ 112
- 0
GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java View File

@@ -0,0 +1,112 @@
1
+/*
2
+ * Copyright (C) 2011 Markus Junginger, greenrobot (http://greenrobot.de)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *      http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package nodomain.freeyourgadget.gadgetbridge.daogen;
17
+
18
+import de.greenrobot.daogenerator.DaoGenerator;
19
+import de.greenrobot.daogenerator.Entity;
20
+import de.greenrobot.daogenerator.Property;
21
+import de.greenrobot.daogenerator.Schema;
22
+
23
+/**
24
+ * Generates entities and DAOs for the example project DaoExample.
25
+ * Automatically run during build.
26
+ */
27
+public class GBDaoGenerator {
28
+
29
+    public static final String VALID_FROM_UTC = "validFromUTC";
30
+    public static final String VALID_TO_UTC = "validToUTC";
31
+
32
+    public static void main(String[] args) throws Exception {
33
+        Schema schema = new Schema(7, "nodomain.freeyourgadget.gadgetbridge.entities");
34
+
35
+        Entity userAttributes = addUserAttributes(schema);
36
+        Entity user = addUserInfo(schema, userAttributes);
37
+
38
+        Entity deviceAttributes = addDeviceAttributes(schema);
39
+        Entity device = addDevice(schema, deviceAttributes);
40
+
41
+        addActivitySample(schema, user, device);
42
+
43
+        new DaoGenerator().generateAll(schema, "../app/src/main/gen");
44
+    }
45
+
46
+    private static Entity addUserInfo(Schema schema, Entity userAttributes) {
47
+        Entity user = schema.addEntity("User");
48
+        user.addIdProperty();
49
+        user.addStringProperty("name").notNull();
50
+        user.addDateProperty("birthday").notNull();
51
+        user.addIntProperty("sex").notNull();
52
+        Property userId = userAttributes.addLongProperty("userId").notNull().getProperty();
53
+        user.addToMany(userAttributes, userId);
54
+
55
+        return user;
56
+    }
57
+
58
+    private static Entity addUserAttributes(Schema schema) {
59
+        // additional properties of a user, which may change during the lifetime of a user
60
+        // this allows changing attributes while preserving user identity
61
+        Entity userAttributes = schema.addEntity("UserAttributes");
62
+        userAttributes.addIdProperty();
63
+        userAttributes.addIntProperty("heightCM").notNull();
64
+        userAttributes.addIntProperty("weightKG").notNull();
65
+        userAttributes.addIntProperty("sleepGoalHPD");
66
+        userAttributes.addIntProperty("stepsGoalSPD");
67
+        userAttributes.addDateProperty(VALID_FROM_UTC);
68
+        userAttributes.addDateProperty(VALID_TO_UTC);
69
+
70
+        return userAttributes;
71
+    }
72
+
73
+    private static Entity addDevice(Schema schema, Entity deviceAttributes) {
74
+        Entity device = schema.addEntity("Device");
75
+        device.addIdProperty();
76
+        device.addStringProperty("name").notNull();
77
+        device.addStringProperty("manufacturer").notNull();
78
+        device.addStringProperty("identifier").notNull().javaDocGetterAndSetter("The fixed identifier, i.e. MAC address of the device.");
79
+        Property deviceId = deviceAttributes.addLongProperty("deviceId").notNull().getProperty();
80
+        device.addToMany(deviceAttributes, deviceId);
81
+
82
+        return device;
83
+    }
84
+
85
+    private static Entity addDeviceAttributes(Schema schema) {
86
+        Entity deviceAttributes = schema.addEntity("DeviceAttributes");
87
+        deviceAttributes.addIdProperty();
88
+        deviceAttributes.addStringProperty("firmwareVersion1").notNull();
89
+        deviceAttributes.addStringProperty("firmwareVersion2");
90
+        deviceAttributes.addDateProperty(VALID_FROM_UTC);
91
+        deviceAttributes.addDateProperty(VALID_TO_UTC);
92
+
93
+        return deviceAttributes;
94
+    }
95
+
96
+    private static Entity addActivitySample(Schema schema, Entity user, Entity device) {
97
+//        public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type, int customValue) {
98
+        Entity activitySample = schema.addEntity("ActivitySample");
99
+        activitySample.addIdProperty();
100
+        activitySample.addIntProperty("timestamp").notNull();
101
+        activitySample.addIntProperty("intensity").notNull();
102
+        activitySample.addIntProperty("steps").notNull();
103
+        activitySample.addIntProperty("type").notNull();
104
+        activitySample.addIntProperty("customValue").notNull();
105
+        Property userId = activitySample.addLongProperty("userId").getProperty();
106
+        activitySample.addToOne(user, userId);
107
+        Property deviceId = activitySample.addLongProperty("deviceId").getProperty();
108
+        activitySample.addToOne(device, deviceId);
109
+
110
+        return activitySample;
111
+    }
112
+}

+ 6
- 0
app/build.gradle View File

@@ -53,6 +53,12 @@ dependencies {
53 53
     compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'
54 54
     compile 'com.github.pfichtner:durationformatter:0.1.1'
55 55
     compile 'de.cketti.library.changelog:ckchangelog:1.2.2'
56
+    compile 'de.greenrobot:greendao:2.1.0'
57
+}
58
+
59
+preBuild.dependsOn(":GBDaoGenerator:genSources")
60
+gradle.beforeProject {
61
+    preBuild.dependsOn(":GBDaoGenerator:genSources")
56 62
 }
57 63
 
58 64
 check.dependsOn 'findbugs', 'pmd', 'lint'

+ 1
- 1
settings.gradle View File

@@ -1 +1 @@
1
-include ':app'
1
+include ':app', ':GBDaoGenerator'

Loading…
Cancel
Save