OSDN Git Service

Add UNIQUE to EntrySchema.
authorHung-ying Tyan <tyanh@google.com>
Fri, 4 May 2012 10:07:48 +0000 (18:07 +0800)
committerHung-ying Tyan <tyanh@google.com>
Fri, 4 May 2012 10:08:42 +0000 (18:08 +0800)
Change-Id: I0fbf69a60aafe8d7a82241467d077c48beadbf49

gallerycommon/src/com/android/gallery3d/common/Entry.java
gallerycommon/src/com/android/gallery3d/common/EntrySchema.java

index b8cc512..3f1644e 100644 (file)
@@ -48,6 +48,8 @@ public abstract class Entry {
         boolean fullText() default false;
 
         String defaultValue() default "";
+
+        boolean unique() default false;
     }
 
     public void clear() {
index 46de03f..7bf7e43 100644 (file)
@@ -300,6 +300,7 @@ public final class EntrySchema {
         StringBuilder sql = new StringBuilder("CREATE TABLE ");
         sql.append(tableName);
         sql.append(" (_id INTEGER PRIMARY KEY AUTOINCREMENT");
+        StringBuilder unique = new StringBuilder();
         for (ColumnInfo column : mColumnInfo) {
             if (!column.isId()) {
                 sql.append(',');
@@ -310,8 +311,18 @@ public final class EntrySchema {
                     sql.append(" DEFAULT ");
                     sql.append(column.defaultValue);
                 }
+                if (column.unique) {
+                    if (unique.length() == 0) {
+                        unique.append(column.name);
+                    } else {
+                        unique.append(',').append(column.name);
+                    }
+                }
             }
         }
+        if (unique.length() > 0) {
+            sql.append(",UNIQUE(").append(unique).append(')');
+        }
         sql.append(");");
         logExecSql(db, sql.toString());
         sql.setLength(0);
@@ -493,7 +504,7 @@ public final class EntrySchema {
 
             // Add the column to the array.
             int index = columns.size();
-            columns.add(new ColumnInfo(info.value(), type, info.indexed(),
+            columns.add(new ColumnInfo(info.value(), type, info.indexed(), info.unique(),
                     info.fullText(), info.defaultValue(), field, index));
         }
     }
@@ -504,16 +515,18 @@ public final class EntrySchema {
         public final String name;
         public final int type;
         public final boolean indexed;
+        public final boolean unique;
         public final boolean fullText;
         public final String defaultValue;
         public final Field field;
         public final int projectionIndex;
 
-        public ColumnInfo(String name, int type, boolean indexed,
+        public ColumnInfo(String name, int type, boolean indexed, boolean unique,
                 boolean fullText, String defaultValue, Field field, int projectionIndex) {
             this.name = name.toLowerCase();
             this.type = type;
             this.indexed = indexed;
+            this.unique = unique;
             this.fullText = fullText;
             this.defaultValue = defaultValue;
             this.field = field;