Esempio n. 1
0
        /// <summary>
        /// Gets the object of data table row.
        /// </summary>
        /// <typeparam name="T">The type definition of data table row.</typeparam>
        /// <param name="primaryValue">The primary value.</param>
        /// <returns>The object of type definition.</returns>
        public T GetDataTableRow <T>(object primaryValue) where T : DataTableRow, new()
        {
            DataTableAddressMap addressMap = GetDatabaseAddressMap <T>();
            BoxDBAdapter        dbAdapter  = GetDatabaseBoxAdapter(addressMap);
            T data = default(T);

            if (dbAdapter != null)
            {
                try
                {
                    string tableName = addressMap.Type;
                    dbAdapter.EnsureTable <T>(tableName, addressMap.PrimaryPropertyName);
                    dbAdapter.Open();
                    data = dbAdapter.Select <T>(tableName, primaryValue);
                }
                catch (Exception exception)
                {
                    Debug.LogException(exception);
                }
                finally
                {
                    if (dbAdapter != null)
                    {
                        dbAdapter.Dispose();
                    }
                }
            }

            return(data);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the data table row count.
        /// </summary>
        /// <typeparam name="T">The type definition of data table row.</typeparam>
        /// <param name="conditions">The conditions.</param>
        /// <param name="multiConditionOperators">The multi condition operators.</param>
        /// <returns>The data table row count.</returns>
        public long GetDataTableRowsCount <T>(List <BoxDBQueryCondition> conditions,
                                              List <BoxDBMultiConditionOperator> multiConditionOperators = null) where T : DataTableRow, new()
        {
            DataTableAddressMap addressMap = GetDatabaseAddressMap <T>();
            BoxDBAdapter        dbAdapter  = GetDatabaseBoxAdapter(addressMap);
            long count = 0;

            if (dbAdapter != null)
            {
                try
                {
                    string tableName = addressMap.Type;
                    dbAdapter.EnsureTable <T>(tableName, addressMap.PrimaryPropertyName);
                    dbAdapter.Open();
                    count = dbAdapter.SelectCount(tableName, conditions, multiConditionOperators);
                }
                catch (Exception exception)
                {
                    Debug.LogException(exception);
                }
                finally
                {
                    dbAdapter.Dispose();
                }
            }

            return(count);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets all data table rows.
        /// </summary>
        /// <typeparam name="T">The type definition of data table row.</typeparam>
        /// <returns>The object array of type definition.</returns>
        public T[] GetAllDataTableRows <T>() where T : DataTableRow, new()
        {
            DataTableAddressMap addressMap = GetDatabaseAddressMap <T>();
            BoxDBAdapter        dbAdapter  = GetDatabaseBoxAdapter(addressMap);
            List <T>            results    = new List <T>();

            if (dbAdapter != null)
            {
                try
                {
                    string tableName = addressMap.Type;
                    dbAdapter.EnsureTable <T>(tableName, addressMap.PrimaryPropertyName);
                    dbAdapter.Open();
                    results = dbAdapter.SelectAll <T>(tableName);
                }
                catch (Exception exception)
                {
                    Debug.LogException(exception);
                }
                finally
                {
                    dbAdapter.Dispose();
                }
            }

            return(results.ToArray());
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the database address.
        /// </summary>
        /// <typeparam name="T">The type definition of data.</typeparam>
        /// <returns>The database address.</returns>
        private DataTableAddressMap GetDatabaseAddressMap <T>()
        {
            string name = typeof(T).Name;

            if (addressMapDBAdapter == null)
            {
                Initialize();
            }

            DataTableAddressMap addressMap = addressMapDBAdapter.Select <DataTableAddressMap>(typeof(DataTableAddressMap).Name, name);

            return(addressMap);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the adapter of database.
        /// </summary>
        /// <param name="addressMap">The object of DataTableAddressMap.</param>
        /// <returns>The adapter of database.</returns>
        private BoxDBAdapter GetDatabaseBoxAdapter(DataTableAddressMap addressMap)
        {
            BoxDBAdapter dbAdapter = null;

            if (addressMap != null && addressMap.LocalAddress > 1)
            {
                if (preferencesData.DataTablesStorageLocation == DataTableStorageLocation.ResourcesPath)
                {
                    TextAsset binAsset = Resources.Load <TextAsset>(DataTablesStorageFolderName + "/db" + addressMap.LocalAddress);

                    if (binAsset)
                    {
                        dbAdapter = new BoxDBAdapter(databasePath, binAsset.bytes);
                    }
                }
                else
                {
                    dbAdapter = new BoxDBAdapter(databasePath, addressMap.LocalAddress);
                }
            }

            return(dbAdapter);
        }