示例#1
0
        public static void Drop(string tableName)
        {
            lock (_sLockObj)
            {
                if (_sNeedClose)
                {
                    return;
                }

                _sCanClose = false;
            }

            try
            {
                tableName = Setting.GetTableFullName(tableName);

                DBProvider dbProvider = GetDBProvider(tableName, false);


                if (dbProvider != null)
                {
                    if (dbProvider.Table != null)
                    {
                        if (!dbProvider.Table.IsBigTable)
                        {
                            if (!dbProvider.Table.IndexOnly)
                            {
                                dbProvider.DBAdapter.Drop();
                            }
                            else
                            {
                                if (dbProvider.MirrorDBAdapter != null)
                                {
                                    dbProvider.MirrorDBAdapter.Drop();
                                }
                            }
                        }
                    }

                    if (!dbProvider._TableLock.Enter(Lock.Mode.Mutex, 30000))
                    {
                        throw new TimeoutException();
                    }

                    try
                    {
                        string dir = dbProvider.Directory;

                        if (dir == null)
                        {
                            DeleteTableName(tableName);
                            return;
                        }

                        dbProvider.Drop();
                        DeleteTableName(tableName);

                        Global.Setting.RemoveTableConfig(dir, tableName);
                        Global.Setting.Save();
                    }
                    finally
                    {
                        dbProvider._TableLock.Leave(Lock.Mode.Mutex);
                    }
                }
            }
            finally
            {
                lock (_sLockObj)
                {
                    _sCanClose = true;
                }
            }
        }
示例#2
0
        public static void CreateTable(Table table, string directory)
        {
            lock (_sLockObj)
            {
                if (_sNeedClose)
                {
                    return;
                }

                _sCanClose = false;
            }

            try
            {
                if (table.Name == null)
                {
                    throw new System.ArgumentNullException("Null table name");
                }

                if (table.Name.Trim() == "")
                {
                    throw new System.ArgumentException("Empty table name");
                }

                table.Name = Setting.GetTableFullName(table.Name.Trim());

                if (DBProvider.DBProviderExists(table.Name))
                {
                    throw new DataException(string.Format("Table {0} exists already!", table.Name));
                }

                directory = Hubble.Framework.IO.Path.AppendDivision(directory, '\\');

                if (!System.IO.Directory.Exists(directory))
                {
                    System.IO.Directory.CreateDirectory(directory);
                }

                DBProvider.NewDBProvider(table.Name, new DBProvider());

                try
                {
                    DBProvider.GetDBProvider(table.Name, false).Create(table, directory);
                }
                catch (Exception e)
                {
                    Global.Report.WriteErrorLog("Create table fail!", e);

                    DBProvider.Drop(table.Name);

                    throw e;
                }
            }
            finally
            {
                lock (_sLockObj)
                {
                    _sCanClose = true;
                }
            }
        }