Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added initial support for Composite Foreign Keys and Indexes #19

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ preprocessor/target
common/target
build
*.keystore
*.~*
projectBackupFiles
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ annotations and CRUD classes expose an expressive api for executing SQLite queri
preprocessors on Android.*
```groovy
dependencies {
apt 'com.memtrip.sqlking:preprocessor:1.1.5'
compile 'com.memtrip.sqlking:client:1.1.5'
apt 'com.memtrip.sqlking:preprocessor:1.1.6'
compile 'com.memtrip.sqlking:client:1.1.6'
}
```

Expand Down
8 changes: 4 additions & 4 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ext {
siteUrl = 'https://github.com/memtrip/SQLKing'
gitUrl = 'https://github.com/memtrip/SQLKing.git'

libraryVersion = '1.1.5'
libraryVersion = '1.1.6'

developerId = 'samkirton'
developerName = 'Samuel Kirton'
Expand All @@ -44,7 +44,7 @@ android {
minSdkVersion 11
targetSdkVersion 24
versionCode 7
versionName "1.1.1"
versionName "1.1.6"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -137,11 +137,11 @@ install {
}

dependencies {
compile 'com.memtrip.sqlking:common:1.1.5'
compile 'com.memtrip.sqlking:common:1.1.6'
compile 'io.reactivex:rxjava:1.1.1'
compile 'io.reactivex:rxandroid:1.1.0'

androidTestApt 'com.memtrip.sqlking:preprocessor:1.1.5'
androidTestApt 'com.memtrip.sqlking:preprocessor:1.1.6'

androidTestCompile(
'com.android.support.test:runner:0.3',
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.memtrip.sqlking</groupId>
<artifactId>common</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>

<name>SQLKing common</name>
<description>
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/java/com/memtrip/sqlking/common/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
* @author Samuel Kirton [sam@memtrip.com]
*/
public @interface Column {
boolean index() default false;
boolean primary_key() default false;
boolean auto_increment() default false;
boolean index() default false;
boolean not_null() default false;
}
11 changes: 7 additions & 4 deletions common/src/main/java/com/memtrip/sqlking/common/ForeignKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
* @author Samuel Kirton [sam@memtrip.com]
*/
@SuppressWarnings("WeakerAccess")
public @interface ForeignKey {
String targetTable() default "";
String targetColumn() default "";
String localColumn() default "";
public @interface ForeignKey
{
String foreignTableName ();
String[] foreignColumnNames ();
String[] localColumnNames ();
RIRule updateRule () default RIRule.Restrict;
RIRule deleteRule () default RIRule.Restrict;
}
24 changes: 24 additions & 0 deletions common/src/main/java/com/memtrip/sqlking/common/ForeignKeys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2013-present memtrip LTD.
*
* 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.memtrip.sqlking.common;

/**
* @author Adrian Velcich [adrian@higration.co.za] - 2016-09-16 - Added Composite Foreign Key support
*/

public @interface ForeignKeys {
ForeignKey[] foreignKeys();
}
28 changes: 28 additions & 0 deletions common/src/main/java/com/memtrip/sqlking/common/Index.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2013-present memtrip LTD.
*
* 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.memtrip.sqlking.common;

/**
* @author Adrian Velcich [adrian@higration.co.za] - 2016-09-16 - Added Composite and Unique Index support
*/

import com.memtrip.sqlking.common.IndexColumn;

public @interface Index {
String indexName();
boolean unique() default false;
IndexColumn[] columns() default {};
}
28 changes: 28 additions & 0 deletions common/src/main/java/com/memtrip/sqlking/common/IndexColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2013-present memtrip LTD.
*
* 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.memtrip.sqlking.common;

import java.lang.annotation.Repeatable;

/**
* @author Adrian Velcich [adrian@higration.co.za] - 2016-09-16 - Added Composite and Unique Index support
*/

@SuppressWarnings("WeakerAccess")
public @interface IndexColumn {
String column();
SortOrder sortOrder() default SortOrder.ASC;
}
24 changes: 24 additions & 0 deletions common/src/main/java/com/memtrip/sqlking/common/RIRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.memtrip.sqlking.common;

public enum RIRule
{
SetNull ("SET NULL"),
SetDefault ("SET DEFAULT"),
Cascade ("CASCADE"),
Restrict ("RESTRICT"),
NotNull ("NOT NULL"),
NoAction ("NO ACTION");

private final String name;
public final static RIRule values[] = values();

RIRule (String name)
{
this.name = name;
}

public String getName()
{
return this.name;
}
};
16 changes: 16 additions & 0 deletions common/src/main/java/com/memtrip/sqlking/common/SortOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Author: A.Velcich
*/

package com.memtrip.sqlking.common;

public enum SortOrder
{
ASC ("ASC"),
DESC ("DESC");

private final String text;

SortOrder (String newVal) { text = newVal; }
public final static SortOrder values[] = values();
}
1 change: 1 addition & 0 deletions common/src/main/java/com/memtrip/sqlking/common/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
*/
public @interface Table {
ForeignKey[] foreignKeys() default {};
Index[] indexes() default {};
}
4 changes: 2 additions & 2 deletions preprocessor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.memtrip.sqlking</groupId>
<artifactId>preprocessor</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>

<name>SQLKing preprocessor</name>
<description>
Expand Down Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>com.memtrip.sqlking</groupId>
<artifactId>common</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.google.googlejavaformat.java.FormatterException;
import com.memtrip.sqlking.common.Column;
import com.memtrip.sqlking.common.Table;
import com.memtrip.sqlking.common.Index;
import com.memtrip.sqlking.common.IndexColumn;
import com.memtrip.sqlking.common.ForeignKey;
import com.memtrip.sqlking.preprocessor.processor.data.Data;
import com.memtrip.sqlking.preprocessor.processor.data.parse.ParseAnnotations;
import com.memtrip.sqlking.preprocessor.processor.data.validator.MembersHaveGetterSettersValidator;
Expand Down Expand Up @@ -36,7 +39,7 @@ public synchronized void init(ProcessingEnvironment env) {
}

@Override
public boolean process(Set<? extends TypeElement> annoations, RoundEnvironment env) {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {
Set<? extends Element> elements = env.getElementsAnnotatedWith(Table.class);

if (elements != null && elements.size() > 0) {
Expand Down Expand Up @@ -82,6 +85,9 @@ public Set<String> getSupportedAnnotationTypes() {
Set<String> set = new HashSet<>();
set.add(Table.class.getCanonicalName());
set.add(Column.class.getCanonicalName());
set.add(Index.class.getCanonicalName());
set.add(IndexColumn.class.getCanonicalName());
set.add(ForeignKey.class.getCanonicalName());
return set;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Column {
private String mClassName;
private String mType;
private boolean mIsIndex;
private boolean mIsNotNull;
private boolean mPrimaryKey;
private boolean mHasAutoIncrement;

Expand Down Expand Up @@ -45,6 +46,14 @@ public void setIsIndex(boolean newVal) {
mIsIndex = newVal;
}

public boolean isNotNull ()
{
return mIsNotNull;
}
public void setNotNull (boolean newVal)
{
this.mIsNotNull = newVal;
}
public boolean hasPrimaryKey() {
return mPrimaryKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public class Data {
private List<Table> mTables;
private List<Index> mIndexes;
private List<ForeignKey> mForeignKeys;

public List<Table> getTables() {
return mTables;
Expand All @@ -12,4 +14,14 @@ public List<Table> getTables() {
public void setTables(List<Table> newVal) {
mTables = newVal;
}
public List<Index> getIndexes() { return mIndexes; }
public void setIndexes(List<Index> newVal) { mIndexes = newVal; }
public List<ForeignKey> getForeignKeys ()
{
return mForeignKeys;
}
public void setForeignKeys (List<ForeignKey> newVal)
{
this.mForeignKeys = newVal;
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
package com.memtrip.sqlking.preprocessor.processor.data;

public class ForeignKey {
private String mTable;
private String mThisColumn;
private String mForeignColumn;
import java.util.List;
import com.memtrip.sqlking.common.RIRule;
import com.memtrip.sqlking.preprocessor.processor.utils.StringUtils;
public class ForeignKey
{
private String mForeignTableName;
private List<String> mLocalColumnNames;
private List<String> mForeignColumnNames;
private RIRule mRIUpdateRule;
private RIRule mRIDeleteRule;

public String getTable() {
return mTable;
public String getForeignTableName() {
return mForeignTableName;
}

public void setTable(String newVal) {
mTable = newVal;
public void setForeignTableName(String newVal) {
mForeignTableName = newVal;
}

public String getThisColumn() {
return mThisColumn;
public List<String> getLocalColumnNames() { return mLocalColumnNames; }
public void setLocalColumnNames(List<String> newVal) { mLocalColumnNames = newVal; }
public List<String> getForeignColumnNames() { return mForeignColumnNames; }
public void setForeignColumnNames(List<String> newVals) {
mForeignColumnNames = newVals;
}

public void setLocalColumn(String newVal) {
mThisColumn = newVal;
public RIRule getRIUpdateRule ()
{
return mRIUpdateRule;
}
public void setRIUpdateRule (RIRule newVal)
{
this.mRIUpdateRule = newVal;
}

public String getForeignColumn() {
return mForeignColumn;
public RIRule getRIDeleteRule ()
{
return mRIDeleteRule;
}

public void setTargetColumn(String newVal) {
mForeignColumn = newVal;
public void setRIDeleteRule (RIRule newVal)
{
this.mRIDeleteRule = newVal;
}
}
Loading