File: MATableMaintenanceController.m

package info (click to toggle)
mysql-gui-tools 5.0r12-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 105,540 kB
  • ctags: 50,897
  • sloc: sql: 348,439; pascal: 285,780; cpp: 94,578; ansic: 90,768; objc: 33,761; sh: 25,629; xml: 10,924; yacc: 10,755; java: 9,986; php: 2,806; python: 2,068; makefile: 1,945; perl: 3
file content (245 lines) | stat: -rw-r--r-- 8,038 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#import "MATableMaintenanceController.h"
#import <MySQLToolsCommon/MMySQLDispatcher.h>
#include "myx_admin_public_interface.h"

@implementation MATableMaintenanceController

- (char*)tableList
{
  unsigned int i;
  NSMutableString *list= [[[NSMutableString alloc] init] autorelease];
  for (i= 0; i < [_tables count]; i++)
  {
    if (i > 0)
      [list appendFormat:@" %@",[_tables objectAtIndex:i]];
    else
      [list appendFormat:@"%@",[_tables objectAtIndex:i]];    
  }
  return g_strdup([list UTF8String]);
}

- (void)operationFinished:(id)arg result:(void*)result
{
  MYX_TABLE_COMMAND_STATUSES *status= (MYX_TABLE_COMMAND_STATUSES*)result;
  unsigned int i;
  NSMutableAttributedString *text= [resultText textStorage];
  NSAttributedString *table, *statu, *warning, *error, *info;
  NSDictionary *bold= [NSDictionary dictionaryWithObject:[NSFont boldSystemFontOfSize:[NSFont systemFontSize]] 
                                                  forKey:NSFontAttributeName];

  table= [[[NSAttributedString alloc] initWithString:@"Table: "
                                          attributes:bold] autorelease];
  statu= [[[NSAttributedString alloc] initWithString:@"Status: "
                                           attributes:bold] autorelease];
  warning= [[[NSAttributedString alloc] initWithString:@"WARNING: "
                                           attributes:bold] autorelease];
  error= [[[NSAttributedString alloc] initWithString:@"ERROR: "
                                           attributes:bold] autorelease];
  info= [[[NSAttributedString alloc] initWithString:@"Info: "
                                           attributes:bold] autorelease];
  
  for (i= 0; i < status->status_num; i++)
  {
    [text appendAttributedString:table];
    [text appendAttributedString:[[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %s ",status->status[i].table]] autorelease]];
    switch (status->status[i].message_type)
    {
      case MYX_MESSAGE_STATUS:
        [text appendAttributedString:statu];
        break;
      case MYX_MESSAGE_ERROR:
        [text appendAttributedString:error];
        break;
      case MYX_MESSAGE_WARNING:
        [text appendAttributedString:warning];
        break;
      case MYX_MESSAGE_INFO:
        [text appendAttributedString:info];
        break;
    }
    [text appendAttributedString:[[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"   %s\n",status->status[i].message]] autorelease]];
  }

  [progress stopAnimation:self];
  [continueButton setTitle:@"Close"];

  [continueButton setEnabled:YES];
  [resultLabel2 setStringValue:@""];

  if ([[operationMatrix cellWithTag:0] state] == NSOnState)
  {
    [resultDescription setStringValue:@"The selected tables were optimized."];
  }
  else if ([[operationMatrix cellWithTag:1] state] == NSOnState)
  {
    [resultDescription setStringValue:@"The selected tables were checked."];
  }
  else
  {
    [resultDescription setStringValue:@"The selected tables were repaired."];
  }
  g_free((char*)arg);
}

- (void)dealloc
{
  [_tables release];
  [super dealloc];
}

- (void)runWithTables:(NSArray*)tables dispatcher:(MMySQLDispatcher*)dispatcher
            operation:(int)op
{
  NSMutableString *list= [[NSMutableString alloc] init];
  unsigned int i;
  
  _tables= [tables retain];
  _dispatcher= dispatcher;
  for (i= 0; i < [tables count]; i++)
  {
    if (i > 0)
      [list appendFormat:@"\n%@",[tables objectAtIndex:i]];
    else
      [list appendFormat:@"%@",[tables objectAtIndex:i]];
  }
  [selectionText setString:[NSString stringWithString:list]];
  [list release];
  
  switch (op)
  {
    case 'O':
      [[operationMatrix cellWithTag:0] performClick:nil];
      [self goNext:nil];
      break;
    case 'C':
      [[operationMatrix cellWithTag:1] performClick:nil];
      [self goNext:nil];
      break;
    case 'R':
      [[operationMatrix cellWithTag:2] performClick:nil];
      [self goNext:nil];
      break;
    default:
      break;
  }

  [NSApp runModalForWindow:[self window]];
}

- (IBAction)cancel:(id)sender
{
  [NSApp stopModalWithCode:0];
}

- (IBAction)goNext:(id)sender
{
  NSString *ident= [[tabView selectedTabViewItem] identifier];
  
  if ([ident isEqualToString:@"main"])
  {
    if ([[operationMatrix cellWithTag:0] state] == NSOnState)
    {
      [resultLabel setStringValue:[[operationMatrix cellWithTag:0] title]];
      [resultDescription setStringValue:@"Optimizing selected tables. This may take a few minutes..."];
      [tabView selectTabViewItemWithIdentifier:@"optimize"];
    }
    else if ([[operationMatrix cellWithTag:1] state] == NSOnState)
    {
      [resultLabel setStringValue:[[operationMatrix cellWithTag:1] title]];
      [resultDescription setStringValue:@"Checking selected tables. This may take a few minutes..."];
      [tabView selectTabViewItemWithIdentifier:@"check"];
    }
    else
    {
      [resultLabel setStringValue:[[operationMatrix cellWithTag:2] title]];
      [resultDescription setStringValue:@"Attempting repair of selected tables. This may take a few minutes..."];
      [tabView selectTabViewItemWithIdentifier:@"repair"];
    }
    [resultLabel2 setStringValue:@"Please wait..."];
  }
  else if ([ident isEqualToString:@"check"])
  {
    int mask= 0;
    char *tables= [self tableList];
    
    if ([[repairMatrix cellWithTag:0] state] == NSOnState)
      mask|= MYX_CHECK_QUICK;
    if ([[repairMatrix cellWithTag:1] state] == NSOnState)
      mask|= MYX_CHECK_FAST;
    if ([[repairMatrix cellWithTag:2] state] == NSOnState)
      mask|= MYX_CHECK_MEDIUM;
    if ([[repairMatrix cellWithTag:3] state] == NSOnState)
      mask|= MYX_CHECK_EXTENDED;
    if ([[repairMatrix cellWithTag:4] state] == NSOnState)
      mask|= MYX_CHECK_CHANGED;
    
    [_dispatcher performCallback:(void*(*)(MYSQL*,void*,void*))myx_check_table
                       argument:tables
                       argument:(void*)mask
               finishedSelector:@selector(operationFinished:result:)
                       argument:(id)tables
                         target:self];
    
    [continueButton setEnabled:NO];
    [progress startAnimation:nil];
    [tabView selectTabViewItemWithIdentifier:@"result"];
  }
  else if ([ident isEqualToString:@"repair"])
  {
    int mask= 0;
    char *tables= [self tableList];
    
    if ([[repairMatrix cellWithTag:0] state] == NSOnState)
      mask|= MYX_CHECK_QUICK;
    if ([[repairMatrix cellWithTag:1] state] == NSOnState)
      mask|= MYX_CHECK_EXTENDED;
    if ([[repairMatrix cellWithTag:2] state] == NSOnState)
      mask|= MYX_REPAIR_USE_FRM;
    if ([repairLocalCheck state] == NSOnState)
      mask|= MYX_REPAIR_NO_WRITE_TO_BINLOG;

    [_dispatcher performCallback:(void*(*)(MYSQL*,void*,void*))myx_repair_table
                       argument:tables
                       argument:(void*)mask
               finishedSelector:@selector(operationFinished:result:)
                       argument:(id)tables
                         target:self];
    
    [continueButton setEnabled:NO];
    [progress startAnimation:nil];
    [tabView selectTabViewItemWithIdentifier:@"result"];
  }
  else if ([ident isEqualToString:@"optimize"])
  {
    int mask= 0;
    char *tables= [self tableList];
    
    if ([optimizeLocalCheck state] == NSOnState)
      mask|= MYX_REPAIR_NO_WRITE_TO_BINLOG;
    
    [_dispatcher performCallback:(void*(*)(MYSQL*,void*,void*))myx_optimize_table
                       argument:tables
                       argument:(void*)mask
               finishedSelector:@selector(operationFinished:result:)
                       argument:(id)tables
                         target:self];
    
    [continueButton setEnabled:NO];
    [progress startAnimation:nil];
    [tabView selectTabViewItemWithIdentifier:@"result"];
  }
  else if ([ident isEqualToString:@"result"])
  {
    [NSApp stopModalWithCode:1];    
  }
  else
    [progress startAnimation:nil];
}


-(void)windowDidClose:(NSNotification*)notif
{
  [NSApp abortModal];
}

@end