Skip to content

Commit

Permalink
fixed issue where private AI keys did not reference methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Grosner committed Jul 3, 2015
1 parent ea7cae5 commit 9fcf83f
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public void writeLoadFromCursorDefinition(BaseTableDefinition tableDefinition, J
}
}

public void writeToModelDefinition(JavaWriter javaWriter) throws IOException {
public void writeToModelDefinition(JavaWriter javaWriter, boolean isModelContainerAdapter) throws IOException {

if (!isModel) {
AdapterQueryBuilder adapterQueryBuilder = new AdapterQueryBuilder("Object value");
Expand All @@ -487,6 +487,8 @@ public void writeToModelDefinition(JavaWriter javaWriter) throws IOException {
}


ColumnAccessModel columnAccessModel = new ColumnAccessModel(manager, this, isModelContainerAdapter);

AdapterQueryBuilder queryBuilder = new AdapterQueryBuilder();
queryBuilder.appendVariable(false)
.append(".")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public ColumnAccessModel(ColumnDefinition columnDefinition, ForeignKeyReference
columnFieldBoxedType = columnFieldActualType;
}

public boolean isPrivate() {
return isPrivate;
}

public String getQueryNoCast() {
return getQuery(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void emitColumnAssignment(JavaWriter javaWriter,
queryBuilder.append(")");
}

if (accessModel.isPrivate) {
if (accessModel.isPrivate && !isContainerFieldDefinition) {
queryBuilder.append(")");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void write(JavaWriter javaWriter) throws IOException {

for (ColumnDefinition columnDefinition : baseTableDefinition.getColumnDefinitions()) {
columnDefinition.writeLoadFromCursorDefinition(baseTableDefinition, javaWriter,
isModelContainerDefinition);
isModelContainerDefinition);
}

// don't use methods here as they result in undefined behavior.
Expand All @@ -80,8 +80,8 @@ public void write(JavaWriter javaWriter) throws IOException {
}
if (implementsLoadFromCursorListener && !isModelContainerDefinition) {
javaWriter.emitStatement("%1s.onLoadFromCursor(%1s)",
ModelUtils.getVariable(isModelContainerDefinition),
params[1]);
ModelUtils.getVariable(isModelContainerDefinition),
params[1]);
}

}
Expand Down Expand Up @@ -135,27 +135,27 @@ public void write(JavaWriter javaWriter) throws IOException {
ColumnDefinition columnDefinition = tableDefinition.getPrimaryColumnDefinitions().get(0);

javaWriter.emitStatement("return %1s.%1s", tableDefinition.getTableSourceClassName(),
columnDefinition.columnName.toUpperCase());
columnDefinition.columnName.toUpperCase());
}
}, "String", "getCachingColumnName", Sets.newHashSet(Modifier.PUBLIC));

ColumnAccessModel columnAccessModel = new ColumnAccessModel(tableDefinition.getManager(),
tableDefinition.getPrimaryColumnDefinitions().get(
0), false);
tableDefinition.getPrimaryColumnDefinitions().get(
0), false);
final String statement = ModelUtils
.getCursorStatement(columnAccessModel.getCastedClass(),
columnAccessModel.getReferencedColumnFieldName())
columnAccessModel.getReferencedColumnFieldName())
.replace("()", "");
WriterUtils.emitOverriddenMethod(javaWriter, new FlowWriter() {
@Override
public void write(JavaWriter javaWriter) throws IOException {
@Override
public void write(JavaWriter javaWriter) throws IOException {

javaWriter.emitStatement("return %1s", statement);
javaWriter.emitStatement("return %1s", statement);

}
}, "Object", "getCachingIdFromCursorIndex",
Sets.newHashSet(Modifier.PUBLIC), "Cursor", "cursor",
"int", "index" + columnAccessModel.getReferencedColumnFieldName().replace("()", ""));
}
}, "Object", "getCachingIdFromCursorIndex",
Sets.newHashSet(Modifier.PUBLIC), "Cursor", "cursor",
"int", "index" + columnAccessModel.getReferencedColumnFieldName().replace("()", ""));
}
} else if (tableDefinition.hasAutoIncrement) {
params[0] = ModelUtils.getParameter(isModelContainerDefinition, tableDefinition.getModelClassName());
Expand All @@ -170,10 +170,17 @@ public void write(JavaWriter javaWriter) throws IOException {
.append(ModelUtils.getVariable(isModelContainerDefinition));

if (!isModelContainerDefinition) {
queryBuilder.append(".").append(columnDefinition.columnFieldName)
.append(" = ")
.appendCast(columnDefinition.columnFieldType)
ColumnAccessModel columnAccessModel = new ColumnAccessModel(baseTableDefinition.getManager(),
columnDefinition, isModelContainerDefinition);
queryBuilder.append(".").append(columnAccessModel.getSetterReferenceColumnFieldName());
if (!columnAccessModel.isPrivate()) {
queryBuilder.appendSpaceSeparated("=");
}
queryBuilder.appendCast(columnDefinition.columnFieldType)
.append(params[3]).append(")");
if (columnAccessModel.isPrivate()) {
queryBuilder.append(")");
}
} else {
String containerKeyName = columnDefinition.columnFieldName;
if (columnDefinition.containerKeyName != null) {
Expand All @@ -200,7 +207,10 @@ public void write(JavaWriter javaWriter) throws IOException {
.append(ModelUtils.getVariable(isModelContainerDefinition));

if (!isModelContainerDefinition) {
queryBuilder.append(".").append(columnDefinition.columnFieldName);
ColumnAccessModel columnAccessModel = new ColumnAccessModel(
baseTableDefinition.getManager(),
columnDefinition, isModelContainerDefinition);
queryBuilder.append(".").append(columnAccessModel.getReferencedColumnFieldName());
} else {
String containerKeyName = columnDefinition.columnFieldName;
if (columnDefinition.containerKeyName != null) {
Expand All @@ -220,7 +230,7 @@ public void write(JavaWriter javaWriter) throws IOException {
ColumnDefinition columnDefinition = tableDefinition.autoIncrementDefinition;

javaWriter.emitStatement("return %1s.%1s", tableDefinition.getTableSourceClassName(),
columnDefinition.columnName.toUpperCase());
columnDefinition.columnName.toUpperCase());
}
}, "String", "getAutoIncrementingColumnName", Sets.newHashSet(Modifier.PUBLIC));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void write(JavaWriter javaWriter) throws IOException {
javaWriter.emitStatement(tableDefinition.getModelClassName() + " " + ModelUtils.getVariable(false) +
" = new " + tableDefinition.getModelClassName() + "()");
for (ColumnDefinition columnDefinition : tableDefinition.getColumnDefinitions()) {
columnDefinition.writeToModelDefinition(javaWriter);
columnDefinition.writeToModelDefinition(javaWriter, isModelContainerDefinition);
}
javaWriter.emitStatement("return " + ModelUtils.getVariable(false));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.raizlabs.android.dbflow.test;

import com.raizlabs.android.dbflow.annotation.Column;
import com.raizlabs.android.dbflow.annotation.ModelContainer;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.structure.BaseModel;

import java.util.Date;

@Table(databaseName = TestDatabase.NAME, tableName = AQL.ENDPOINT)
@ModelContainer
public class AQL extends BaseModel {

public static final String ENDPOINT = "AQL";

public interface Columns {
String AQL_ID = "aql_id";
String AQL_NAME = "aql_name";
String AQL_SERVER_ID = "aql_server_id";
String AQL_TIMESTAMP = "aql_timestamp";
}

@Column(name = Columns.AQL_ID)
@PrimaryKey(autoincrement = true)
private Long aql_id;

@Column(name = Columns.AQL_NAME)
private String aql_name;

@Column(name = Columns.AQL_SERVER_ID)
private Long server_id;

@Column(name = Columns.AQL_TIMESTAMP)
private Date timestamp;

public Long getAql_id() {
return aql_id;
}

public void setAql_id(Long aql_id) {
this.aql_id = aql_id;
}

public String getAql_name() {
return aql_name;
}

public void setAql_name(String aql_name) {
this.aql_name = aql_name;
}

public Long getServer_id() {
return server_id;
}

public void setServer_id(Long server_id) {
this.server_id = server_id;
}

public Date getTimestamp() {
return timestamp;
}

public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
}

0 comments on commit 9fcf83f

Please sign in to comment.