示例#1
0
 private void CheckAttributeParams(DBStorageParamsAttribute attrs)
 {
     if (attrs == null)
     {
         throw new DBStorageException("You should declare <DBStorageParams> attribute to your class");
     }
 }
示例#2
0
        internal DBStorage(Type classType, DBStorageParamsAttribute attrs)
        {
            try
            {
                CheckAttributeParams(attrs);

                ColumnBindings = new Dictionary <DBMemberInfo, DBColumnInfo>();
                ClassType      = classType;
                TableName      = attrs.CustomTableName ?? classType.Name;

                CheckProvidedType();
                SetupDatabaseManager(attrs.ConnectionString);
                InitBindings();
                _storages.Add(classType, this);
            }
            catch (DBStorageException innerException)
            {
                throw new DBStorageException(string.Format("Exception occured while creating DBStorage object for type {0}", classType),
                                             innerException);
            }
            Items = new Dictionary <Guid, DBStorageItem>();

            if (DatabaseManager.IsTablePresent(TableName))
            {
                DataAdapter = DatabaseManager.CreateDataAdapter(TableName);
                SetupDataTable();

                if (AreColumnsCorrect())
                {
                    LoadFromDisk();
                    return;
                }
                else
                {
                    DatabaseManager.DropTable(TableName);
                }
            }
            DatabaseManager.ConstructTable(TableName, ColumnBindings);
            DataAdapter = DatabaseManager.CreateDataAdapter(TableName);
            SetupDataTable();

            DatabaseManager.AddTable(DataTable);
            DataAdapter.Fill(DataTable);
        }
示例#3
0
 public SQLiteStorage(Type classType, DBStorageParamsAttribute attrs)
     : base(classType, attrs)
 {
 }