Skip to content

Commit acc1a80

Browse files
committed
prepared a test for byte arrays as query params (unsupported yet)
1 parent b626499 commit acc1a80

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

DaoTest/src-gen/de/greenrobot/daotest/TestEntity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class TestEntity {
1616
private String indexedStringAscUnique;
1717
private java.util.Date simpleDate;
1818
private Boolean simpleBoolean;
19+
private byte[] simpleByteArray;
1920

2021
public TestEntity() {
2122
}
@@ -24,7 +25,7 @@ public TestEntity(Long id) {
2425
this.id = id;
2526
}
2627

27-
public TestEntity(Long id, int simpleInt, Integer simpleInteger, String simpleStringNotNull, String simpleString, String indexedString, String indexedStringAscUnique, java.util.Date simpleDate, Boolean simpleBoolean) {
28+
public TestEntity(Long id, int simpleInt, Integer simpleInteger, String simpleStringNotNull, String simpleString, String indexedString, String indexedStringAscUnique, java.util.Date simpleDate, Boolean simpleBoolean, byte[] simpleByteArray) {
2829
this.id = id;
2930
this.simpleInt = simpleInt;
3031
this.simpleInteger = simpleInteger;
@@ -34,6 +35,7 @@ public TestEntity(Long id, int simpleInt, Integer simpleInteger, String simpleSt
3435
this.indexedStringAscUnique = indexedStringAscUnique;
3536
this.simpleDate = simpleDate;
3637
this.simpleBoolean = simpleBoolean;
38+
this.simpleByteArray = simpleByteArray;
3739
}
3840

3941
public Long getId() {
@@ -110,4 +112,12 @@ public void setSimpleBoolean(Boolean simpleBoolean) {
110112
this.simpleBoolean = simpleBoolean;
111113
}
112114

115+
public byte[] getSimpleByteArray() {
116+
return simpleByteArray;
117+
}
118+
119+
public void setSimpleByteArray(byte[] simpleByteArray) {
120+
this.simpleByteArray = simpleByteArray;
121+
}
122+
113123
}

DaoTest/src-gen/de/greenrobot/daotest/TestEntityDao.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static class Properties {
3232
public final static Property IndexedStringAscUnique = new Property(6, String.class, "indexedStringAscUnique", false, "INDEXED_STRING_ASC_UNIQUE");
3333
public final static Property SimpleDate = new Property(7, java.util.Date.class, "simpleDate", false, "SIMPLE_DATE");
3434
public final static Property SimpleBoolean = new Property(8, Boolean.class, "simpleBoolean", false, "SIMPLE_BOOLEAN");
35+
public final static Property SimpleByteArray = new Property(9, byte[].class, "simpleByteArray", false, "SIMPLE_BYTE_ARRAY");
3536
};
3637

3738

@@ -55,7 +56,8 @@ public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
5556
"\"INDEXED_STRING\" TEXT," + // 5: indexedString
5657
"\"INDEXED_STRING_ASC_UNIQUE\" TEXT," + // 6: indexedStringAscUnique
5758
"\"SIMPLE_DATE\" INTEGER," + // 7: simpleDate
58-
"\"SIMPLE_BOOLEAN\" INTEGER);"); // 8: simpleBoolean
59+
"\"SIMPLE_BOOLEAN\" INTEGER," + // 8: simpleBoolean
60+
"\"SIMPLE_BYTE_ARRAY\" BLOB);"); // 9: simpleByteArray
5961
// Add Indexes
6062
db.execSQL("CREATE INDEX " + constraint + "IDX_TEST_ENTITY_INDEXED_STRING ON TEST_ENTITY" +
6163
" (\"INDEXED_STRING\");");
@@ -110,6 +112,11 @@ protected void bindValues(SQLiteStatement stmt, TestEntity entity) {
110112
if (simpleBoolean != null) {
111113
stmt.bindLong(9, simpleBoolean ? 1L: 0L);
112114
}
115+
116+
byte[] simpleByteArray = entity.getSimpleByteArray();
117+
if (simpleByteArray != null) {
118+
stmt.bindBlob(10, simpleByteArray);
119+
}
113120
}
114121

115122
/** @inheritdoc */
@@ -130,7 +137,8 @@ public TestEntity readEntity(Cursor cursor, int offset) {
130137
cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // indexedString
131138
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // indexedStringAscUnique
132139
cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)), // simpleDate
133-
cursor.isNull(offset + 8) ? null : cursor.getShort(offset + 8) != 0 // simpleBoolean
140+
cursor.isNull(offset + 8) ? null : cursor.getShort(offset + 8) != 0, // simpleBoolean
141+
cursor.isNull(offset + 9) ? null : cursor.getBlob(offset + 9) // simpleByteArray
134142
);
135143
return entity;
136144
}
@@ -147,6 +155,7 @@ public void readEntity(Cursor cursor, TestEntity entity, int offset) {
147155
entity.setIndexedStringAscUnique(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
148156
entity.setSimpleDate(cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)));
149157
entity.setSimpleBoolean(cursor.isNull(offset + 8) ? null : cursor.getShort(offset + 8) != 0);
158+
entity.setSimpleByteArray(cursor.isNull(offset + 9) ? null : cursor.getBlob(offset + 9));
150159
}
151160

152161
/** @inheritdoc */

DaoTest/src/de/greenrobot/daotest/query/QueryBuilderSimpleTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ public void testEqBoolean() {
171171
assertEquals(testEntity.getId(), testEntity2.getId());
172172
}
173173

174+
// TODO fix byte arrays? Android is doing String args everywhere
175+
public void _testEqByteArray() {
176+
ArrayList<TestEntity> inserted = insert(3);
177+
TestEntity testEntity = inserted.get(1);
178+
179+
byte[] byteArray = {96, 77, 37, -21};
180+
testEntity.setSimpleByteArray(byteArray);
181+
dao.update(testEntity);
182+
183+
Query<TestEntity> queryBoolean = dao.queryBuilder().where(Properties.SimpleByteArray.eq(byteArray)).build();
184+
TestEntity testEntity2 = queryBoolean.uniqueOrThrow();
185+
assertEquals(testEntity.getId(), testEntity2.getId());
186+
187+
queryBoolean.setParameter(0, new byte[]{96, 77, 37, -21, 99});
188+
assertNull(queryBoolean.unique());
189+
}
190+
174191
public void testIsNullIsNotNull() {
175192
ArrayList<TestEntity> inserted = insert(2);
176193
TestEntity testEntityNull = inserted.get(0);
@@ -210,15 +227,15 @@ public void testLike() {
210227
Query<TestEntity> query = dao.queryBuilder().where(Properties.SimpleString.like("%robot")).build();
211228
TestEntity entity2 = query.uniqueOrThrow();
212229
assertEquals(entity.getId(), entity2.getId());
213-
230+
214231
query.setParameter(0, "green%");
215232
entity2 = query.uniqueOrThrow();
216233
assertEquals(entity.getId(), entity2.getId());
217-
234+
218235
query.setParameter(0, "%enrob%");
219236
entity2 = query.uniqueOrThrow();
220237
assertEquals(entity.getId(), entity2.getId());
221-
238+
222239
query.setParameter(0, "%nothere%");
223240
entity2 = query.unique();
224241
assertNull(entity2);

DaoTestGenerator/src/de/greenrobot/daogenerator/gentest/TestDaoGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ protected Entity createTest() {
113113
testEntity.addStringProperty("indexedStringAscUnique").indexAsc(null, true);
114114
testEntity.addDateProperty("simpleDate");
115115
testEntity.addBooleanProperty("simpleBoolean");
116+
testEntity.addByteArrayProperty("simpleByteArray");
116117
return testEntity;
117118
}
118119

0 commit comments

Comments
 (0)