From a13b6ce4ddaa225b8aa7c0b12dc8739456736ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artjom=20Ko=CC=88nig?= Date: Wed, 29 Mar 2017 15:02:55 +0200 Subject: [PATCH] =?UTF-8?q?support=20for=20=E2=80=9EON=20DELETE=20CASCADE?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schematic/annotation/References.java | 2 +- .../schematic/compiler/TableWriter.java | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/schematic-annotations/src/main/java/net/simonvt/schematic/annotation/References.java b/schematic-annotations/src/main/java/net/simonvt/schematic/annotation/References.java index 129d6ed..2f3e1e6 100644 --- a/schematic-annotations/src/main/java/net/simonvt/schematic/annotation/References.java +++ b/schematic-annotations/src/main/java/net/simonvt/schematic/annotation/References.java @@ -32,6 +32,6 @@ @Retention(CLASS) @Target(FIELD) public @interface References { String table(); - String column(); + boolean onDeleteCascade() default false; } diff --git a/schematic-compiler/src/main/java/net/simonvt/schematic/compiler/TableWriter.java b/schematic-compiler/src/main/java/net/simonvt/schematic/compiler/TableWriter.java index 45171fa..1ac2885 100644 --- a/schematic-compiler/src/main/java/net/simonvt/schematic/compiler/TableWriter.java +++ b/schematic-compiler/src/main/java/net/simonvt/schematic/compiler/TableWriter.java @@ -22,12 +22,30 @@ import com.squareup.javapoet.JavaFile; import com.squareup.javapoet.MethodSpec; import com.squareup.javapoet.TypeSpec; + +import net.simonvt.schematic.annotation.AutoIncrement; +import net.simonvt.schematic.annotation.Check; +import net.simonvt.schematic.annotation.ConflictResolutionType; +import net.simonvt.schematic.annotation.Constraints; +import net.simonvt.schematic.annotation.DataType; +import net.simonvt.schematic.annotation.DefaultValue; +import net.simonvt.schematic.annotation.ForeignKeyConstraint; +import net.simonvt.schematic.annotation.IfNotExists; +import net.simonvt.schematic.annotation.NotNull; +import net.simonvt.schematic.annotation.PrimaryKey; +import net.simonvt.schematic.annotation.PrimaryKeyConstraint; +import net.simonvt.schematic.annotation.References; +import net.simonvt.schematic.annotation.Table; +import net.simonvt.schematic.annotation.Unique; +import net.simonvt.schematic.annotation.UniqueConstraint; + import java.io.IOException; import java.io.Writer; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import javax.annotation.processing.Filer; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.Element; @@ -38,21 +56,6 @@ import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic.Kind; import javax.tools.JavaFileObject; -import net.simonvt.schematic.annotation.AutoIncrement; -import net.simonvt.schematic.annotation.Check; -import net.simonvt.schematic.annotation.ConflictResolutionType; -import net.simonvt.schematic.annotation.Constraints; -import net.simonvt.schematic.annotation.DataType; -import net.simonvt.schematic.annotation.DefaultValue; -import net.simonvt.schematic.annotation.ForeignKeyConstraint; -import net.simonvt.schematic.annotation.IfNotExists; -import net.simonvt.schematic.annotation.NotNull; -import net.simonvt.schematic.annotation.PrimaryKey; -import net.simonvt.schematic.annotation.PrimaryKeyConstraint; -import net.simonvt.schematic.annotation.References; -import net.simonvt.schematic.annotation.Table; -import net.simonvt.schematic.annotation.Unique; -import net.simonvt.schematic.annotation.UniqueConstraint; public class TableWriter { @@ -251,6 +254,10 @@ public void createTable(TypeSpec.Builder databaseBuilder) .append("(") .append(references.column()) .append(")"); + + if(references.onDeleteCascade()) { + query.append(" ON DELETE CASCADE"); + } } }