コード例 #1
0
        /**
         * Permanently deletes all the documents stored in a collection and removes the accessor for that collection.
         */
        public bool removeCollection()
        {
            // cannot remove if transaction is in progress, throw exception
            if (JSONStore.transactionInProgress)
            {
                //JSONStoreLoggerError(@"Error: JSON_STORE_TRANSACTION_FAILURE_DURING_REMOVE_COLLECTION, code: %d", rc);
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_TRANSACTION_FAILURE_DURING_REMOVE_COLLECTION);
            }

            JSONStoreSQLLite store = JSONStoreSQLLite.sharedManager();

            if (store == null)
            {
                //JSONStoreLoggerError(@"Error: JSON_STORE_DATABASE_NOT_OPEN, code: %d", rc);
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN);
            }

            // drop the table
            lock (JSONStore.lockThis)
            {
                bool worked = store.dropTable(collectionName);

                if (!worked)
                {
                    //JSONStoreLoggerError(@"Error: JSON_STORE_ERROR_CLEARING_COLLECTION, code: %d, collection name: %@, accessor username: %@", rc, self.collectionName, accessor != nil ? accessor.username : @"nil");
                    throw new JSONStoreException(JSONStoreConstants.JSON_STORE_ERROR_CLEARING_COLLECTION);
                }
                else
                {
                    JSONStore.removeAccessor(collectionName);
                }

                return(worked);
            }
        }
コード例 #2
0
        private static int provisionCollection(string collectionName, IDictionary <string, string> searchFields, IDictionary <string,
                                                                                                                              string> additionalSearchFields, string username, string password, bool dropFirst)
        {
            // if no username set, use the default
            if (String.IsNullOrEmpty(username))
            {
                username = JSONStoreConstants.JSON_STORE_DEFAULT_USER;
            }

            // get the shared manager
            JSONStoreSQLLite store = JSONStoreSQLLite.sharedManager(username);

            if (store == null)
            {
                //JSONStoreLoggerError(@"Error: JSON_STORE_USERNAME_MISMATCH, code: %d, username passed: %@, accessor username: %@, collection name: %@", JSON_STORE_USERNAME_MISMATCH, username, accessor != nil ? accessor.username : @"nil", collectionName);
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_USERNAME_MISMATCH);
            }

            if (!String.IsNullOrEmpty(password))
            {
                // set the key for the database
                lock (lockThis)
                {
                    if (!store.setDatabaseKey(username, password))
                    {
                        //JSONStoreLoggerError(@"Error: JSON_STORE_PROVISION_KEY_FAILURE, code: %d, checkForSecurityUpgrade return code: %d, setDBKeyWorked: %@", JSON_STORE_PROVISION_KEY_FAILURE, rc, setDBKeyWorked ? @"YES" : @"NO");
                        throw new JSONStoreException(JSONStoreConstants.JSON_STORE_PROVISION_KEY_FAILURE);
                    }
                }
            }

            int rc = 0;

            lock (lockThis)
            {
                // drop the table if needed
                if (dropFirst)
                {
                    store.dropTable(collectionName);
                }

                // provision the collection for the name, searchFields, and additionalSearchFields

                rc = store.provisionCollection(collectionName, new JSONStoreSchema(searchFields, additionalSearchFields));

                if (rc < JSONStoreConstants.JSON_STORE_RC_OK)
                {
                    //JSONStoreLoggerError(@"Error: JSON_STORE_EXCEPTION, code: %d, username: %@, accessor username: %@, collection name: %@, searchFields: %@, additionalSearchFields: %@", rc, username, accessor != nil ? accessor.username : @"nil", collectionName, searchFields, additionalIndexes);

                    store.close();

                    throw new JSONStoreException(rc);
                }
            }

            return(rc);
        }