-
Notifications
You must be signed in to change notification settings - Fork 182
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 generator for Table class for StorIOSQLiteProcessor. (Issue #694) #734
Changes from 2 commits
6776110
bea0ff6
81acd08
46ea6d4
740a589
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,31 +5,33 @@ | |
|
||
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; | ||
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; | ||
|
||
|
||
// Just a class for demonstration, real Tweet structure is more complex. | ||
|
||
// This annotation will trigger annotation processor | ||
// Which will generate type mapping code in compile time, | ||
// You just need to link it in your code. | ||
@StorIOSQLiteType(table = TweetsTable.TABLE) | ||
@StorIOSQLiteType(table = "tweets") | ||
public class Tweet { | ||
|
||
/** | ||
* If object was not inserted into db, id will be null | ||
*/ | ||
@Nullable | ||
@StorIOSQLiteColumn(name = TweetsTable.COLUMN_ID, key = true) | ||
@StorIOSQLiteColumn(name = "_id", key = true) | ||
Long id; | ||
|
||
@NonNull | ||
@StorIOSQLiteColumn(name = TweetsTable.COLUMN_AUTHOR) | ||
@StorIOSQLiteColumn(name = "author") | ||
String author; | ||
|
||
@NonNull | ||
@StorIOSQLiteColumn(name = TweetsTable.COLUMN_CONTENT) | ||
@StorIOSQLiteColumn(name = "content") | ||
String content; | ||
|
||
// This column is not used in app, but shows how update code is generated | ||
@StorIOSQLiteColumn(name = "NewColumn", ignoreNull = true, version = 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make name snake case like another fields? |
||
String newColumn; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And add nullability please ;) |
||
|
||
// leave default constructor for AutoGenerated code! | ||
Tweet() { | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.pushtorefresh.storio.basic_sample; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.pushtorefresh.storio.sqlite.queries.Query; | ||
|
||
// We suggest to store table meta such as table name, columns names, queries, etc in separate class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// Because it makes code of the Entity itself cleaner and easier to read/understand/support | ||
public class TweetsQueries { | ||
|
||
// Yep, with StorIO you can safely store queries as objects and reuse them, they are immutable | ||
@NonNull | ||
public static final Query QUERY_ALL = Query.builder() | ||
.table(TweetTable.tableName) | ||
.build(); | ||
|
||
// This is just class with Meta Data, we don't need instances | ||
private TweetsQueries() { | ||
throw new IllegalStateException("No instances please"); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,26 @@ | |
import javax.lang.model.type.TypeMirror; | ||
|
||
public enum JavaType { | ||
BOOLEAN("INTEGER"), | ||
BOOLEAN_OBJECT("INTEGER"), | ||
SHORT("INTEGER"), | ||
SHORT_OBJECT("INTEGER"), | ||
INTEGER("INTEGER"), | ||
INTEGER_OBJECT("INTEGER"), | ||
LONG("INTEGER"), | ||
LONG_OBJECT("INTEGER"), | ||
FLOAT("REAL"), | ||
FLOAT_OBJECT("REAL"), | ||
DOUBLE("REAL"), | ||
DOUBLE_OBJECT("REAL"), | ||
STRING("TEXT"), | ||
BYTE_ARRAY("BLOB"); | ||
|
||
BOOLEAN, | ||
BOOLEAN_OBJECT, | ||
SHORT, | ||
SHORT_OBJECT, | ||
INTEGER, | ||
INTEGER_OBJECT, | ||
LONG, | ||
LONG_OBJECT, | ||
FLOAT, | ||
FLOAT_OBJECT, | ||
DOUBLE, | ||
DOUBLE_OBJECT, | ||
STRING, | ||
BYTE_ARRAY; | ||
JavaType(String sqlType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NotNull |
||
this.sqlType = sqlType; | ||
} | ||
|
||
private String sqlType; | ||
|
||
@NotNull | ||
public static JavaType from(@NotNull TypeMirror typeMirror) { | ||
|
@@ -73,4 +78,8 @@ public boolean isBoxedType() { | |
return false; | ||
} | ||
} | ||
|
||
public String getSqlType() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here please too =) |
||
return sqlType; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! But I not sure that everyone will need generated class, maybe add flag to this annotation? Something like
@StorIOSQLiteType(table = "tweets", generateTableClass = false)
which will be true by default?