Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private static bool destroyClearKeyChainAndCloseWithAccessor(JSONStoreSQLLite store, Boolean destroyAll)
        {
            int rc = 0;

            lock (lockThis)
            {
                rc = store.destroyDbDirectory(destroyAll);
                store.close();
            }

            return((rc == 0) ? true : false);
        }
Exemplo n.º 3
0
        /**
         * Locks access to all the collections until init is called.
         */
        public static bool closeAllCollections()
        {
            bool worked = false;

            // if transaction in process, cannot close, throw exception
            if (transactionInProgress)
            {
                //JSONStoreLoggerError(@"Error: JSON_STORE_TRANSACTION_FAILURE_DURING_CLOSE_ALL, code: %d", JSON_STORE_TRANSACTION_FAILURE_DURING_CLOSE_ALL);
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_TRANSACTION_FAILURE_DURING_CLOSE_ALL);
            }

            JSONStoreSQLLite store = JSONStoreSQLLite.sharedManager();

            if (store == null)
            {
                // if can't get a store, then we are already closed
                worked = true;
            }
            else if (!store.isOpen())
            {
                // already closed!
                worked = true;
            }
            else
            {
                // not closed, so do the close
                worked = store.close();
            }

            if (worked)
            {
                // clear the collections
                globalJSONStoreCollectionAccessors = null;
            }
            else
            {
                //JSONStoreLoggerError(@"Error: JSON_STORE_ERROR_CLOSING_ALL, code: %d", rc);
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_ERROR_CLOSING_ALL);
            }
            return(worked);
        }