/* doAsyncCallback() runs in the main thread. We don't want it to block. TODO: verify whether any IO is done by checking WaitMetaRequestCount at the start and end. */ void GetTableCall::doAsyncCallback(Local<Object> ctx) { const char *tableName; HandleScope scope; DEBUG_PRINT("GetTableCall::doAsyncCallback: return_val %d", return_val); /* User callback arguments */ Handle<Value> cb_args[2]; cb_args[0] = Null(); cb_args[1] = Null(); /* TableMetadata = { database : "" , // Database name name : "" , // Table Name columns : [] , // ordered array of DBColumn objects indexes : [] , // array of DBIndex objects partitionKey : [] , // ordered array of column numbers in the partition key }; */ if(ndb_table && ! return_val) { Local<Object> table = NdbDictTableEnv.newWrapper(); const NdbDictionary::Table * js_ndb_table = ndb_table; wrapPointerInObject(js_ndb_table, NdbDictTableEnv, table); // database table->Set(String::NewSymbol("database"), String::New(arg1)); // name tableName = ndb_table->getName(); table->Set(String::NewSymbol("name"), String::New(tableName)); // partitionKey int nPartitionKeys = 0; Handle<Array> partitionKeys = Array::New(); table->Set(String::NewSymbol("partitionKey"), partitionKeys); // columns Local<Array> columns = Array::New(ndb_table->getNoOfColumns()); for(int i = 0 ; i < ndb_table->getNoOfColumns() ; i++) { const NdbDictionary::Column *ndb_col = ndb_table->getColumn(i); Handle<Object> col = buildDBColumn(ndb_col); columns->Set(i, col); if(ndb_col->getPartitionKey()) { /* partition key */ partitionKeys->Set(nPartitionKeys++, String::New(ndb_col->getName())); } } table->Set(String::NewSymbol("columns"), columns); // indexes (primary key & secondary) Local<Array> js_indexes = Array::New(idx_list.count + 1); js_indexes->Set(0, buildDBIndex_PK()); // primary key for(unsigned int i = 0 ; i < idx_list.count ; i++) { // secondary indexes const NdbDictionary::Index * idx = dict->getIndex(idx_list.elements[i].name, arg2); js_indexes->Set(i+1, buildDBIndex(idx)); } table->Set(String::NewSymbol("indexes"), js_indexes, ReadOnly); // Table Record (implementation artifact; not part of spec) DEBUG_PRINT("Creating Table Record"); Record * rec = new Record(dict, ndb_table->getNoOfColumns()); for(int i = 0 ; i < ndb_table->getNoOfColumns() ; i++) { rec->addColumn(ndb_table->getColumn(i)); } rec->completeTableRecord(ndb_table); table->Set(String::NewSymbol("record"), Record_Wrapper(rec)); // foreign keys (only foreign keys for which this table is the child) // now create the javascript foreign key metadata objects for dictionary objects cached earlier Local<Array> js_fks = Array::New(fk_count); int fk_number = 0; for(unsigned int i = 0 ; i < fk_list.count ; i++) { NdbDictionary::ForeignKey fk; if (fk_list.elements[i].type == NdbDictionary::Object::ForeignKey) { const char * fk_name = fk_list.elements[i].name; int fkGetCode = dict->getForeignKey(fk, fk_name); DEBUG_PRINT("getForeignKey for %s returned %i", fk_name, fkGetCode); // see if the foreign key child table is this table if(splitNameMatchesDbAndTable(fk.getChildTable())) { // the foreign key child table is this table; build the fk object DEBUG_PRINT("Adding foreign key for %s at %i", fk.getName(), fk_number); js_fks->Set(fk_number++, buildDBForeignKey(&fk)); } } } table->Set(String::NewSymbol("foreignKeys"), js_fks, ReadOnly); // Autoincrement Cache Impl (also not part of spec) if(per_table_ndb) { table->Set(String::NewSymbol("per_table_ndb"), Ndb_Wrapper(per_table_ndb)); } // User Callback cb_args[1] = table; } else { cb_args[0] = NdbError_Wrapper(* ndbError); } callback->Call(ctx, 2, cb_args); }
/* doAsyncCallback() runs in the main thread. We don't want it to block. TODO: verify whether any IO is done by checking WaitMetaRequestCount at the start and end. */ void GetTableCall::doAsyncCallback(Local<Object> ctx) { const char *ndbTableName; EscapableHandleScope scope(isolate); DEBUG_PRINT("GetTableCall::doAsyncCallback: return_val %d", return_val); /* User callback arguments */ Handle<Value> cb_args[2]; cb_args[0] = Null(isolate); cb_args[1] = Null(isolate); /* TableMetadata = { database : "" , // Database name name : "" , // Table Name columns : [] , // ordered array of DBColumn objects indexes : [] , // array of DBIndex objects partitionKey : [] , // ordered array of column numbers in the partition key sparseContainer : null // default column for sparse fields }; */ if(ndb_table && ! return_val) { Local<Object> table = NdbDictTableEnv.wrap(ndb_table)->ToObject(); // database table->Set(SYMBOL(isolate, "database"), String::NewFromUtf8(isolate, arg1)); // name ndbTableName = ndb_table->getName(); table->Set(SYMBOL(isolate, "name"), String::NewFromUtf8(isolate, ndbTableName)); // partitionKey int nPartitionKeys = 0; Handle<Array> partitionKeys = Array::New(isolate); table->Set(SYMBOL(isolate, "partitionKey"), partitionKeys); // sparseContainer table->Set(SYMBOL(isolate,"sparseContainer"), Null(isolate)); // columns Local<Array> columns = Array::New(isolate, ndb_table->getNoOfColumns()); for(int i = 0 ; i < ndb_table->getNoOfColumns() ; i++) { const NdbDictionary::Column *ndb_col = ndb_table->getColumn(i); Handle<Object> col = buildDBColumn(ndb_col); columns->Set(i, col); if(ndb_col->getPartitionKey()) { /* partition key */ partitionKeys->Set(nPartitionKeys++, String::NewFromUtf8(isolate, ndb_col->getName())); } if( ! strcmp(ndb_col->getName(), "SPARSE_FIELDS") && ( (! strncmp(getColumnType(ndb_col), "VARCHAR", 7) && (getEncoderCharsetForColumn(ndb_col)->isUnicode)) || ( ! strncmp(getColumnType(ndb_col), "VARBINARY", 9) || ! strncmp(getColumnType(ndb_col), "JSON", 4)))) { table->Set(SYMBOL(isolate,"sparseContainer"), String::NewFromUtf8(isolate, ndb_col->getName())); } } table->Set(SYMBOL(isolate, "columns"), columns); // indexes (primary key & secondary) Local<Array> js_indexes = Array::New(isolate, idx_list.count + 1); js_indexes->Set(0, buildDBIndex_PK()); // primary key for(unsigned int i = 0 ; i < idx_list.count ; i++) { // secondary indexes const NdbDictionary::Index * idx = dict->getIndex(idx_list.elements[i].name, arg2); js_indexes->Set(i+1, buildDBIndex(idx)); } SET_RO_PROPERTY(table, SYMBOL(isolate, "indexes"), js_indexes); // foreign keys (only foreign keys for which this table is the child) // now create the javascript foreign key metadata objects for dictionary objects cached earlier Local<Array> js_fks = Array::New(isolate, fk_count); int fk_number = 0; for(unsigned int i = 0 ; i < fk_list.count ; i++) { NdbDictionary::ForeignKey fk; if (fk_list.elements[i].type == NdbDictionary::Object::ForeignKey) { const char * fk_name = fk_list.elements[i].name; int fkGetCode = dict->getForeignKey(fk, fk_name); DEBUG_PRINT("getForeignKey for %s returned %i", fk_name, fkGetCode); // see if the foreign key child table is this table if(splitNameMatchesDbAndTable(fk.getChildTable())) { // the foreign key child table is this table; build the fk object DEBUG_PRINT("Adding foreign key for %s at %i", fk.getName(), fk_number); js_fks->Set(fk_number++, buildDBForeignKey(&fk)); } } } SET_RO_PROPERTY(table, SYMBOL(isolate, "foreignKeys"), js_fks); // Autoincrement Cache Impl (also not part of spec) if(per_table_ndb) { table->Set(SYMBOL(isolate, "per_table_ndb"), Ndb_Wrapper(per_table_ndb)); } // User Callback cb_args[1] = table; } else { cb_args[0] = NdbError_Wrapper(* ndbError); } ToLocal(& callback)->Call(ctx, 2, cb_args); }