1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-23 02:16:48 +01:00

Work towards using greenDAO #206

This commit is contained in:
cpfeiffer 2016-03-27 22:13:06 +02:00
parent 8815f0d134
commit 3513a902ae
5 changed files with 149 additions and 1 deletions

2
GBDaoGenerator/.gitignore vendored Normal file
View File

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

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
}

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;
}
}

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'

View File

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