public void Execute() { // Wrap the upgrade in a single commit. using (var updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)) { // bug #8924: disable validation to avoid deadlocks ((UpdateContext)updateContext).DisableValidation(); // Update SQL var upgradeBroker = updateContext.GetBroker <IUpgradeBroker>(); upgradeBroker.ExecuteSql(GetScript()); // Update the db version string var broker = updateContext.GetBroker <IPersistentStoreVersionBroker>(); var where = new PersistentStoreVersionSearchCriteria(); // only 1 row in the database. var version = broker.FindOne(where); version.Revision = DestinationVersion.Revision.ToString(); version.Build = DestinationVersion.Build.ToString(); version.Minor = DestinationVersion.Minor.ToString(); version.Major = DestinationVersion.Major.ToString(); updateContext.Commit(); } }
private Version QueryVersion() { try { using (var read = OpenReadContext()) { var broker = read.GetBroker<IPersistentStoreVersionBroker>(); var criteria = new PersistentStoreVersionSearchCriteria(); criteria.Major.SortDesc(0); criteria.Minor.SortDesc(1); criteria.Build.SortDesc(2); criteria.Revision.SortDesc(3); var versions = broker.Find(criteria); if (versions.Count == 0) return Assembly.GetExecutingAssembly().GetName().Version; var version = CollectionUtils.FirstElement(versions); return new Version( int.Parse(version.Major), int.Parse(version.Minor), int.Parse(version.Build), int.Parse(version.Revision)); } } catch (Exception e) { Platform.Log(LogLevel.Error, e); return Assembly.GetExecutingAssembly().GetName().Version; } }
public void Execute() { // Wrap the upgrade in a single commit. using (var updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)) { // bug #8924: disable validation to avoid deadlocks ((UpdateContext)updateContext).DisableValidation(); // Update SQL var upgradeBroker = updateContext.GetBroker<IUpgradeBroker>(); upgradeBroker.ExecuteSql(GetScript()); // Update the db version string var broker = updateContext.GetBroker<IPersistentStoreVersionBroker>(); var where = new PersistentStoreVersionSearchCriteria(); // only 1 row in the database. var version = broker.FindOne(where); version.Revision = DestinationVersion.Revision.ToString(); version.Build = DestinationVersion.Build.ToString(); version.Minor = DestinationVersion.Minor.ToString(); version.Major = DestinationVersion.Major.ToString(); updateContext.Commit(); } }