Permalink
Browse files

The functions of Writing column's name and index are added.

  • Loading branch information...
1 parent 0d113fe commit aeb747f1417eabdb1099eb48bb81c00ffb66c0c1 @cattaka committed Jun 17, 2012
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Generate DB Handler
Bundle-SymbolicName: GenDbHandler;singleton:=true
-Bundle-Version: 0.9.6
+Bundle-Version: 0.9.7
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.jdt.apt.core
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Binary file not shown.
Binary file not shown.
@@ -16,4 +16,7 @@
String[] find() default {};
String[] unique() default {};
+
+ boolean columnIndexConstants() default true;
+ boolean columnNameConstants() default true;
}
@@ -64,6 +64,8 @@ public int compareTo(FindEntriesPerVersion o) {
String columnName = null;
+ String constantsColumnName = null;
+
FieldType fieldType = FieldType.STRING;
String fieldClass;
@@ -201,6 +203,19 @@ public void process() {
pw.println(" public static final String[] COLUMNS_ARRAY = new String[] {"
+ createColumnsArray(bundle) + "};");
+ if (genDbHandler.columnIndexConstants()) {
+ int index = 0;
+ for (FieldEntry fe : bundle.fieldEntries) {
+ pw.println(" public static final int COL_INDEX_" + fe.constantsColumnName + " = "+ index +";");
+ index++;
+ }
+ }
+ if (genDbHandler.columnNameConstants()) {
+ for (FieldEntry fe : bundle.fieldEntries) {
+ pw.println(" public static final String COL_NAME_" + fe.constantsColumnName + " = \"" + fe.columnName + "\";");
+ }
+ }
+
// Insert
pw.println(" public static long insert(SQLiteDatabase db, " + className
+ " model) {");
@@ -745,6 +760,7 @@ public void visitPrimitiveType(PrimitiveType t) {
{
fe.name = fd.getSimpleName();
fe.columnName = convertName(genDbHandler.fieldNamingConventions(), fe.name);
+ fe.constantsColumnName = convertName(NamingConventions.UPPER_COMPOSITE, fe.name);
}
if (fe.persistent) {
fes.add(fe);
@@ -4,6 +4,6 @@
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
- <classpathentry kind="lib" path="lib/GenDbHandler_0.9.6.jar"/>
+ <classpathentry kind="lib" path="lib/GenDbHandler_0.9.7.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
@@ -1,3 +1,4 @@
<factorypath>
- <factorypathentry kind="WKSPJAR" id="/GenDbHandlerAppTest/lib/GenDbHandler_0.9.6.jar" enabled="true" runInBatchMode="false"/>
+ <factorypathentry kind="WKSPJAR" id="/GenDbHandlerAppTest/lib/GenDbHandler_0.9.7.jar" enabled="true" runInBatchMode="false"/>
+ <factorypathentry kind="PLUGIN" id="org.eclipse.jst.ws.annotations.core" enabled="false" runInBatchMode="false"/>
</factorypath>
@@ -40,7 +40,7 @@ public void testDml() {
tags.add("Java");
tags.add("PHP");
model = new UserModel(null, "taro", "Taro Yamada", "A", Role.PROGRAMMER,
- new Date(), tags, Authority.ADMIN);
+ new Date(), tags, Authority.ADMIN, new byte[] {1,2});
}
UserModelHandler.insert(db, model);
UserModel model2 = UserModelHandler.findByUsername(db, "taro");
@@ -53,6 +53,9 @@ public void testDml() {
assertEquals("Java", model2.getTags().get(0));
assertEquals("PHP", model2.getTags().get(1));
assertEquals(Authority.ADMIN, model2.getAuthority());
+ assertNotNull(model2.getBlob());
+ assertEquals((byte) 1,model2.getBlob()[0]);
+ assertEquals((byte) 2,model2.getBlob()[1]);
}
{ // Update
UserModel model = UserModelHandler.findByUsername(db, "taro");
@@ -67,6 +70,7 @@ public void testDml() {
model.setRole(Role.MANAGER);
model.setCreatedAt(new Date());
model.setTags(tags);
+ model.setBlob(null);
}
long n = UserModelHandler.update(db, model);
assertEquals(1L, n);
@@ -79,6 +83,7 @@ public void testDml() {
assertEquals(model.getTags().size(), model2.getTags().size());
assertEquals("Java", model2.getTags().get(0));
assertEquals("PHP", model2.getTags().get(1));
+ assertNull(model2.getBlob());
}
{ // delete
UserModel model = UserModelHandler.findByUsername(db, "taro2");
@@ -48,6 +48,8 @@
@Attribute(persistent = false)
private Object userData;
+ private byte[] blob;
+
public UserModel() {
}
@@ -64,6 +66,12 @@ public UserModel(Long id, String username, String nickname, String team, Role ro
this.authority = authority;
}
+ public UserModel(Long id, String username, String nickname, String team, Role role,
+ Date createdAt, List<String> tags, Authority authority, byte[] blob) {
+ this(id, username, nickname, team, role, createdAt, tags, authority);
+ this.blob = blob;
+ }
+
public Long getId() {
return id;
}
@@ -135,4 +143,13 @@ public Authority getAuthority() {
public void setAuthority(Authority authority) {
this.authority = authority;
}
+
+ public byte[] getBlob() {
+ return blob;
+ }
+
+ public void setBlob(byte[] blob) {
+ this.blob = blob;
+ }
+
}

0 comments on commit aeb747f

Please sign in to comment.