diff --git a/daogenerator/.gitignore b/daogenerator/.gitignore new file mode 100644 index 000000000..a0cc187d4 --- /dev/null +++ b/daogenerator/.gitignore @@ -0,0 +1,4 @@ +/build + +# Intellij +*.iml diff --git a/daogenerator/build.gradle b/daogenerator/build.gradle new file mode 100644 index 000000000..95d9a7c8a --- /dev/null +++ b/daogenerator/build.gradle @@ -0,0 +1,22 @@ +/* + * Copyright 2015 Hippo Seven + * + * 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. + */ + +apply plugin: 'java' + +dependencies { + compile('de.greenrobot:greendao-generator:1.3.1') + compile fileTree(dir: 'libs', include: ['*.jar']) +} diff --git a/daogenerator/src/main/java/com/hippo/ehviewer/EhDaoGenerator.java b/daogenerator/src/main/java/com/hippo/ehviewer/EhDaoGenerator.java new file mode 100644 index 000000000..ea56d778e --- /dev/null +++ b/daogenerator/src/main/java/com/hippo/ehviewer/EhDaoGenerator.java @@ -0,0 +1,74 @@ +/* + * Copyright 2015 Hippo Seven + * + * 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 com.hippo.ehviewer; + +import java.io.File; + +import de.greenrobot.daogenerator.DaoGenerator; +import de.greenrobot.daogenerator.Entity; +import de.greenrobot.daogenerator.Schema; + +public class EhDaoGenerator { + + private static final String PACKAGE = "com.hippo.ehviewer.dao"; + private static final String OUT_DIR = "./app/src/main/java-gen"; + + public static void main(String args[]) throws Exception { + File outDir = new File(OUT_DIR); + Utilities.deleteContents(outDir); + outDir.delete(); + outDir.mkdirs(); + + Schema schema = new Schema(1, PACKAGE); + addGalleryBase(schema); + addDownloadInfo(schema); + addSpider(schema); + new DaoGenerator().generateAll(schema, OUT_DIR); + } + + public static void addGalleryBase(Schema schema) { + Entity galleryBase = schema.addEntity("GalleryBaseObj"); + galleryBase.setTableName("GALLERY_BASE"); + galleryBase.addLongProperty("gid").primaryKey(); + galleryBase.addStringProperty("token"); + galleryBase.addStringProperty("title"); + galleryBase.addStringProperty("titleJpn"); + galleryBase.addStringProperty("thumb"); + galleryBase.addIntProperty("category"); + galleryBase.addStringProperty("posted"); + galleryBase.addStringProperty("uploader"); + galleryBase.addFloatProperty("rating"); + galleryBase.addIntProperty("reference"); + } + + public static void addDownloadInfo(Schema schema) { + Entity downloadInfo = schema.addEntity("DownloadInfoObj"); + downloadInfo.setTableName("DOWNLOAD_INFO"); + downloadInfo.addLongProperty("gid").primaryKey(); + downloadInfo.addIntProperty("state"); + } + + public static void addSpider(Schema schema) { + Entity spider = schema.addEntity("SpiderObj"); + spider.setTableName("SPIDER"); + spider.addLongProperty("gid").primaryKey(); + spider.addIntProperty("lastIndex"); + spider.addStringProperty("dirname"); + spider.addBooleanProperty("download"); + spider.addLongProperty("time"); + } +} diff --git a/daogenerator/src/main/java/com/hippo/ehviewer/Utilities.java b/daogenerator/src/main/java/com/hippo/ehviewer/Utilities.java new file mode 100644 index 000000000..2f4b10124 --- /dev/null +++ b/daogenerator/src/main/java/com/hippo/ehviewer/Utilities.java @@ -0,0 +1,38 @@ +/* + * Copyright 2015 Hippo Seven + * + * 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 com.hippo.ehviewer; + +import java.io.File; + +public final class Utilities { + + public static boolean deleteContents(File dir) { + File[] files = dir.listFiles(); + boolean success = true; + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + success &= deleteContents(file); + } + if (!file.delete()) { + success = false; + } + } + } + return success; + } +}