-
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
Closed
pbochenski
wants to merge
5
commits into
pushtorefresh:master
from
pbochenski:feature/table_creation_annotation
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6776110
Added generator for Table class for StorIOSQLiteProcessor. (Issue #694)
bea0ff6
removed testing code from basic sample app
81acd08
fixed some nullability annotations and names.
46ea6d4
added unit test for table generation
740a589
added option to turn off feature of creating table
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,31 +5,34 @@ | |
|
||
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 | ||
@Nullable | ||
@StorIOSQLiteColumn(name = "new_column", ignoreNull = true, version = 2) | ||
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() { | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
...o-basic-sample-app/src/main/java/com/pushtorefresh/storio/basic_sample/TweetsQueries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 queries in separate class | ||
// 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"); | ||
} | ||
} |
48 changes: 0 additions & 48 deletions
48
storio-basic-sample-app/src/main/java/com/pushtorefresh/storio/basic_sample/TweetsTable.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(@NotNull String sqlType) { | ||
this.sqlType = sqlType; | ||
} | ||
|
||
private String sqlType; | ||
|
||
@NotNull | ||
public static JavaType from(@NotNull TypeMirror typeMirror) { | ||
|
@@ -73,4 +78,9 @@ public boolean isBoxedType() { | |
return false; | ||
} | ||
} | ||
|
||
@NotNull | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?