!=========================================================================
! Copyright (C) VMware, Inc. 1986-2011.  All Rights Reserved.
!
! Name - upgradeAllSymbols.topaz
!
! Purpose:
!       Convert AllSymbols from a CanonicalStringDictionary 
!       to a CanonStringDict and change the reserved objId of AllSymbols
!       for Gemstone2G to Gemstone64 repository conversion.
!      
!       Also used in Gemstone64 initial filein, to convert the AllSymbols
!       produced by bom.c to the new AllSymbols . 
!
! $Id: upgradeAllSymbols.topaz,v 1.14 2008-01-09 22:50:20 stever Exp $
!
!=======================================================================


!------------------------------------------------------------
! migrate AllSymbols from  old format to new format
input $upgradeDir/migratesyms.gs

expectvalue %String
run
System stopSymbolCreationSession  .
System stopAllGcSessions .
System sleep: 5 .
^ System currentSessionNames
%
time

expectvalue %String
run
"This compilation and execution must not create any new Symbols.
 While the SymbolGem is shutdown, any new Symbol creation will hang.
 The block will commit and return true if successful.

 For Gemstone upgrade from 2G to Gemstone64 1.0 or 1.1, 
 the block will be executed.  
 For upgrade from Gemstone64 1.0 to 1.1 , do nothing.
"
| oldDict |
oldDict := Globals at:#AllSymbols otherwise: nil .
oldDict == nil ifTrue:[ | symUser |
  symUser := AllUsers userWithId:'SymbolUser' .
  oldDict := (symUser resolveSymbol: #AllSymbols) value .
].
oldDict class == CanonicalStringDictionary ifTrue:[
  ^ (Globals at:#MigrateAllSymbolsBlock) value .
].
oldDict _validateInstanceOf: CanonSymbolDict .
^ 'no conversion needed'
%
! after evaluating MigrateAllSymbolsBlock, must logout and login
!  to reset object manager state .
logout
login

time
expectvalue %String
run
System startSymbolCreationSession .
System sleep: 5 .
^ System currentSessionNames
%
time

expectvalue true
run
| allSyms |
allSyms := Globals at:#AllSymbols otherwise: nil .
allSyms ~~ nil ifTrue:[ | symUser ugDict |
  allSyms _validateInstanceOf: CanonSymbolDict .
  symUser := AllUsers userWithId:'SymbolUser' .
  ugDict := (symUser resolveSymbol: #UserGlobals) value .
  Globals removeKey: #AllSymbols .
  ugDict at: #AllSymbols put: allSyms 
].
Globals removeKey: #MigrateAllSymbolsBlock .
^ true
%

commit

