memtrip / SQLKing

SQLKing is an Android SQLite ORM powered by an annotation preprocessor, tables are defined by Table annotations and CRUD classes expose an expressive api for executing SQLite queries. @memtrip
Other
21 stars 9 forks source link

Duplicate definitions being generated in retrieveSQLSelectResults #14

Closed Trellian closed 8 years ago

Trellian commented 8 years ago

Hi Sam,

I have a table that has two FK's in it as follows:

public class TblMapVisitor2Entry extends BaseObservable implements Parcelable
    {
    @Column(index = true) private int       id;
    @Column private TblEntry   tblEntry;
    @Column private TblVisitor tblVisitor;

and in Q.Java, I get an error on duplicate symbols as follows:

      for (int i = 0; !cursor.isAfterLast(); i++) {
        com.thorburn.sanscan.scanDB.TblMapVisitor2Entry tblmapvisitor2entry =
            new com.thorburn.sanscan.scanDB.TblMapVisitor2Entry();

        com.thorburn.sanscan.scanDB.TblEntry tblentry = new com.thorburn.sanscan.scanDB.TblEntry();
        tblmapvisitor2entry.setTblEntry(tblentry);

        com.thorburn.sanscan.scanDB.TblVisitor tblvisitor =
            new com.thorburn.sanscan.scanDB.TblVisitor();
        tblmapvisitor2entry.setTblVisitor(tblvisitor);

        com.thorburn.sanscan.scanDB.TblEntry tblentry = new com.thorburn.sanscan.scanDB.TblEntry();
        tblmapvisitor2entry.setTblEntry(tblentry);

        com.thorburn.sanscan.scanDB.TblVisitor tblvisitor =
            new com.thorburn.sanscan.scanDB.TblVisitor();
        tblmapvisitor2entry.setTblVisitor(tblvisitor);

You can see that 'tblentry' and 'tblvisitor' variables are being declared twice. I have had a look at the preprocessor template source for Q.Java but can't see how it could be happening. I'm currently taking a shot at fixing it, but not having much success.

Please can you take a look?

Thanks, Adrian

samkirton commented 8 years ago

Hi Adrian,

Could you paste the source of "BaseObservable" also?

Cheers, Sam

Trellian commented 8 years ago

Hi Sam,

You can see the source here: https://android.googlesource.com/platform/frameworks/data-binding/+/c9a5d6f140f732ca0ff279a4b1ee315072e1c422/library/src/main/java/android/databinding/BaseObservable.java

Thanks for the quick response!

/Adrian

On 02 Sep 2016 11:34, Samuel Kirton wrote:

Hi Adrian,

Could you paste the source of "BaseObservable" also?

Cheers, Sam

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/memtrip/SQLKing/issues/14#issuecomment-244329223, or mute the thread https://github.com/notifications/unsubscribe-auth/ABCOrHj89qUoypJUc3-pBWToCJ-2RyqWks5ql-2LgaJpZM4JzfYh.

Trellian commented 8 years ago

BaseObservable is being used because I'm using the new 2-way DataBinding features, instead of Butterknife

/Adrian

On 02 Sep 2016 11:34, Samuel Kirton wrote:

Hi Adrian,

Could you paste the source of "BaseObservable" also?

Cheers, Sam

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/memtrip/SQLKing/issues/14#issuecomment-244329223, or mute the thread https://github.com/notifications/unsubscribe-auth/ABCOrHj89qUoypJUc3-pBWToCJ-2RyqWks5ql-2LgaJpZM4JzfYh.

Trellian commented 8 years ago

I have tried this in Q.Java (starting at line 167 - in retrieveSQLSelectResults):

I'm building a list of columns already processed for the table, to avoid generating duplicates.

                for (int i = 0; !cursor.isAfterLast(); i++) {
                    ${packagedTableName} ${table.getName()?lower_case} = new ${packagedTableName}();
                    <#assign colsProcessed=[]>
                    <#list table.getColumns() as column>
                        <#if column.isJoinable(tables) >
                            <#if colsProcessed?seq_contains(column.getName()) != true>
                            ${joinReferences(table.getName(),tables)}
                                <#assign colsProcessed = colsProcessed + [column.getName()]>
                            </#if>
                        </#if>
                    </#list>

Preprocessor builds fine, but final Q.Java doesn't generate now, so obviously I've made a stupid mistake.

samkirton commented 8 years ago

If the final Q doesn't generate it will be a FreeMarker issue, if you build the project with mvn clean install -X it should be logged.

Also is 2 way binding available in the support library?

Trellian commented 8 years ago

I've got the final Q to generate now, it still has the double declarations, but FreeMarker seems happy for now.

One thing that concerns me is that the Maven Install installs to: C:\Users\Adrian.m2\repository\com\memtrip\sqlking\preprocessor\1.0.15\preprocessor-1.0.15.jar

And it looks like my gradle build of my project is using what it has in it's cache at

C:\Users\Adrian\m2repository\com\memtrip\sqlking\preprocessor\1.0.15\preprocessor-1.0.15.jar

I couldn't find a way to point either one to a consolidated maven repository.

Have you experienced this before?

Regards, Adrian

On 02 Sep 2016 11:56, Samuel Kirton wrote:

If the final Q doesn't generate it will be a FreeMarker issue, if you build the project with |mvn clean install -X| it should be logged.

Also is 2 way binding available in the support library?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/memtrip/SQLKing/issues/14#issuecomment-244334152, or mute the thread https://github.com/notifications/unsubscribe-auth/ABCOrHSdDh9rjRb4ysSBuQE1zEwT6E6Aks5ql_LLgaJpZM4JzfYh.

samkirton commented 8 years ago

On the client project it might be worth using: gradle build --refresh-dependencies

Also its probably best if you stash your changes and see if you can reproduce the issue, it might have been fixed in 1.1, 1.0.15 is quite old!

Trellian commented 8 years ago

I'm a bit confused here... it turns out that I was indeed using 1.1, but changes to my local 1.0.15 showed up as compile errors in my client project?

Anyway, I have moved to 1.1, the original problem still exists with the duplicate declarations.

Any Ideas?

Thanks, Adrian

samkirton commented 8 years ago

Hi Adrian,

Please see the fix/duplicate_relationships branch, the issue has been fixed. I will push a release to maven central tonight.

Cheers, Sam

Trellian commented 8 years ago

Hi Sam, Did you get a chance to push a release to Maven?

Thanks, Adrian

samkirton commented 8 years ago

All deployed.

Cheers, Sam

Trellian commented 8 years ago

Thanks Sam, works like a charm!