Browse Source

Work towards using greenDAO #206

tags/0.12.2
cpfeiffer 3 years ago
parent
commit
3513a902ae
5 changed files with 149 additions and 1 deletions
  1. +2
    -0
      GBDaoGenerator/.gitignore
  2. +28
    -0
      GBDaoGenerator/build.gradle
  3. +112
    -0
      GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java
  4. +6
    -0
      app/build.gradle
  5. +1
    -1
      settings.gradle

+ 2
- 0
GBDaoGenerator/.gitignore View File

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

+ 28
- 0
GBDaoGenerator/build.gradle View File

@@ -0,0 +1,28 @@
apply plugin: 'java'
//apply plugin: 'maven'
apply plugin:'application'

archivesBaseName = 'gadgetbridge-daogenerator'
//version = '0.9.2-SNAPSHOT'

dependencies {
compile 'de.greenrobot:greendao-generator:2.1.0'
}

sourceSets {
main {
java {
srcDir 'src'
srcDir 'src-gen'
}
}
}

task (genSources, type: JavaExec) {
main = "nodomain.freeyourgadget.gadgetbridge.daogen.GBDaoGenerator"
classpath = sourceSets.main.runtimeClasspath
}

artifacts {
archives jar
}

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

@@ -0,0 +1,112 @@
/*
* Copyright (C) 2011 Markus Junginger, greenrobot (http://greenrobot.de)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nodomain.freeyourgadget.gadgetbridge.daogen;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;

/**
* Generates entities and DAOs for the example project DaoExample.
* Automatically run during build.
*/
public class GBDaoGenerator {

public static final String VALID_FROM_UTC = "validFromUTC";
public static final String VALID_TO_UTC = "validToUTC";

public static void main(String[] args) throws Exception {
Schema schema = new Schema(7, "nodomain.freeyourgadget.gadgetbridge.entities");

Entity userAttributes = addUserAttributes(schema);
Entity user = addUserInfo(schema, userAttributes);

Entity deviceAttributes = addDeviceAttributes(schema);
Entity device = addDevice(schema, deviceAttributes);

addActivitySample(schema, user, device);

new DaoGenerator().generateAll(schema, "../app/src/main/gen");
}

private static Entity addUserInfo(Schema schema, Entity userAttributes) {
Entity user = schema.addEntity("User");
user.addIdProperty();
user.addStringProperty("name").notNull();
user.addDateProperty("birthday").notNull();
user.addIntProperty("sex").notNull();
Property userId = userAttributes.addLongProperty("userId").notNull().getProperty();
user.addToMany(userAttributes, userId);

return user;
}

private static Entity addUserAttributes(Schema schema) {
// additional properties of a user, which may change during the lifetime of a user
// this allows changing attributes while preserving user identity
Entity userAttributes = schema.addEntity("UserAttributes");
userAttributes.addIdProperty();
userAttributes.addIntProperty("heightCM").notNull();
userAttributes.addIntProperty("weightKG").notNull();
userAttributes.addIntProperty("sleepGoalHPD");
userAttributes.addIntProperty("stepsGoalSPD");
userAttributes.addDateProperty(VALID_FROM_UTC);
userAttributes.addDateProperty(VALID_TO_UTC);

return userAttributes;
}

private static Entity addDevice(Schema schema, Entity deviceAttributes) {
Entity device = schema.addEntity("Device");
device.addIdProperty();
device.addStringProperty("name").notNull();
device.addStringProperty("manufacturer").notNull();
device.addStringProperty("identifier").notNull().javaDocGetterAndSetter("The fixed identifier, i.e. MAC address of the device.");
Property deviceId = deviceAttributes.addLongProperty("deviceId").notNull().getProperty();
device.addToMany(deviceAttributes, deviceId);

return device;
}

private static Entity addDeviceAttributes(Schema schema) {
Entity deviceAttributes = schema.addEntity("DeviceAttributes");
deviceAttributes.addIdProperty();
deviceAttributes.addStringProperty("firmwareVersion1").notNull();
deviceAttributes.addStringProperty("firmwareVersion2");
deviceAttributes.addDateProperty(VALID_FROM_UTC);
deviceAttributes.addDateProperty(VALID_TO_UTC);

return deviceAttributes;
}

private static Entity addActivitySample(Schema schema, Entity user, Entity device) {
// public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type, int customValue) {
Entity activitySample = schema.addEntity("ActivitySample");
activitySample.addIdProperty();
activitySample.addIntProperty("timestamp").notNull();
activitySample.addIntProperty("intensity").notNull();
activitySample.addIntProperty("steps").notNull();
activitySample.addIntProperty("type").notNull();
activitySample.addIntProperty("customValue").notNull();
Property userId = activitySample.addLongProperty("userId").getProperty();
activitySample.addToOne(user, userId);
Property deviceId = activitySample.addLongProperty("deviceId").getProperty();
activitySample.addToOne(device, deviceId);

return activitySample;
}
}

+ 6
- 0
app/build.gradle View File

@@ -53,6 +53,12 @@ dependencies {
compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'
compile 'com.github.pfichtner:durationformatter:0.1.1'
compile 'de.cketti.library.changelog:ckchangelog:1.2.2'
compile 'de.greenrobot:greendao:2.1.0'
}

preBuild.dependsOn(":GBDaoGenerator:genSources")
gradle.beforeProject {
preBuild.dependsOn(":GBDaoGenerator:genSources")
}

check.dependsOn 'findbugs', 'pmd', 'lint'

+ 1
- 1
settings.gradle View File

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

Loading…
Cancel
Save