本文整理汇总了C#中SessionNoServer.BeginUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# SessionNoServer.BeginUpdate方法的具体用法?C# SessionNoServer.BeginUpdate怎么用?C# SessionNoServer.BeginUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SessionNoServer
的用法示例。
在下文中一共展示了SessionNoServer.BeginUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TwoUpdaters1
public void TwoUpdaters1()
{
Assert.Throws<OptimisticLockingFailed>(() =>
{
UInt64 id;
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
Man man = new Man();
man.Persist(session, man);
id = man.Id;
session.Commit();
session.BeginUpdate();
man.Age = ++man.Age;
Database db = session.NewDatabase(3567);
using (SessionNoServer session2 = new SessionNoServer(systemDir))
{
session2.BeginUpdate();
Man man2 = (Man)session2.Open(id);
Assert.Less(man2.Age, man.Age);
man2.Age = ++man.Age;
session2.Commit();
}
session.DeleteDatabase(db);
session.Commit(); // OptimisticLockingFailed here
}
});
}
示例2: aaaFakeLicenseDatabase
public void aaaFakeLicenseDatabase()
{
Assert.Throws<NoValidVelocityDBLicenseFoundException>(() =>
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
Database database;
License license = new License("Mats", 1, null, null, null, 99999, DateTime.MaxValue, 9999, 99, 9999);
Placement placer = new Placement(License.PlaceInDatabase, 1, 1, 1);
license.Persist(placer, session);
for (uint i = 10; i < 20; i++)
{
database = session.NewDatabase(i);
Assert.NotNull(database);
}
session.Commit();
File.Copy(Path.Combine(systemDir, "20.odb"), Path.Combine(systemDir, "4.odb"));
session.BeginUpdate();
for (uint i = 21; i < 30; i++)
{
database = session.NewDatabase(i);
Assert.NotNull(database);
}
session.RegisterClass(typeof(VelocityDbSchema.Samples.Sample1.Person));
Graph g = new Graph(session);
session.Persist(g);
session.Commit();
}
});
}
示例3: Main
static readonly string s_systemDir = "JsonExportImport"; // appended to SessionBase.BaseDatabasePath
static void Main(string[] args)
{
try
{
int personCt = 0;
using (SessionBase session = new SessionNoServer(s_systemDirToImport))
{
session.BeginRead();
IEnumerable<string> personStringEnum = session.ExportToJson<Person>();
using (SessionBase sessionImport = new SessionNoServer(s_systemDir))
{
sessionImport.BeginUpdate();
foreach (string json in personStringEnum)
{
Person person = sessionImport.ImportJson<Person>(json);
sessionImport.Persist(person);
personCt++;
}
session.Commit();
sessionImport.Commit();
Console.WriteLine("Imported " + personCt + " from Json strings");
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
示例4: Main
static readonly string systemDir = "QuickStart"; // appended to SessionBase.BaseDatabasePath
static int Main(string[] args)
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
try
{
session.BeginUpdate();
Company company = new Company();
company.Name = "MyCompany";
session.Persist(company);
Employee employee1 = new Employee();
employee1.Employer = company;
employee1.FirstName = "John";
employee1.LastName = "Walter";
session.Persist(employee1);
session.Commit();
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
session.Abort();
}
}
Retrieve();
return 0;
}
示例5: CreateLocationSameHost
public void CreateLocationSameHost()
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
DatabaseLocation remoteLocation = new DatabaseLocation(Dns.GetHostName(), location2Dir, locationStartDbNum, locationEndDbNum, session, PageInfo.compressionKind.LZ4, 0);
remoteLocation = session.NewLocation(remoteLocation);
Database database = session.NewDatabase(remoteLocation.StartDatabaseNumber);
Assert.NotNull(database);
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
Database database = session.OpenDatabase(locationStartDbNum, false);
Assert.NotNull(database);
session.DeleteDatabase(database);
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
foreach (DatabaseLocation loc in session.DatabaseLocations)
Console.WriteLine(loc.ToStringDetails(session, false));
session.DeleteLocation(session.DatabaseLocations.LocationForDb(locationStartDbNum));
foreach (DatabaseLocation loc in session.DatabaseLocations)
Console.WriteLine(loc.ToStringDetails(session, false));
session.Commit();
}
}
示例6: SingleReaderSingleUpdater1
public void SingleReaderSingleUpdater1()
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
Man man = new Man();
man.Persist(session, man);
session.Commit();
}
UInt64 id;
using (SessionNoServer session = new SessionNoServer(systemDir, 5000))
{
session.BeginUpdate();
Man man = new Man();
man.Persist(session, man);
id = man.Id;
using (SessionNoServer session2 = new SessionNoServer(systemDir))
{
session2.BeginRead();
Man man2 = (Man)session2.Open(id);
Assert.Null(man2);
session2.Commit();
}
session.Commit();
}
}
示例7: CompareString
public void CompareString(int compArraySize)
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
AllSupported obj = new AllSupported(1);
CompareByField<AllSupported> compareByField = new CompareByField<AllSupported>("aString", session);
BTreeSet<AllSupported> sortedSet = new BTreeSet<AllSupported>(compareByField, session, 1000, (ushort) compArraySize);
for (int i = 0; i < 10000; i++)
{
obj = new AllSupported(1);
obj.aString = RandomString(10);
sortedSet.Add(obj);
}
obj = new AllSupported(1);
obj.aString = null;
sortedSet.Add(obj);
int ct = 0;
AllSupported prior = null;
foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet)
{
if (prior != null)
{
if (prior.aString != null)
if (currentObj.aString == null)
Assert.Fail("Null is < than a non NULL");
else
Assert.Less(prior.aString, currentObj.aString);
}
prior = currentObj;
ct++;
}
session.Commit();
}
}
示例8: hashCodeComparerStringTest
public void hashCodeComparerStringTest()
{
Oid id;
using (SessionNoServer session = new SessionNoServer(systemDir))
{
Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
session.Compact();
session.BeginUpdate();
HashCodeComparer<string> hashCodeComparer = new HashCodeComparer<string>();
BTreeSet<string> bTree = new BTreeSet<string>(hashCodeComparer, session);
bTree.Persist(place, session);
id = bTree.Oid;
for (int i = 0; i < 100000; i++)
{
bTree.Add(i.ToString());
}
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginRead();
BTreeSet<string> bTree= (BTreeSet<string>)session.Open(id);
int count = 0;
foreach (string str in bTree)
{
count++;
}
Assert.True(100000 == count);
session.Commit();
}
}
示例9: Main
static readonly string systemDir = "Sample3"; // appended to SessionBase.BaseDatabasePath
static void Main(string[] args)
{
try
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
session.BeginUpdate();
Person robinHood = new Person("Robin", "Hood", 30);
Person billGates = new Person("Bill", "Gates", 56, robinHood);
Person steveJobs = new Person("Steve", "Jobs", 56, billGates);
robinHood.BestFriend = billGates;
session.Persist(steveJobs);
steveJobs.Friends.Add(billGates);
steveJobs.Friends.Add(robinHood);
billGates.Friends.Add(billGates);
robinHood.Friends.Add(steveJobs);
session.Commit();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
示例10: GermanString
public void GermanString()
{
UInt64 id = 0;
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
using (var trans = new TransactionScope())
{
session.BeginUpdate();
VelocityDbSchema.Person person = new VelocityDbSchema.Person();
person.LastName = "Med vänliga hälsningar";
id = session.Persist(person);
trans.Complete();
}
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
using (var trans = new TransactionScope())
{
session.BeginUpdate();
VelocityDbSchema.Person person = session.Open<VelocityDbSchema.Person>(id);
person.LastName = "Mit freundlichen Grüßen";
trans.Complete();
}
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
using (var trans = new TransactionScope())
{
session.BeginUpdate();
VelocityDbSchema.Person person = session.Open<VelocityDbSchema.Person>(id);
person.LastName = "Med vänliga hälsningar";
trans.Complete();
}
}
}
示例11: AddSomeBicycles
public void AddSomeBicycles()
{
try
{
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginUpdate();
for (int i = 0; i < 1000000; i++)
{
Bicycle bicycle = new Bicycle();
bicycle.Color = "red";
session.Persist(bicycle);
}
for (int i = 0; i < 10; i++)
{
Bicycle bicycle = new Bicycle();
bicycle.Color = "blue";
session.Persist(bicycle);
}
for (int i = 0; i < 10; i++)
{
Bicycle bicycle = new Bicycle();
bicycle.Color = "yellow";
session.Persist(bicycle);
}
session.Commit();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
示例12: CreateData
static void CreateData()
{
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
bool dirExist = Directory.Exists(session.SystemDirectory);
if (dirExist)
Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
Directory.CreateDirectory(session.SystemDirectory);
File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
DataCache.MaximumMemoryUse = 10000000000; // 10 GB, set this to what fits your case
SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4;
session.BeginUpdate();
BTreeMap<Int64, VelocityDbList<Person>> btreeMap = new BTreeMap<Int64, VelocityDbList<Person>>(null, session);
session.Persist(btreeMap);
for (int i = 0; i < 100000; i++)
{
Person p = new Person();
GeoHash geohash = GeoHash.WithBitPrecision(p.Lattitude, p.Longitude);
VelocityDbList<Person> personList;
if (btreeMap.TryGetValue(geohash.LongValue, out personList))
personList.Add(p);
else
{
personList = new VelocityDbList<Person>(1);
//session.Persist(p);
personList.Add(p);
session.Persist(personList);
btreeMap.Add(geohash.LongValue, personList);
}
}
session.Commit();
}
}
示例13: LocalDateTest
public void LocalDateTest()
{
LocalDate d1 = new LocalDate(2016, 1, 10);
LocalDate d2 = new LocalDate(2016, 1, 1);
LocalDate d1other = new LocalDate(2016, 1, 10);
Assert.AreNotEqual(d1, d2);
Assert.AreEqual(d1, d1other);
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
LocalDateField test1 = new LocalDateField("def", d1);
session.Persist(test1);
LocalDateField test = new LocalDateField("abc", d2);
session.Persist(test);
var result1 = session.AllObjects<LocalDateField>().First(t => t.Field2.Equals(d2)); // this works
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginRead();
var result2 = session.AllObjects<LocalDateField>().First(t =>
{
var l = t.Field2;
return l.Equals(d2);
}); // this should work and doesnt
session.Commit();
}
}
示例14: CreateData
static void CreateData()
{
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
bool dirExist = Directory.Exists(session.SystemDirectory);
if (dirExist)
{
return;
Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
}
Directory.CreateDirectory(session.SystemDirectory);
File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4;
session.BeginUpdate();
CompareGeoObj comparer = new CompareGeoObj();
var btreeSet = new BTreeSet<GeoObj>(comparer, session, 1000);
for (int i = 0; i < s_numberOfSamples; i++)
{
var g = new GeoObj();
btreeSet.Add(g);
}
session.Persist(btreeSet);
session.Commit();
Console.Out.WriteLine([email protected]"Done creating {s_numberOfSamples} GeoHashSample GeoObj ");
}
}
示例15: bSyncDeletedDatabases
public void bSyncDeletedDatabases()
{
using (SessionBase session = new SessionNoServer(s_sync1))
{
using (var trans = session.BeginUpdate())
{
for (uint i = 10; i < 14; i++)
{
var database = session.OpenDatabase(i);
session.DeleteDatabase(database);
}
session.Commit();
}
}
using (SessionBase readFromSession = new SessionNoServer(s_sync1))
{
using (SessionBase updateSession = new SessionNoServer(s_sync2))
{
updateSession.SyncWith(readFromSession);
}
}
using (SessionBase readFromSession = new SessionNoServer(s_sync1))
{
readFromSession.BeginRead();
using (SessionBase updateSession = new SessionNoServer(s_sync2))
{
using (var trans = updateSession.BeginRead())
{
Assert.AreEqual(updateSession.OpenAllDatabases().Count, readFromSession.OpenAllDatabases().Count - 1); // - 1 due to additional change tracking databases in original
}
}
}
}