Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// Initializes.
        /// </summary>
        private void Initialize()
        {
            preferencesData = Resources.Load <DataTablePreferences>("DataTablePreferences");
            databasePath    = Path.Combine(Application.persistentDataPath, DataTablesStorageFolderName);

            if (preferencesData && preferencesData.DataTablesStorageLocation == DataTableStorageLocation.StreamingAssetsPath)
            {
                databasePath = Path.Combine(Application.streamingAssetsPath, DataTablesStorageFolderName);
            }

            if (preferencesData && preferencesData.DataTablesStorageLocation == DataTableStorageLocation.ResourcesPath)
            {
                TextAsset binAsset = Resources.Load <TextAsset>(DataTablesStorageFolderName + "/db1");

                if (binAsset)
                {
                    addressMapDBAdapter = new BoxDBAdapter(databasePath, binAsset.bytes);
                }
            }
            else
            {
                addressMapDBAdapter = new BoxDBAdapter(databasePath);
            }

            addressMapDBAdapter.EnsureTable <DataTableAddressMap>(typeof(DataTableAddressMap).Name, DataTableAddressMap.PrimaryKey);
            addressMapDBAdapter.Open();
        }
Exemple #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());
        }
Exemple #4
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);
        }
        /// <summary>
        /// Gets the box database adapter.
        /// </summary>
        /// <returns>The BoxDBAdapter object.</returns>
        private BoxDBAdapter GetBoxDBAdapter()
        {
            BoxDBAdapter db = new BoxDBAdapter(Application.persistentDataPath);

            db.EnsureTable <BoxDBAdapterTestVO>(tableName, "Id");
            db.Open();
            return(db);
        }