[Groonga-commit] groonga/gcs [master] Move codes to delete index field from configuration API to IndexField

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 12日 (木) 18:49:34 JST


SHIMODA Hiroshi	2012-07-12 18:49:34 +0900 (Thu, 12 Jul 2012)

  New Revision: e7142eee9231d04531ee7452f5b57b8c40b44117
  https://github.com/groonga/gcs/commit/e7142eee9231d04531ee7452f5b57b8c40b44117

  Log:
    Move codes to delete index field from configuration API to IndexField

  Modified files:
    lib/api/2011-02-01/configuration.js
    lib/database/domain.js
    lib/database/index-field.js

  Modified: lib/api/2011-02-01/configuration.js (+1 -18)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-07-12 18:29:44 +0900 (7512b0d)
+++ lib/api/2011-02-01/configuration.js    2012-07-12 18:49:34 +0900 (9f20503)
@@ -253,25 +253,8 @@ handlers.DeleteIndexField = function(context, request, response) {
 
   var fieldName = request.query['IndexFieldName'] || '';
   var field = domain.getIndexField(fieldName);
-
-  var column = context.columnListSync(domain.tableName)
-                 .filter(function(column) {
-                   return column.name == field.columnName;
-                 })[0];
-
   try {
-    context.commandSync('column_remove', {
-      table: domain.tableName,
-      name: field.columnName
-    });
-
-    if (column.range == field.fieldTypeToColumnType('uint') ||
-        column.range == field.fieldTypeToColumnType('literal')) {
-      context.commandSync('table_remove', {
-        name: field.alterTableName
-      });
-    }
-
+    field.deleteSync();
     response.contentType('application/xml');
     response.send(createDeleteIndexFieldResponse({}));
   } catch(error) {

  Modified: lib/database/domain.js (+8 -25)
===================================================================
--- lib/database/domain.js    2012-07-12 18:29:44 +0900 (8701003)
+++ lib/database/domain.js    2012-07-12 18:49:34 +0900 (926f57a)
@@ -101,33 +101,16 @@ Domain.prototype = {
     if (!this.context)
       throw new Error('no context');
     var columns = this.context.ordinalColumnsSync(this.tableName);
-    var fields = columns.map(this.columnToIndexField, this);
+    var fields = columns.map(function(column) {
+                   // XXX The "name" must be the field name given by the user,
+                   // not normalized. Because there is no such information in the
+                   // context and currently the column name is luckly equals to the
+                   // given field name, we can use the column name.
+                   var name = column.name;
+                   return this.getIndexField(name);
+                 }, this);
     return fields;
   },
-  columnToIndexField: function(column) {
-    // XXX The "name" must be the field name given by the user,
-    // not normalized. Because there is no such information in the
-    // context and currently the column name is luckly equals to the
-    // given field name, we can use the column name.
-    var name = column.name;
-    var field = this.getIndexField(name);
-
-    var type;
-    if (column.type == 'var') {
-      if (column.range == nroonga.ShortText)
-        type = 'text';
-    } else if (column.type == 'fix') {
-      if (column.range == nroonga.UInt32)
-        type = 'uint';
-      else if (column.range == field.alterTableName)
-        type = 'literal';
-    }
-    if (!type)
-      throw new Error('unknown unfixed column '+column.name);
-
-    field.type = type;
-    return field;
-  },
   get synonymTableName() {
     if (!this._synonymTableName)
       this._synonymTableName = this.tableName + '_synonyms';

  Modified: lib/database/index-field.js (+54 -0)
===================================================================
--- lib/database/index-field.js    2012-07-12 18:29:44 +0900 (be5297a)
+++ lib/database/index-field.js    2012-07-12 18:49:34 +0900 (8104444)
@@ -42,6 +42,7 @@ function assertValidFieldName(field) {
 
 function IndexField(name, domain) {
   this.domain = domain;
+  this.context = domain.context;
   this.name = name;
   this.type = null;
   this.initialize();
@@ -103,6 +104,59 @@ IndexField.prototype = {
         throw new Error('Unsupported index field type '+fieldType+
                         ' for alter table');
     }
+  },
+
+  get column() {
+    var columns = this.context.ordinalColumnsSync(this.domain.tableName);
+    for (var i = 0, maxi = columns.length; i < maxi; i++) {
+      if (columns[i].name == this.columnName)
+        return columns[i];
+    }
+    return null;
+  },
+
+  get type() {
+    if (this._type)
+      return this._type;
+
+    var column = this.column;
+    if (!column)
+      throw new Error('the column '+this.columnName+' is not created yet');
+
+    if (column.type == 'var') {
+      if (column.range == nroonga.ShortText)
+        return 'text';
+    } else if (column.type == 'fix') {
+      if (column.range == nroonga.UInt32)
+        return 'uint';
+      else if (column.range == field.alterTableName)
+        return 'literal';
+    }
+
+    throw new Error('unknown unfixed column '+this.columnName);
+  },
+  set type(type) {
+    return this._type = type
+  },
+
+  deleteSync: function() {
+    var column = this.context.columnListSync(domain.tableName)
+                 .filter(function(column) {
+                   return column.name == field.columnName;
+                 })[0];
+    this.context.commandSync('column_remove', {
+      table: this.domain.tableName,
+      name: this.columnName
+    });
+
+    if (column.range == field.fieldTypeToColumnType('uint') ||
+        column.range == field.fieldTypeToColumnType('literal')) {
+      context.commandSync('table_remove', {
+        name: field.alterTableName
+      });
+    }
+
+
   }
 };
 
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index