public void HideCursor() { Active = false; currentConfig = null; CursorSprite.Swap(TransparentSprite); }
public void GetSecondaryCursurWithTxn(string home, string name, bool ifCfg) { string dbFileName = name + ".db"; SecondaryCursor cursor; // Open env. DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseTxns = true; envConfig.UseMPool = true; DatabaseEnvironment env = DatabaseEnvironment.Open(home, envConfig); // Open primary/secondary database. Transaction txn = env.BeginTransaction(); BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; BTreeDatabase db = BTreeDatabase.Open(dbFileName, dbConfig, txn); SecondaryBTreeDatabaseConfig secDBConfig = new SecondaryBTreeDatabaseConfig(db, new SecondaryKeyGenDelegate(SecondaryKeyGen)); secDBConfig.Env = env; SecondaryBTreeDatabase secDB = SecondaryBTreeDatabase.Open(dbFileName, secDBConfig, txn); for (int i = 0; i < 10; i++) { db.Put(new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(BitConverter.GetBytes((int)i)), txn); } // Create secondary cursor. if (ifCfg == false) { secDB.SecondaryCursor(txn); } else if (ifCfg == true) { CursorConfig cursorConfig = new CursorConfig(); cursorConfig.WriteCursor = false; cursor = secDB.SecondaryCursor(cursorConfig, txn); cursor.Close(); } secDB.Close(); db.Close(); txn.Commit(); env.Close(); }
/* * This simply counts the number of records contained in the * database and returns the result. You can use this method * in three ways: * * First call it with an active txn handle. * Secondly, configure the cursor for dirty reads * Third, call countRecords AFTER the writer has committed * its transaction. * * If you do none of these things, the writer thread will * self-deadlock. * * Note that this method exists only for illustrative purposes. * A more straight-forward way to count the number of records in * a database is to use the Database.getStats() method. */ private int CountRecords(Transaction txn) { int count = 0; Cursor cursor = null; try { // Get the cursor. CursorConfig cc = new CursorConfig(); /* * Isolation degree one is ignored if the * database was not opened for uncommitted * read support. TxnGuide opens its database * in this way and TxnGuideInMemory does not. */ cc.IsolationDegree = Isolation.DEGREE_ONE; cursor = db.Cursor(cc, txn); while (cursor.MoveNext()) { count++; } } finally { if (cursor != null) { cursor.Close(); } } return(count); }
public void GetCursur(string dbFileName, bool ifConfig) { HeapDatabaseConfig dbConfig = new HeapDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; HeapDatabase db = HeapDatabase.Open(dbFileName, dbConfig); HeapRecordId rid = db.Append( new DatabaseEntry(BitConverter.GetBytes((int)1))); Cursor cursor; CursorConfig cursorConfig = new CursorConfig(); cursorConfig.Priority = CachePriority.HIGH; if (ifConfig == false) { cursor = db.Cursor(); } else { cursor = db.Cursor(cursorConfig); } cursor.Add(new KeyValuePair <DatabaseEntry, DatabaseEntry>( new DatabaseEntry(rid.toArray()), new DatabaseEntry(BitConverter.GetBytes((int)2)))); Cursor dupCursor = cursor.Duplicate(false); Assert.IsNull(dupCursor.Current.Key); if (ifConfig) { Assert.AreEqual(CachePriority.HIGH, dupCursor.Priority); } dupCursor.Close(); cursor.Close(); db.Close(); }
/// <summary> /// 返回游标 /// </summary> /// <param name="config"></param> /// <param name="txn"></param> /// <returns></returns> public Cursor OpenCursor(CursorConfig config = null, Transaction txn = null) { if (config == null) { config = new CursorConfig(); } return(db.Cursor(config, txn)); }
private void GetMultipleDB(string dbFileName, BTreeDatabaseConfig dbConfig, Transaction txn, out BTreeDatabase db, out BTreeCursor cursor) { if (txn == null) { db = BTreeDatabase.Open(dbFileName, dbConfig); cursor = db.Cursor(); } else { db = BTreeDatabase.Open( dbFileName, dbConfig, txn); CursorConfig cursorConfig = new CursorConfig(); cursor = db.Cursor(cursorConfig, txn); } KeyValuePair <DatabaseEntry, DatabaseEntry> pair; DatabaseEntry key, data; for (int i = 1; i < 100; i++) { key = new DatabaseEntry(BitConverter.GetBytes(i)); data = new DatabaseEntry(BitConverter.GetBytes(i)); pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(key, data); cursor.Add(pair); } if (dbConfig.UseRecordNumbers == true) { byte[] bytes = new byte[512]; for (int i = 0; i < 512; i++) { bytes[i] = (byte)i; } key = new DatabaseEntry(BitConverter.GetBytes(100)); data = new DatabaseEntry(bytes); pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(key, data); cursor.Add(pair); } else { if (dbConfig.Duplicates == DuplicatesPolicy.UNSORTED || dbConfig.Duplicates == DuplicatesPolicy.SORTED) { key = new DatabaseEntry(BitConverter.GetBytes(99)); data = new DatabaseEntry(BitConverter.GetBytes(100)); pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(key, data); cursor.Add(pair); } key = new DatabaseEntry(BitConverter.GetBytes(101)); data = new DatabaseEntry(BitConverter.GetBytes(101)); pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(key, data); cursor.Add(pair); } }
void Awake() { //texNormal=(Texture)Resources.Load(StaticConfig.UIFilePath + "ICON/mouse_0"); //texSelect=(Texture)Resources.Load(StaticConfig.UIFilePath + "ICON/mouse_1"); Instance = this; //禁用默认鼠标指针 Screen.showCursor = false; //设置鼠标指针 SetCursorType(CursorType.Normal); }
void SetCursorConfig(CursorConfig cursorConfig) { if (cursorConfig == currentConfig) { return; } currentConfig = cursorConfig; StopAllCoroutines(); StartCoroutine(SetPivotHandler(CursorTransform.pivot, cursorConfig.Sprite.pivot / cursorConfig.Sprite.rect.height)); CursorSprite.Swap(cursorConfig.Sprite); }
public void TestConfig() { testName = "TestConfig"; /* * Configure the fields/properties and see if * they are updated successfully. */ CursorConfig cursorConfig = new CursorConfig(); XmlElement xmlElem = Configuration.TestSetUp( testFixtureName, testName); Config(xmlElem, ref cursorConfig, true); Confirm(xmlElem, cursorConfig, true); }
public static void Config(XmlElement xmlElement, ref CursorConfig cursorConfig, bool compulsory) { Configuration.ConfigIsolation(xmlElement, "IsolationDegree", ref cursorConfig.IsolationDegree, compulsory); Configuration.ConfigCachePriority(xmlElement, "Priority", ref cursorConfig.Priority, compulsory); Configuration.ConfigBool(xmlElement, "SnapshotIsolation", ref cursorConfig.SnapshotIsolation, compulsory); Configuration.ConfigBool(xmlElement, "WriteCursor", ref cursorConfig.WriteCursor, compulsory); }
public static void GetCursorInBtreeDBInTDS( string home, string name, CursorConfig cursorConfig, out DatabaseEnvironment env, out BTreeDatabase db, out BTreeCursor cursor, out Transaction txn) { string dbFileName = name + ".db"; Configuration.ClearDir(home); // Open an environment. DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseMPool = true; envConfig.UseTxns = true; envConfig.NoMMap = false; envConfig.UseLocking = true; env = DatabaseEnvironment.Open(home, envConfig); // Begin a transaction. txn = env.BeginTransaction(); /* * Open an btree database. The underlying database * should be opened with ReadUncommitted if the * cursor's isolation degree will be set to be 1. */ BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; if (cursorConfig.IsolationDegree == Isolation.DEGREE_ONE) { dbConfig.ReadUncommitted = true; } db = BTreeDatabase.Open(dbFileName, dbConfig, txn); // Get a cursor in the transaction. cursor = db.Cursor(cursorConfig, txn); }
public void ReadTxn() { // Get a new transaction for reading the db. TransactionConfig txnConfig = new TransactionConfig(); txnConfig.Snapshot = true; readTxn = paramEnv.BeginTransaction( txnConfig); // Get a new cursor for putting record into db. CursorConfig cursorConfig = new CursorConfig(); cursorConfig.WriteCursor = false; BTreeCursor cursor = paramDB.Cursor( cursorConfig, readTxn); // Continually reading record from db. try { Assert.IsTrue(cursor.MoveFirst()); int i = 0; do { Assert.AreEqual( BitConverter.ToInt32( cursor.Current.Key.Data, 0), BitConverter.ToInt32( cursor.Current.Value.Data, 0)); } while (i <= 1000 && cursor.MoveNext()); } catch (DeadlockException) { } finally { cursor.Close(); } }
public void TestWriteCursor() { BTreeCursor cursor; BTreeDatabase db; CursorConfig cursorConfig; DatabaseEnvironment env; testName = "TestWriteCursor"; testHome = testFixtureHome + "/" + testName; Configuration.ClearDir(testHome); cursorConfig = new CursorConfig(); cursorConfig.WriteCursor = true; GetCursorInBtreeDBInCDS(testHome, testName, cursorConfig, out env, out db, out cursor); /* * Add a record by cursor to the database. If the * WriteCursor doesn't work, exception will be * throwed in the environment which is configured * with DB_INIT_CDB. */ try { AddOneByCursor(db, cursor); } catch (DatabaseException) { throw new TestException(); } finally { cursor.Close(); db.Close(); env.Close(); } }
public void TestSecondaryCursorWithConfig() { testName = "TestSecondaryCursorWithConfig"; testHome = testFixtureHome + "/" + testName; string dbFileName = testHome + "/" + testName + ".db"; Configuration.ClearDir(testHome); BTreeDatabase db; SecondaryBTreeDatabase secDB; OpenPrimaryAndSecondaryDB(dbFileName, out db, out secDB); for (int i = 0; i < 10; i++) { db.Put(new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(BitConverter.GetBytes((int)i))); } CursorConfig cursorConfig = new CursorConfig(); cursorConfig.WriteCursor = false; SecondaryCursor cursor = secDB.SecondaryCursor(cursorConfig); cursor.Move(new DatabaseEntry( BitConverter.GetBytes((int)5)), true); Assert.AreEqual(1, cursor.Count()); // Close the cursor. cursor.Close(); // Close secondary database. secDB.Close(); // Close primary database. db.Close(); }
public void TestPriority() { BTreeCursor cursor; BTreeDatabase db; CachePriority[] priorities; CursorConfig cursorConfig; DatabaseEnvironment env; cursorConfig = new CursorConfig(); priorities = new CachePriority[5]; priorities[0] = CachePriority.DEFAULT; priorities[1] = CachePriority.HIGH; priorities[2] = CachePriority.LOW; priorities[3] = CachePriority.VERY_HIGH; priorities[4] = CachePriority.VERY_LOW; testName = "TestPriority"; testHome = testFixtureHome + "/" + testName; Configuration.ClearDir(testHome); for (int i = 0; i < 5; i++) { // Configure the cursor priority. cursorConfig.Priority = priorities[i]; // Open a database to test a specified priority. GetCursorInBtreeDBInCDS(testHome, testName, cursorConfig, out env, out db, out cursor); Assert.AreEqual(priorities[i], cursorConfig.Priority); cursor.Close(); db.Close(); env.Close(); } }
public void TestIsolationDegree() { BTreeDatabase db; BTreeCursor cursor; CursorConfig cursorConfig; DatabaseEnvironment env; Transaction txn; testName = "TestIsolationDegree"; testHome = testFixtureHome + "/" + testName; Isolation[] isolationDegrees = new Isolation[3]; isolationDegrees[0] = Isolation.DEGREE_ONE; isolationDegrees[1] = Isolation.DEGREE_TWO; isolationDegrees[2] = Isolation.DEGREE_THREE; IsolationDelegate[] delegates = { new IsolationDelegate(CursorReadUncommited), new IsolationDelegate(CursorReadCommited), new IsolationDelegate(CursorRead) }; cursorConfig = new CursorConfig(); for (int i = 0; i < 3; i++) { cursorConfig.IsolationDegree = isolationDegrees[i]; GetCursorInBtreeDBInTDS(testHome + "/" + i.ToString(), testName, cursorConfig, out env, out db, out cursor, out txn); cursor.Close(); db.Close(); txn.Commit(); env.Close(); } }
/* * Test the external file database with or without environment. * 1. Config and open the environment; * 2. Verify the environment external file configs; * 3. Config and open the database; * 4. Verify the database external file configs; * 5. Insert and verify some external file data by database methods; * 6. Insert some external file data by cursor, update it and verify * the update by database stream and cursor; * 7. Verify the stats; * 8. Close all handles. * If "blobdbt" is true, set the data DatabaseEntry.ExternalFile as * true, otherwise make the data DatabaseEntry reach the external file * threshold in size. */ void TestBlobHashDatabase(uint env_threshold, string env_blobdir, uint db_threshold, string db_blobdir, bool blobdbt) { if (env_threshold == 0 && db_threshold == 0) { return; } string hashDBName = testHome + "/" + testName + ".db"; Configuration.ClearDir(testHome); HashDatabaseConfig cfg = new HashDatabaseConfig(); cfg.Creation = CreatePolicy.ALWAYS; string blrootdir = "__db_bl"; // Open the environment and verify the external file config. if (env_threshold > 0) { DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.AutoCommit = true; envConfig.Create = true; envConfig.UseMPool = true; envConfig.UseLogging = true; envConfig.UseTxns = true; envConfig.UseLocking = true; envConfig.ExternalFileThreshold = env_threshold; if (env_blobdir != null) { envConfig.ExternalFileDir = env_blobdir; blrootdir = env_blobdir; } DatabaseEnvironment env = DatabaseEnvironment.Open( testHome, envConfig); if (env_blobdir == null) { Assert.IsNull(env.ExternalFileDir); } else { Assert.AreEqual(0, env.ExternalFileDir.CompareTo(env_blobdir)); } Assert.AreEqual(env_threshold, env.ExternalFileThreshold); cfg.Env = env; hashDBName = testName + ".db"; } // Open the database and verify the external file config. if (db_threshold > 0) { cfg.ExternalFileThreshold = db_threshold; } if (db_blobdir != null) { cfg.ExternalFileDir = db_blobdir; /* * The external file directory setting in the database * is effective only when it is opened without * an environment. */ if (cfg.Env == null) { blrootdir = db_blobdir; } } HashDatabase db = HashDatabase.Open(hashDBName, cfg); Assert.AreEqual( db_threshold > 0 ? db_threshold : env_threshold, db.ExternalFileThreshold); if (db_blobdir == null && cfg.Env == null) { Assert.IsNull(db.ExternalFileDir); } else { Assert.AreEqual(0, db.ExternalFileDir.CompareTo(blrootdir)); } // Insert and verify some external file data by database // methods. string[] records = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p","q","r", "s", "t", "u", "v", "w", "x", "y", "z" }; DatabaseEntry kdbt = new DatabaseEntry(); DatabaseEntry ddbt = new DatabaseEntry(); byte[] kdata, ddata; string str; KeyValuePair <DatabaseEntry, DatabaseEntry> pair; ddbt.ExternalFile = blobdbt; Assert.AreEqual(blobdbt, ddbt.ExternalFile); for (int i = 0; i < records.Length; i++) { kdata = BitConverter.GetBytes(i); str = records[i]; if (!blobdbt) { for (int j = 0; j < db_threshold; j++) { str = str + records[i]; } } ddata = Encoding.ASCII.GetBytes(str); kdbt.Data = kdata; ddbt.Data = ddata; db.Put(kdbt, ddbt); try { pair = db.Get(kdbt); } catch (DatabaseException) { db.Close(); if (cfg.Env != null) { cfg.Env.Close(); } throw new TestException(); } Assert.AreEqual(ddata, pair.Value.Data); } /* * Insert some external file data by cursor, update it and * verify the update by database stream. */ kdata = BitConverter.GetBytes(records.Length); ddata = Encoding.ASCII.GetBytes("abc"); kdbt.Data = kdata; ddbt.Data = ddata; ddbt.ExternalFile = true; Assert.IsTrue(ddbt.ExternalFile); pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(kdbt, ddbt); CursorConfig dbcConfig = new CursorConfig(); Transaction txn = null; if (cfg.Env != null) { txn = cfg.Env.BeginTransaction(); } HashCursor cursor = db.Cursor(dbcConfig, txn); cursor.Add(pair); DatabaseStreamConfig dbsc = new DatabaseStreamConfig(); dbsc.SyncPerWrite = true; DatabaseStream dbs = cursor.DbStream(dbsc); Assert.AreNotEqual(null, dbs); Assert.IsFalse(dbs.GetConfig.ReadOnly); Assert.IsTrue(dbs.GetConfig.SyncPerWrite); Assert.AreEqual(3, dbs.Size()); DatabaseEntry sdbt = dbs.Read(0, 3); Assert.IsNotNull(sdbt); Assert.AreEqual(ddata, sdbt.Data); sdbt = new DatabaseEntry(Encoding.ASCII.GetBytes("defg")); Assert.IsTrue(dbs.Write(sdbt, 3)); Assert.AreEqual(7, dbs.Size()); sdbt = dbs.Read(0, 7); Assert.IsNotNull(sdbt); Assert.AreEqual(Encoding.ASCII.GetBytes("abcdefg"), sdbt.Data); dbs.Close(); /* * Verify the database stream can not write when it is * configured to be read-only. */ dbsc.ReadOnly = true; dbs = cursor.DbStream(dbsc); Assert.IsTrue(dbs.GetConfig.ReadOnly); try { Assert.IsFalse(dbs.Write(sdbt, 7)); throw new TestException(); } catch (DatabaseException) { } dbs.Close(); // Verify the update by cursor. Assert.IsTrue(cursor.Move(kdbt, true)); pair = cursor.Current; Assert.AreEqual(Encoding.ASCII.GetBytes("abcdefg"), pair.Value.Data); cursor.Close(); if (cfg.Env != null) { txn.Commit(); } /* * Verify the external files are created in the expected * location. * This part of test is disabled since BTreeDatabase.BlobSubDir * is not exposed to users. */ //if (cfg.Env != null) // blrootdir = testHome + "/" + blrootdir; //string blobdir = blrootdir + "/" + db.BlobSubDir; //Assert.AreEqual(records.Length + 1, // Directory.GetFiles(blobdir, "__db.bl*").Length); //Assert.AreEqual(1, // Directory.GetFiles(blobdir, "__db_blob_meta.db").Length); // Verify the stats. HashStats st = db.Stats(); Assert.AreEqual(records.Length + 1, st.nExternalFiles); // Close all handles. db.Close(); if (cfg.Env != null) { cfg.Env.Close(); } /* * Remove the default external file directory * when it is not under the test home. */ if (db_blobdir == null && cfg.Env == null) { Directory.Delete("__db_bl", true); } }