public Commit ( CommitTransactionGrbit grbit ) : void | ||
grbit | CommitTransactionGrbit | JetCommitTransaction options. |
return | void |
internal static void CreateTable(JET_SESID sesid, JET_DBID dbid) { JET_TABLEID tableid; Api.JetCreateTable(sesid, dbid, GeometryTableName, 8, 80, out tableid); using (var transaction = new Microsoft.Isam.Esent.Interop.Transaction(sesid)) { JET_COLUMNID columnid; var columndef = new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnAutoincrement }; Api.JetAddColumn(sesid, tableid, colNameGeometryLabel, columndef, null, 0, out columnid); columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameProductLabel, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.UnsignedByte; Api.JetAddColumn(sesid, tableid, colNameGeomType, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.Short; Api.JetAddColumn(sesid, tableid, colNameProductIfcTypeId, columndef, null, 0, out columnid); Api.JetAddColumn(sesid, tableid, colNameSubPart, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.Binary; columndef.grbit = ColumndefGrbit.ColumnMaybeNull; Api.JetAddColumn(sesid, tableid, colNameTransformMatrix, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.LongBinary; //if (EsentVersion.SupportsWindows7Features) // columndef.grbit |= Windows7Grbits.ColumnCompressed; Api.JetAddColumn(sesid, tableid, colNameShapeData, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.Long; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameGeometryHash, columndef, null, 0, out columnid); columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameStyleLabel, columndef, null, 0, out columnid); // The primary index is the type and the entity label. string indexDef = string.Format("+{0}\0\0", colNameGeometryLabel); Api.JetCreateIndex(sesid, tableid, geometryTablePrimaryIndex, CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length, 100); //create index by geometry hashes indexDef = string.Format("+{0}\0\0", colNameGeometryHash); Api.JetCreateIndex(sesid, tableid, geometryTableHashIndex, CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100); //Create index by product indexDef = string.Format("+{0}\0{1}\0{2}\0{3}\0{4}\0\0", colNameGeomType, colNameProductIfcTypeId, colNameProductLabel, colNameSubPart, colNameStyleLabel); Api.JetCreateIndex(sesid, tableid, geometryTableGeomTypeIndex, CreateIndexGrbit.IndexUnique, indexDef, indexDef.Length, 100); //create index by style indexDef = string.Format("+{0}\0{1}\0{2}\0{3}\0{4}\0\0", colNameGeomType, colNameStyleLabel, colNameProductIfcTypeId, colNameProductLabel, colNameGeometryLabel); Api.JetCreateIndex(sesid, tableid, geometryTableStyleIndex, CreateIndexGrbit.None, indexDef, indexDef.Length, 100); Api.JetCloseTable(sesid, tableid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } }
internal static void CreateTable(Session session, JET_DBID dbid) { JET_TABLEID tableid; Api.JetCreateTable(session, dbid, ifcHeaderTableName, 1, 100, out tableid); using (var transaction = new Microsoft.Isam.Esent.Interop.Transaction(session)) { JET_COLUMNID columnid; var columndef = new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnAutoincrement }; Api.JetAddColumn(session, tableid, _colNameHeaderId, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.Currency; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(session, tableid, _colNameEntityCount, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.LongBinary; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(session, tableid, _colNameHeaderData, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.Text; columndef.grbit = ColumndefGrbit.ColumnNotNULL; columndef.cbMax = 32; Api.JetAddColumn(session, tableid, _colNameFileVersion, columndef, null, 0, out columnid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } }
internal static void CreateTable(Session session, JET_DBID dbid) { JET_TABLEID tableid; Api.JetCreateTable(session, dbid, ifcHeaderTableName, 1, 100, out tableid); using (var transaction = new Microsoft.Isam.Esent.Interop.Transaction(session)) { JET_COLUMNID columnid; var columndef = new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnAutoincrement }; Api.JetAddColumn(session, tableid, _colNameHeaderId, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.Currency; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(session, tableid, _colNameEntityCount, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.LongBinary; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(session, tableid, _colNameHeaderData, columndef, null, 0, out columnid); columndef.coltyp = JET_coltyp.Text; columndef.grbit = ColumndefGrbit.ColumnNotNULL; columndef.cbMax = 32; Api.JetAddColumn(session, tableid, _colNameFileVersion, columndef, null, 0, out columnid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } }
public void Update(Session session, JET_DBID dbid) { using (var tx = new Transaction(session)) { using (var files = new Table(session, dbid, "files", OpenTableGrbit.None)) { const string indexDef = "+etag\0\0"; Api.JetCreateIndex(session, files, "by_etag", CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100); using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using (var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "2.7", Encoding.Unicode); update.Save(); } } } tx.Commit(CommitTransactionGrbit.None); } }
public void Create(JET_SESID session, JET_DBID dbid) { using (var tran = new Transaction(session)) { JET_TABLEID tblID; Api.JetCreateTable(session, dbid, tableName, 1, 80, out tblID); JET_COLUMNID c; Api.JetAddColumn(session, tblID, colName_ID, new JET_COLUMNDEF() { coltyp = JET_coltyp.Currency, grbit = ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL, }, null, 0, out c); Api.JetAddColumn(session, tblID, colName_LogID, new JET_COLUMNDEF() { coltyp = JET_coltyp.Currency, grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL, }, null, 0, out c); var indexDef = "+" + colName_ID + "\0\0"; Api.JetCreateIndex(session, tblID, idxName_Primary, CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length, 80); tran.Commit(CommitTransactionGrbit.None); } }
public void Update(Session session, JET_DBID dbid) { using (var tx = new Transaction(session)) { using (var tasks = new Table(session, dbid, "tasks", OpenTableGrbit.None)) { JET_COLUMNID columnid; Api.JetAddColumn(session, tasks, "added_at",new JET_COLUMNDEF { coltyp = JET_coltyp.DateTime, grbit = ColumndefGrbit.ColumnNotNULL }, null, 0, out columnid); using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using (var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "2.5", Encoding.Unicode); update.Save(); } } } tx.Commit(CommitTransactionGrbit.None); } }
public static void WithDatabase(this JET_INSTANCE instance, string database, Func<Session, JET_DBID, Transaction, Transaction> action) { using (var session = new Session(instance)) { var tx = new Transaction(session); try { JET_DBID dbid; Api.JetOpenDatabase(session, database, "", out dbid, OpenDatabaseGrbit.None); try { tx = action(session, dbid, tx); } finally { Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None); } tx.Commit(CommitTransactionGrbit.None); } finally { if(tx != null) tx.Dispose(); } } }
public void Create(string database) { JET_DBID dbid; Api.JetCreateDatabase(session, database, null, out dbid, CreateDatabaseGrbit.None); try { using (var tx = new Transaction(session)) { CreateDetailsTable(dbid); CreateQueuesTable(dbid); CreateSubQueuesTable(dbid); CreateTransactionTable(dbid); CreateRecoveryTable(dbid); CreateOutgoingTable(dbid); CreateOutgoingHistoryTable(dbid); CreateReceivedMessagesTable(dbid); tx.Commit(CommitTransactionGrbit.None); } } finally { Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None); } }
public int GetUniqueId(string value) { OpenTableForUpdatingWithoutTransaction(); while (true) { if (TrySeek(value)) { return Api.RetrieveColumnAsInt32(SessionId, TableId, _idColumnId).Value; } using (var transaction = new Transaction(SessionId)) { PrepareUpdate(JET_prep.Insert); var id = Api.RetrieveColumnAsInt32(SessionId, TableId, _idColumnId, RetrieveColumnGrbit.RetrieveCopy).Value; // set name Api.SetColumn(SessionId, TableId, _nameColumnId, value, Encoding.Unicode); if (ApplyChanges()) { transaction.Commit(CommitTransactionGrbit.LazyFlush); return id; } } } }
public void CreateBasicTableColumnIndex3OnXp() { var tablecreate = new JET_TABLECREATE { szTableName = "table" }; string directory = SetupHelper.CreateRandomDirectory(); string database = Path.Combine(directory, "test.db"); using (var instance = new Instance("XpCreateBasicTableColumnIndex3")) { instance.Parameters.Recovery = false; instance.Parameters.NoInformationEvent = true; instance.Parameters.MaxTemporaryTables = 0; instance.Init(); using (var session = new Session(instance)) { JET_DBID dbid; Api.JetCreateDatabase(session, database, String.Empty, out dbid, CreateDatabaseGrbit.None); using (var transaction = new Transaction(session)) { Api.JetCreateTableColumnIndex3(session, dbid, tablecreate); Assert.AreNotEqual(JET_TABLEID.Nil, tablecreate.tableid); Assert.AreEqual(tablecreate.cCreated, 1); Api.JetCloseTable(session, tablecreate.tableid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } } } }
public void Create(string database) { JET_DBID dbid; Api.JetCreateDatabase(session, database, null, out dbid, CreateDatabaseGrbit.None); try { using (var tx = new Transaction(session)) { CreateDetailsTable(dbid); CreateDocumentsTable(dbid); CreateTasksTable(dbid); CreateScheduledReductionsTable(dbid); CreateMapResultsTable(dbid); CreateReduceResultsTable(dbid); CreateIndexingStatsTable(dbid); CreateIndexingStatsReduceTable(dbid); CreateIndexingEtagsTable(dbid); CreateFilesTable(dbid); CreateQueueTable(dbid); CreateListsTable(dbid); CreateIdentityTable(dbid); CreateReduceKeysCountsTable(dbid); CreateReduceKeysStatusTable(dbid); CreateIndexedDocumentsReferencesTable(dbid); tx.Commit(CommitTransactionGrbit.None); } } finally { Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None); } }
private static void CreateDatabase() { using (var databaseInstance = new Instance(DatabasePath)) { InitializeDatabaseInstance(databaseInstance); if (File.Exists(DatabasePath)) { return; } using (var session = new Session(databaseInstance)) { JET_DBID dbid; Api.JetCreateDatabase(session, DatabasePath, null, out dbid, CreateDatabaseGrbit.OverwriteExisting); using (var transaction = new Transaction(session)) { JET_TABLEID tableid; Api.JetCreateTable(session, dbid, "Message", 0, 100, out tableid); CreateIdColumn(session, tableid); CreateDateCreatedColumn(session, tableid); CreateIndexes(session, tableid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None); Api.JetDetachDatabase(session, DatabasePath); } } }
public void Create(string database) { JET_DBID dbid; Api.JetCreateDatabase(session, database, null, out dbid, CreateDatabaseGrbit.None); try { using (var tx = new Transaction(session)) { CreateDetailsTable(dbid); CreateDocumentsTable(dbid); CreateDocumentsBeingModifiedByTransactionsTable(dbid); CreateTransactionsTable(dbid); CreateTasksTable(dbid); CreateMapResultsTable(dbid); CreateIndexingStatsTable(dbid); CreateIndexingStatsReduceTable(dbid); CreateFilesTable(dbid); CreateQueueTable(dbid); CreateIdentityTable(dbid); tx.Commit(CommitTransactionGrbit.None); } } finally { Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None); } }
public void Update(Session session, JET_DBID dbid) { using(var tx = new Transaction(session)) { using (var mappedResults = new Table(session, dbid, "mapped_results", OpenTableGrbit.None)) { JET_COLUMNID columnid; Api.JetAddColumn(session, mappedResults, "reduce_key_and_view_hashed", new JET_COLUMNDEF { cbMax = 32, coltyp = JET_coltyp.Binary, grbit = ColumndefGrbit.ColumnNotNULL }, null, 0, out columnid); const string indexDef = "+reduce_key_and_view_hashed\0\0"; Api.JetCreateIndex(session, mappedResults, "by_reduce_key_and_view_hashed", CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100); Api.JetDeleteIndex(session, mappedResults, "by_view_and_reduce_key"); var columnDictionary = Api.GetColumnDictionary(session, mappedResults); Api.MoveBeforeFirst(session, mappedResults); while (Api.TryMoveNext(session, mappedResults)) { using (var update = new Update(session, mappedResults, JET_prep.Replace)) { var computeHash = MapReduceIndex.ComputeHash( Api.RetrieveColumnAsString(session, mappedResults, columnDictionary["view"], Encoding.Unicode), Api.RetrieveColumnAsString(session, mappedResults, columnDictionary["reduce_key"], Encoding.Unicode)); Api.SetColumn(session, mappedResults, columnDictionary["reduce_key_and_view_hashed"], computeHash); update.Save(); } } using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using(var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "2.2", Encoding.Unicode); update.Save(); } } } tx.Commit(CommitTransactionGrbit.None); } }
public void Update(Session session, JET_DBID dbid) { Transaction tx; using (tx = new Transaction(session)) { using ( var tbl = new Table(session, dbid, "indexes_stats", OpenTableGrbit.PermitDDL | OpenTableGrbit.DenyRead | OpenTableGrbit.DenyWrite)) { var columnDictionary = Api.GetColumnDictionary(session, tbl); if (columnDictionary.ContainsKey("reduce_attempts")) Api.JetDeleteColumn(session, tbl, "reduce_attempts"); if (columnDictionary.ContainsKey("reduce_errors")) Api.JetDeleteColumn(session, tbl, "reduce_errors"); if (columnDictionary.ContainsKey("reduce_successes")) Api.JetDeleteColumn(session, tbl, "reduce_successes"); } CreateIndexesStatsReduce(session, dbid); using (var stats = new Table(session, dbid, "indexes_stats",OpenTableGrbit.None)) using (var reduce = new Table(session, dbid, "indexes_stats_reduce", OpenTableGrbit.None)) { var tblKeyColumn = Api.GetColumnDictionary(session, stats)["key"]; var reduceKeyCol = Api.GetColumnDictionary(session, reduce)["key"]; Api.MoveBeforeFirst(session, stats); while (Api.TryMoveNext(session, stats)) { using(var update = new Update(session, reduce, JET_prep.Insert)) { var indexName = Api.RetrieveColumnAsString(session, stats, tblKeyColumn, Encoding.Unicode); Api.SetColumn(session, reduce, reduceKeyCol, indexName, Encoding.Unicode); update.Save(); } } } tx.Commit(CommitTransactionGrbit.LazyFlush); tx.Dispose(); tx = new Transaction(session); } using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using (var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "3.4", Encoding.Unicode); update.Save(); } } tx.Commit(CommitTransactionGrbit.None); tx.Dispose(); }
public void JetRetrieveColumns() { short s = Any.Int16; string str = Any.String; double d = Any.Double; var setcolumns = new[] { new JET_SETCOLUMN { cbData = sizeof(short), columnid = this.columnDict["Int16"], pvData = BitConverter.GetBytes(s) }, new JET_SETCOLUMN { cbData = sizeof(double), columnid = this.columnDict["Double"], pvData = BitConverter.GetBytes(d) }, new JET_SETCOLUMN { cbData = str.Length * sizeof(char), columnid = this.columnDict["Unicode"], pvData = Encoding.Unicode.GetBytes(str) }, new JET_SETCOLUMN { cbData = 0, columnid = this.columnDict["Binary"], pvData = null }, }; using (var trx = new Transaction(this.session)) using (var update = new Update(this.session, this.tableid, JET_prep.Insert)) { Api.JetSetColumns(this.session, this.tableid, setcolumns, setcolumns.Length); update.Save(); trx.Commit(CommitTransactionGrbit.None); } Api.TryMoveFirst(this.session, this.tableid); var retrievecolumns = new[] { new JET_RETRIEVECOLUMN { cbData = sizeof(short), columnid = this.columnDict["Int16"], pvData = new byte[sizeof(short)] }, new JET_RETRIEVECOLUMN { cbData = sizeof(double), columnid = this.columnDict["Double"], pvData = new byte[sizeof(double)] }, new JET_RETRIEVECOLUMN { cbData = str.Length * sizeof(char) * 2, columnid = this.columnDict["Unicode"], pvData = new byte[str.Length * sizeof(char) * 2] }, new JET_RETRIEVECOLUMN { cbData = 10, columnid = this.columnDict["Binary"], pvData = new byte[10] }, }; for (int i = 0; i < retrievecolumns.Length; ++i) { retrievecolumns[i].itagSequence = 1; } Api.JetRetrieveColumns(this.session, this.tableid, retrievecolumns, retrievecolumns.Length); // retrievecolumns[0] = short Assert.AreEqual(sizeof(short), retrievecolumns[0].cbActual); Assert.AreEqual(JET_wrn.Success, retrievecolumns[0].err); Assert.AreEqual(s, BitConverter.ToInt16(retrievecolumns[0].pvData, 0)); // retrievecolumns[1] = double Assert.AreEqual(sizeof(double), retrievecolumns[1].cbActual); Assert.AreEqual(JET_wrn.Success, retrievecolumns[1].err); Assert.AreEqual(d, BitConverter.ToDouble(retrievecolumns[1].pvData, 0)); // retrievecolumns[2] = string Assert.AreEqual(str.Length * sizeof(char), retrievecolumns[2].cbActual); Assert.AreEqual(JET_wrn.Success, retrievecolumns[2].err); Assert.AreEqual(str, Encoding.Unicode.GetString(retrievecolumns[2].pvData, 0, retrievecolumns[2].cbActual)); // retrievecolumns[3] = null Assert.AreEqual(0, retrievecolumns[3].cbActual); Assert.AreEqual(JET_wrn.ColumnNull, retrievecolumns[3].err); }
public void Update(Session session, JET_DBID dbid) { Transaction tx; using (tx = new Transaction(session)) { var count = 0; const int rowsInTxCount = 100; var tablesWithEtags = new[] { new {Table = "indexes_stats", Column = "last_indexed_etag"}, new {Table = "documents", Column = "etag"}, new {Table = "mapped_results", Column = "etag"}, new {Table = "files", Column = "etag"}, new {Table = "documents_modified_by_transaction", Column = "etag"}, }; foreach (var tablesWithEtag in tablesWithEtags) { using (var tbl = new Table(session, dbid, tablesWithEtag.Table, OpenTableGrbit.None)) { var columnid = Api.GetColumnDictionary(session, tbl)[tablesWithEtag.Column]; Api.MoveBeforeFirst(session, tbl); while (Api.TryMoveNext(session, tbl)) { using (var update = new Update(session, tbl, JET_prep.Replace)) { Api.SetColumn(session, tbl, columnid, Guid.Empty.TransformToValueForEsentSorting()); update.Save(); } if (count++%rowsInTxCount == 0) { tx.Commit(CommitTransactionGrbit.LazyFlush); tx.Dispose(); tx = new Transaction(session); } } tx.Commit(CommitTransactionGrbit.LazyFlush); tx.Dispose(); tx = new Transaction(session); } } using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using (var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "3.2", Encoding.Unicode); update.Save(); } } tx.Commit(CommitTransactionGrbit.None); tx.Dispose(); } }
public void CreateCommitAndBegin() { using (var transaction = new Transaction(this.sesid)) { Assert.IsTrue(transaction.IsInTransaction); transaction.Commit(CommitTransactionGrbit.None); Assert.IsFalse(transaction.IsInTransaction); transaction.Begin(); Assert.IsTrue(transaction.IsInTransaction); } }
public void Update(Session session, JET_DBID dbid) { // those actions are no longer required, and are actually removed on the next version // also, they don't work on non empty tables, so we skip them //using (tx = new Transaction(session)) //{ // using (var tbl = new Table(session, dbid, "indexes_stats", OpenTableGrbit.PermitDDL | OpenTableGrbit.DenyRead|OpenTableGrbit.DenyWrite)) // { // JET_COLUMNID columnid; // var defaultValue = BitConverter.GetBytes(0); // Api.JetAddColumn(session, tbl, "reduce_attempts", new JET_COLUMNDEF // { // coltyp = JET_coltyp.Long, // grbit = // ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnEscrowUpdate | ColumndefGrbit.ColumnNotNULL // }, defaultValue, defaultValue.Length, out columnid); // Api.JetAddColumn(session, tbl, "reduce_errors", new JET_COLUMNDEF // { // coltyp = JET_coltyp.Long, // grbit = // ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnEscrowUpdate | ColumndefGrbit.ColumnNotNULL // }, defaultValue, defaultValue.Length, out columnid); // Api.JetAddColumn(session, tbl, "reduce_successes", new JET_COLUMNDEF // { // coltyp = JET_coltyp.Long, // grbit = // ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnEscrowUpdate // }, defaultValue, defaultValue.Length, out columnid); // } // tx.Commit(CommitTransactionGrbit.LazyFlush); // tx.Dispose(); // tx = new Transaction(session); //} using (var tx = new Transaction(session)) { using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using (var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "3.3", Encoding.Unicode); update.Save(); } } tx.Commit(CommitTransactionGrbit.None); } }
public void Update(Session session, JET_DBID dbid) { using (var tx = new Transaction(session)) { using (var indexStats = new Table(session, dbid, "indexes_stats", OpenTableGrbit.None)) using (var documents = new Table(session, dbid, "documents", OpenTableGrbit.None)) using (var documentsInTx = new Table(session, dbid, "documents_modified_by_transaction", OpenTableGrbit.None)) { var defaultValue = Guid.Empty.ToByteArray(); JET_COLUMNID columnid; Api.JetAddColumn(session, indexStats, "last_indexed_etag", new JET_COLUMNDEF { coltyp = JET_coltyp.Binary, cbMax = 16, grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL }, defaultValue, defaultValue.Length, out columnid); defaultValue = BitConverter.GetBytes(SystemTime.UtcNow.AddSeconds(-1).ToOADate()); Api.JetAddColumn(session, indexStats, "last_indexed_timestamp", new JET_COLUMNDEF { coltyp = JET_coltyp.DateTime, grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL }, defaultValue, defaultValue.Length, out columnid); Api.JetAddColumn(session, documents, "last_modified", new JET_COLUMNDEF { coltyp = JET_coltyp.DateTime, grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL, }, defaultValue, defaultValue.Length, out columnid); Api.JetAddColumn(session, documentsInTx, "last_modified", new JET_COLUMNDEF { coltyp = JET_coltyp.DateTime, grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL, }, defaultValue, defaultValue.Length, out columnid); using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using (var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "2.6", Encoding.Unicode); update.Save(); } } } tx.Commit(CommitTransactionGrbit.None); } }
public void Create(string database) { JET_DBID dbid; Api.JetCreateDatabase(session, database, null, out dbid, CreateDatabaseGrbit.None); using (var tx = new Transaction(session)) { CreateKeysTable(dbid); CreateDataTable(dbid); tx.Commit(CommitTransactionGrbit.None); } }
public void Update(Session session, JET_DBID dbid) { Transaction tx; using (tx = new Transaction(session)) { using (var tbl = new Table(session, dbid, "indexes_stats", OpenTableGrbit.PermitDDL | OpenTableGrbit.DenyRead|OpenTableGrbit.DenyWrite)) { JET_COLUMNID columnid; var defaultValue = BitConverter.GetBytes(0); Api.JetAddColumn(session, tbl, "reduce_attempts", new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnEscrowUpdate | ColumndefGrbit.ColumnNotNULL }, defaultValue, defaultValue.Length, out columnid); Api.JetAddColumn(session, tbl, "reduce_errors", new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnEscrowUpdate | ColumndefGrbit.ColumnNotNULL }, defaultValue, defaultValue.Length, out columnid); Api.JetAddColumn(session, tbl, "reduce_successes", new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnEscrowUpdate }, defaultValue, defaultValue.Length, out columnid); } tx.Commit(CommitTransactionGrbit.LazyFlush); tx.Dispose(); tx = new Transaction(session); } using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using (var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "3.3", Encoding.Unicode); update.Save(); } } tx.Commit(CommitTransactionGrbit.None); tx.Dispose(); }
public void CreateIndexesOnXp() { string directory = SetupHelper.CreateRandomDirectory(); string database = Path.Combine(directory, "test.db"); using (var instance = new Instance("XPcreateindexes")) { instance.Parameters.Recovery = false; instance.Parameters.NoInformationEvent = true; instance.Parameters.MaxTemporaryTables = 0; instance.Parameters.TempDirectory = directory; instance.Init(); using (var session = new Session(instance)) { JET_DBID dbid; Api.JetCreateDatabase(session, database, String.Empty, out dbid, CreateDatabaseGrbit.None); using (var transaction = new Transaction(session)) { JET_TABLEID tableid; Api.JetCreateTable(session, dbid, "table", 0, 100, out tableid); JET_COLUMNID columnid; Api.JetAddColumn( session, tableid, "column1", new JET_COLUMNDEF { coltyp = JET_coltyp.Long }, null, 0, out columnid); var indexcreates = new[] { new JET_INDEXCREATE { szKey = "+column1\0", cbKey = 10, szIndexName = "index1", pidxUnicode = new JET_UNICODEINDEX { lcid = 1033 }, }, }; Api.JetCreateIndex2(session, tableid, indexcreates, indexcreates.Length); transaction.Commit(CommitTransactionGrbit.LazyFlush); } } } Cleanup.DeleteDirectoryWithRetry(directory); }
public override void Close() { if (disposed) return; // Ensure all data is flushed using (var transaction = new Transaction(session)) { transaction.Commit(CommitTransactionGrbit.WaitLastLevel0Commit); } // TODO : exception out if there is an in progress transaction session.Dispose(); instance.Dispose(); base.Close(); }
public void AddTask(RevaleeTask task) { if (task == null) { throw new ArgumentNullException("task"); } if (_EseInstance == null) { throw new InvalidOperationException("Storage provider has not been opened."); } EseConnection connection = _ConnectionPool.OpenConnection(); try { using (Table table = connection.GetTable(_TableNameCallbacks, OpenTableGrbit.Updatable)) { IDictionary<string, JET_COLUMNID> columnIds = connection.GetSchema(_TableNameCallbacks); using (var transaction = new Transaction(connection)) { using (var update = new Update(connection, table, JET_prep.Insert)) { Api.SetColumn(connection, table, columnIds[_ColumnNameCallbackId], task.CallbackId); Api.SetColumn(connection, table, columnIds[_ColumnNameCreatedTime], EnforceMinimumDateTime(task.CreatedTime)); Api.SetColumn(connection, table, columnIds[_ColumnNameCallbackTime], EnforceMinimumDateTime(task.CallbackTime)); Api.SetColumn(connection, table, columnIds[_ColumnNameCallbackUrl], task.CallbackUrl.OriginalString, Encoding.Unicode); Api.SetColumn(connection, table, columnIds[_ColumnNameAttemptsRemaining], task.AttemptsRemaining); if (task.AuthorizationCipher != null) { Api.SetColumn(connection, table, columnIds[_ColumnNameAuthorizationCipher], task.AuthorizationCipher, Encoding.Unicode); } update.Save(); } transaction.Commit(CommitTransactionGrbit.None); } } } finally { _ConnectionPool.CloseConnection(connection); } }
public static void Generate(Instance instance, string pathToDatabase) { using (var session = new Session(instance)) { JET_DBID dbid; Api.JetCreateDatabase(session, pathToDatabase, null, out dbid, CreateDatabaseGrbit.None); using (var transaction = new Transaction(session)) { JET_TABLEID tableid; Api.JetCreateTable(session, dbid, "Documents", 16, 100, out tableid); CreateDocumentsTable(session, tableid); Api.JetCloseTable(session, tableid); transaction.Commit(CommitTransactionGrbit.None); } Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None); } }
public void Update(Session session, JET_DBID dbid) { Transaction tx; using (tx = new Transaction(session)) { CreateIndexingEtagsTable(dbid, session); using (var stats = new Table(session, dbid, "indexes_stats",OpenTableGrbit.None)) using (var reduce = new Table(session, dbid, "indexes_etag", OpenTableGrbit.None)) { var tblKeyColumn = Api.GetColumnDictionary(session, stats)["key"]; var reduceKeyCol = Api.GetColumnDictionary(session, reduce)["key"]; Api.MoveBeforeFirst(session, stats); while (Api.TryMoveNext(session, stats)) { using(var update = new Update(session, reduce, JET_prep.Insert)) { var indexName = Api.RetrieveColumnAsString(session, stats, tblKeyColumn, Encoding.Unicode); Api.SetColumn(session, reduce, reduceKeyCol, indexName, Encoding.Unicode); update.Save(); } } } tx.Commit(CommitTransactionGrbit.LazyFlush); tx.Dispose(); tx = new Transaction(session); } using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using (var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "3.6", Encoding.Unicode); update.Save(); } } tx.Commit(CommitTransactionGrbit.None); tx.Dispose(); }
public static void WithDatabase(this JET_INSTANCE instance, string database, Action<Session, JET_DBID> action) { using (var session = new Session(instance)) using(var tx = new Transaction(session)) { JET_DBID dbid; Api.JetOpenDatabase(session, database, "", out dbid, OpenDatabaseGrbit.None); try { action(session, dbid); } finally { Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None); } tx.Commit(CommitTransactionGrbit.None); } }
protected void ExecuteInDatabase(Action<Session, JET_DBID> action) { var instance = new Instance(databasePath); try { instance.Parameters.CircularLog = true; instance.Parameters.CreatePathIfNotExist = true; instance.Parameters.TempDirectory = Path.Combine(Path.GetDirectoryName(databasePath), "temp"); instance.Parameters.SystemDirectory = Path.Combine(Path.GetDirectoryName(databasePath), "system"); instance.Parameters.LogFileDirectory = Path.Combine(Path.GetDirectoryName(databasePath), "logs"); instance.Init(); using (var session = new Session(instance)) { Api.JetAttachDatabase(session, databasePath, AttachDatabaseGrbit.None); try { using (var tx = new Transaction(session)) { JET_DBID dbid; Api.JetOpenDatabase(session, databasePath, "", out dbid, OpenDatabaseGrbit.None); try { action(session, dbid); tx.Commit(CommitTransactionGrbit.None); } finally { Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None); } } } finally { Api.JetDetachDatabase(session, databasePath); } } } finally { instance.Term(); } }
static void CreateTables(JET_DBID dbId, JET_SESID session) { using (var transaction = new Transaction(session)) { JET_TABLEID tableId = Esent.CreateTable(dbId, session, ChangeStoreTable.Name); Esent.AddColumn(session, tableId, ChangeStoreTable.ChangeRootIdColumn, JET_coltyp.Text, JET_CP.Unicode); Esent.AddColumn(session, tableId, ChangeStoreTable.SequenceColumn, JET_coltyp.Long, JET_CP.None, ColumndefGrbit.ColumnAutoincrement); Esent.AddColumn(session, tableId, ChangeStoreTable.BodyColumn, JET_coltyp.LongText, JET_CP.Unicode); string keyDescription = string.Format("+{0}\0+{1}\0\0", ChangeStoreTable.ChangeRootIdColumn, ChangeStoreTable.SequenceColumn); Esent.CreateIndex(session, tableId, ChangeStoreTable.Index, keyDescription); Esent.CloseTable(session, tableId); transaction.Commit(CommitTransactionGrbit.None); } }
public void Create(string database) { JET_DBID dbid; Api.JetCreateDatabase(session, database, null, out dbid, CreateDatabaseGrbit.None); try { using (var tx = new Transaction(session)) { CreateDetailsTable(dbid); CreateDocumentsTable(dbid); CreateViewsTable(dbid); CreateViewTransformationQueueTable(dbid); tx.Commit(CommitTransactionGrbit.None); } } finally { Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None); } }
public void Update(Session session, JET_DBID dbid) { using (var tx = new Transaction(session)) { new SchemaCreator(session).CreateQueueTable(dbid); using (var details = new Table(session, dbid, "details", OpenTableGrbit.None)) { Api.JetMove(session, details, JET_Move.First, MoveGrbit.None); var columnids = Api.GetColumnDictionary(session, details); using (var update = new Update(session, details, JET_prep.Replace)) { Api.SetColumn(session, details, columnids["schema_version"], "2.3", Encoding.Unicode); update.Save(); } } tx.Commit(CommitTransactionGrbit.None); } }
internal static void CreateTable(JET_SESID sesid, JET_DBID dbid) { JET_TABLEID tableid; Api.JetCreateTable(sesid, dbid, InstanceTableName, 8, 80, out tableid); using (var transaction = new Microsoft.Isam.Esent.Interop.Transaction(sesid)) { JET_COLUMNID columnid; //Unique instanceData label var columndef = new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL }; Api.JetAddColumn(sesid, tableid, colNameInstanceLabel, columndef, null, 0, out columnid); //IFC type ID columndef.coltyp = JET_coltyp.Short; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameIfcTypeId, columndef, null, 0, out columnid); //ifc Product label columndef.coltyp = JET_coltyp.Long; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameIfcProductLabel, columndef, null, 0, out columnid); //style label columndef.coltyp = JET_coltyp.Long; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameStyleLabel, columndef, null, 0, out columnid); //shape label columndef.coltyp = JET_coltyp.Long; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameShapeLabel, columndef, null, 0, out columnid); //Representation Context columndef.coltyp = JET_coltyp.Long; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameRepresentationContext, columndef, null, 0, out columnid); //Representation Context columndef.coltyp = JET_coltyp.UnsignedByte; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameRepType, columndef, null, 0, out columnid); //Transformation data columndef.coltyp = JET_coltyp.Binary; columndef.grbit = ColumndefGrbit.ColumnNotNULL; columndef.cbMax = MaxSizeOfTransformation; Api.JetAddColumn(sesid, tableid, colNameTransformation, columndef, null, 0, out columnid); //Bounding Box data columndef.coltyp = JET_coltyp.Binary; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameBoundingBox, columndef, null, 0, out columnid); string indexDef; // The index on the shape geometry label. indexDef = string.Format("+{0}\0\0", colNameShapeLabel); Api.JetCreateIndex(sesid, tableid, geometryShapeIndex, CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100); //create index by ifc product label.. .. indexDef = string.Format("+{0}\0\0", colNameIfcProductLabel); Api.JetCreateIndex(sesid, tableid, productIndex, CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100); //create index by ifc product type label.. .. indexDef = string.Format("+{0}\0\0", colNameIfcTypeId); Api.JetCreateIndex(sesid, tableid, productTypeIndex, CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100); //create by context,then ifc style... indexDef = string.Format("+{0}\0{1}\0{2}\0{3}\0\0", colNameRepresentationContext, colNameStyleLabel, colNameIfcTypeId, colNameInstanceLabel); Api.JetCreateIndex(sesid, tableid, instanceTablePrimaryIndex, CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length, 100); Api.JetCloseTable(sesid, tableid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } }
public void Commit() { //_undoRedoSession.Commit(); _dbTransaction.Commit(CommitTransactionGrbit.None); }
/// <summary> /// Create the globals table. /// </summary> /// <param name="sesid">The session to use.</param> /// <param name="dbid">The database to create the table in.</param> public static void CreateGlobalsTable(JET_SESID sesid, JET_DBID dbid) { JET_TABLEID tableid; JET_COLUMNID versionColumnid; JET_COLUMNID countColumnid; using (var transaction = new Microsoft.Isam.Esent.Interop.Transaction(sesid)) { Api.JetCreateTable(sesid, dbid, globalsTableName, 1, 100, out tableid); Api.JetAddColumn( sesid, tableid, versionColumnName, new JET_COLUMNDEF { coltyp = JET_coltyp.LongText }, null, 0, out versionColumnid); byte[] defaultValue = BitConverter.GetBytes(0); Api.JetAddColumn( sesid, tableid, entityCountColumnName, new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnEscrowUpdate }, defaultValue, defaultValue.Length, out countColumnid); Api.JetAddColumn( sesid, tableid, geometryCountColumnName, new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnEscrowUpdate }, defaultValue, defaultValue.Length, out countColumnid); Api.JetAddColumn( sesid, tableid, flushColumnName, new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnEscrowUpdate }, defaultValue, defaultValue.Length, out countColumnid); Api.JetAddColumn( sesid, tableid, ifcHeaderColumnName, new JET_COLUMNDEF { coltyp = JET_coltyp.LongBinary }, null, 0, out countColumnid); using (var update = new Update(sesid, tableid, JET_prep.Insert)) { Api.SetColumn(sesid, tableid, versionColumnid, version, Encoding.Unicode); update.Save(); } Api.JetCloseTable(sesid, tableid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } }
internal static void CreateTable(JET_SESID sesid, JET_DBID dbid) { JET_TABLEID tableid; Api.JetCreateTable(sesid, dbid, GeometryTableName, 8, 80, out tableid); using (var transaction = new Microsoft.Isam.Esent.Interop.Transaction(sesid)) { JET_COLUMNID columnid; //Unique geometry label var columndef = new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL }; Api.JetAddColumn(sesid, tableid, colNameShapeLabel, columndef, null, 0, out columnid); //IFC shape label columndef.coltyp = JET_coltyp.Long; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameIfcShapeLabel, columndef, null, 0, out columnid); //Geometry hash columndef.coltyp = JET_coltyp.Long; columndef.grbit = ColumndefGrbit.ColumnMaybeNull; Api.JetAddColumn(sesid, tableid, colNameGeometryHash, columndef, null, 0, out columnid); //cost columndef.coltyp = JET_coltyp.Long; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameCost, columndef, null, 0, out columnid); //reference count columndef.coltyp = JET_coltyp.Long; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameReferenceCount, columndef, null, 0, out columnid); //LOD columndef.coltyp = JET_coltyp.UnsignedByte; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameLOD, columndef, null, 0, out columnid); //Data format type columndef.coltyp = JET_coltyp.UnsignedByte; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameFormat, columndef, null, 0, out columnid); //Bounding Box data columndef.coltyp = JET_coltyp.Binary; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameBoundingBox, columndef, null, 0, out columnid); //Shape data columndef.coltyp = JET_coltyp.LongBinary; columndef.grbit = ColumndefGrbit.ColumnNotNULL; Api.JetAddColumn(sesid, tableid, colNameShapeData, columndef, null, 0, out columnid); // The primary index is the geometry label. var indexDef = string.Format("+{0}\0\0", colNameShapeLabel); Api.JetCreateIndex(sesid, tableid, geometryTablePrimaryIndex, CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100); //create index by geometry hashes indexDef = string.Format("+{0}\0\0", colNameGeometryHash); // Api.JetCreateIndex(sesid, tableid, geometryTableHashIndex, CreateIndexGrbit.None, indexDef, indexDef.Length, 100); //create index for reference count indexDef = string.Format("-{0}\0{1}\0{2}\0\0", colNameCost, colNameReferenceCount, colNameShapeLabel); Api.JetCreateIndex(sesid, tableid, geometryTableReferenceIndex, CreateIndexGrbit.None, indexDef, indexDef.Length, 100); Api.JetCloseTable(sesid, tableid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } }