/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new db4o database. Removes old one if exists. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateInternal() { BasicInit(); try { if (m_localHost) { Db4oServerInfo info = GetDb4OServerInfo(m_host, Db4OServerFinder.ServiceDiscoveryPort); info.CreateServerFile(ProjectId.Name); // Ask Service for connection port. RequestDatabaseStart(); } StartClientOnRemoteServer(); // Store model version number; m_modelVersionNumber = new ModelVersionNumber { m_modelVersionNumber = m_modelVersionOverride }; m_dbStore.Store(m_modelVersionNumber); m_dbStore.Commit(); } catch (SocketException e) { throw new StartupException(string.Format(Strings.ksCannotConnectToServer, "FwRemoteDatabaseConnectorService"), e); } catch (Exception err) { StopClient(); RequestServerShutdown(); throw; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start up the back end. /// </summary> /// <param name="currentModelVersion">The current model version.</param> /// <returns>The data store's current version number.</returns> /// ------------------------------------------------------------------------------------ protected override int StartupInternal(int currentModelVersion) { BasicInit(); // Ask Service for connection port. RequestDatabaseStart(); // Currently we don't support local-client mode. //if (m_localHost) //{ // OpenServerFile(); // StartClientOnLocalServer(); //} //else StartClientOnRemoteServer(); // DB4O always returns current state of objects when queries are done - need to use // lock so we can get a consistent state for starting. GetCommitLock(true); try { //--( Load model version number, and check against current number. )--// m_modelVersionNumber = m_dbStore.Query<ModelVersionNumber>()[0]; var currentDataStoreVersion = m_modelVersionNumber.m_modelVersionNumber; var needConversion = (currentDataStoreVersion != currentModelVersion); if (m_restarting) { Debug.Assert(currentDataStoreVersion == currentModelVersion); m_restarting = false; // need to set explicitly before each call. return currentDataStoreVersion; } //--( Load custom fields )--/ var customFields = new List<CustomFieldInfo>(); foreach (CustomFieldInfo customField in m_dbStore.Query<CustomFieldInfo>().ToArray()) { CustomFieldInfo dupInfo; if (m_myKnownCustomFields.TryGetValue(customField.Key, out dupInfo)) { // This should never happen, but somehow some databases are around which have the problem. // Try to correct it. (The flids may not match exactly. See LT-11486.) if (dupInfo.AlmostEquals(customField)) { m_dbStore.Delete(customField); m_dbStore.Commit(); continue; } // If they are NOT (almost) equal, we will go ahead and crash :-< } customFields.Add(customField); m_myKnownCustomFields.Add(customField.Key, customField); } RegisterOriginalCustomProperties(customFields); //--( Load surrogates )--/ var generations = from CommitData cd in m_dbStore select cd.WriteGeneration; m_lastWriteGenerationSeen = 0; if (generations.Count() > 0) m_lastWriteGenerationSeen = generations.Max(); Db4oServerInfo info = GetDb4OServerInfo(m_host, Db4OServerFinder.ServiceDiscoveryPort); long[] ids; var objs = info.GetCmObjectSurrogates(ProjectId.Name); using (var decompressoar = new CmObjectSurrogateStreamDecompressor(objs, m_cache, m_identityMap, m_idMap)) { foreach (CmObjectSurrogate surrogate in decompressoar) { if (needConversion) RegisterSurrogateForConversion(surrogate); else RegisterInactiveSurrogate(surrogate); } } return currentDataStoreVersion; } catch (SocketException e) { throw new StartupException(string.Format(Strings.ksCannotConnectToServer, "FwRemoteDatabaseConnectorService"), e); } finally { ReleaseCommitLock(); } }