private BDbcMethods(IntPtr pdbc, BDbOffsetOf offsetOf, BerkeleyDbType dbType) { _offsetOf = offsetOf; _dbType = dbType; foreach (BDbOffsetOfItem offsetOfItem in offsetOf.Dbc) { IntPtr funcptr = Marshal.ReadIntPtr(pdbc + offsetOfItem.Offset); switch (offsetOfItem.Name) { case "close": _close = (close)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(close)); break; case "del": _del = (del)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(del)); break; case "get": _get = (get)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(get)); break; case "put": _put = (put)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(put)); break; } } }
private static BDbcMethods GetMethodsInternal(BerkeleyDbType dbType) { switch (dbType) { case BerkeleyDbType.DB_BTREE: return(_btree); case BerkeleyDbType.DB_HASH: return(_hash); case BerkeleyDbType.DB_RECNO: return(_recno); case BerkeleyDbType.DB_QUEUE: return(_queue); case BerkeleyDbType.DB_UNKNOWN: return(_unknown); case BerkeleyDbType.DB_HEAP: return(_hash); default: throw new ArgumentOutOfRangeException("dbType", dbType.ToString()); } }
private BDbMethods(IntPtr pdb, BDbOffsetOf offsetOf, BerkeleyDbType dbType) { _dbType = dbType; _offsetOf = offsetOf; foreach (BDbOffsetOfItem offsetOfItem in offsetOf.Db) { IntPtr funcptr = Marshal.ReadIntPtr(pdb + offsetOfItem.Offset); switch (offsetOfItem.Name) { case "close": _close = (close)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(close)); break; case "cursor": _cursor = (cursor)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(cursor)); break; case "del": _del = (del)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(del)); break; case "get_pagesize": _get_pagesize = (get_pagesize)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(get_pagesize)); break; case "open": _open = (open)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(open)); break; case "put": _put = (put)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(put)); break; case "set_flags": _set_flags = (set_flags)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(set_flags)); break; } } }
public static BDbcMethods GetMethods(BerkeleyDbType dbType) { BDbcMethods methods = GetMethodsInternal(dbType); if (methods == null) { throw new InvalidOperationException("must call DbcMethods.Create"); } return(methods); }
public static BerkeleyDbError Create(BDbOffsetOf offsetOf, IntPtr pdb, BerkeleyDbType dbType, BerkeleyDbCursorFlags flags, out IntPtr pdbc) { BDbMethods dbMethods = BDbMethods.GetMethods(dbType); BerkeleyDbError error = dbMethods.Cursor(pdb, flags, out pdbc); if (error == 0) { CreateMethods(dbType, pdbc, offsetOf); } return(error); }
public static BerkeleyDbError Create(BDbOffsetOf offsetOf, IntPtr penv, BerkeleyDbType dbType, BerkeleyDbFlags flags, out IntPtr pdb) { var error = (BerkeleyDbError)db_create(out pdb, penv, 0); if (error != 0) { return(error); } BDbMethods methods = CreateMethods(dbType, pdb, offsetOf); error = (BerkeleyDbError)methods.SetFlags(pdb, flags); if (error != 0 && pdb != IntPtr.Zero) { methods.Close(pdb, 0); pdb = IntPtr.Zero; } return(error); }
private static BDbcMethods CreateMethods(BerkeleyDbType dbType, IntPtr pdbc, BDbOffsetOf offsetOf) { BDbcMethods dbcMethods = GetMethodsInternal(dbType); if (dbcMethods == null) { lock (typeof(BDbcMethods)) { dbcMethods = GetMethodsInternal(dbType); if (dbcMethods == null) { dbcMethods = new BDbcMethods(pdbc, offsetOf, dbType); switch (dbType) { case BerkeleyDbType.DB_BTREE: _btree = dbcMethods; break; case BerkeleyDbType.DB_HASH: _hash = dbcMethods; break; case BerkeleyDbType.DB_RECNO: _recno = dbcMethods; break; case BerkeleyDbType.DB_QUEUE: _queue = dbcMethods; break; case BerkeleyDbType.DB_UNKNOWN: _unknown = dbcMethods; break; case BerkeleyDbType.DB_HEAP: _heap = dbcMethods; break; } } } } return(dbcMethods); }
public BerkeleyDtoResult Create([FromUri] BerkeleyDbType type, [FromUri] String flags) { ulong handle = 0; BerkeleyDbFlags bdbFlags = BerkeleyEnumParser.Flags(flags); IntPtr pdb; IntPtr penv = DbenvInstance.Instance.Handle; BerkeleyDbError error = BDbMethods.Create(BDbOffsetOfInstance.Instance, penv, type, bdbFlags, out pdb); if (error == 0) { BDbMethods dbMethods = BDbMethods.GetMethods(type); var db = new DbHandle(pdb, dbMethods); handle = DbInstance.AddDb(db); if (handle == 0) { dbMethods.Close(pdb, 0); throw new HttpResponseException(HttpStatusCode.InternalServerError); } } return(new BerkeleyDtoResult(error, handle.ToString())); }
public static String ToStringEx(this BerkeleyDbType flag) { switch (flag) { case BerkeleyDbType.DB_BTREE: return("db_btree"); case BerkeleyDbType.DB_HASH: return("db_hash"); case BerkeleyDbType.DB_RECNO: return("db_recno"); case BerkeleyDbType.DB_QUEUE: return("db_queue"); case BerkeleyDbType.DB_UNKNOWN: return("db_unknown"); default: throw new ArgumentOutOfRangeException(flag.ToString()); } }
private static BDbcMethods CreateMethods(BerkeleyDbType dbType, IntPtr pdbc, BDbOffsetOf offsetOf) { BDbcMethods dbcMethods = GetMethodsInternal(dbType); if (dbcMethods == null) { lock (typeof(BDbcMethods)) { dbcMethods = GetMethodsInternal(dbType); if (dbcMethods == null) { dbcMethods = new BDbcMethods(pdbc, offsetOf, dbType); switch (dbType) { case BerkeleyDbType.DB_BTREE: _btree = dbcMethods; break; case BerkeleyDbType.DB_HASH: _hash = dbcMethods; break; case BerkeleyDbType.DB_RECNO: _recno = dbcMethods; break; case BerkeleyDbType.DB_QUEUE: _queue = dbcMethods; break; case BerkeleyDbType.DB_UNKNOWN: _unknown = dbcMethods; break; case BerkeleyDbType.DB_HEAP: _heap = dbcMethods; break; } } } } return dbcMethods; }
public static BerkeleyDbError Create(BDbOffsetOf offsetOf, IntPtr penv, BerkeleyDbType dbType, BerkeleyDbFlags flags, out IntPtr pdb) { var error = (BerkeleyDbError)db_create(out pdb, penv, 0); if (error != 0) return error; BDbMethods methods = CreateMethods(dbType, pdb, offsetOf); error = (BerkeleyDbError)methods.SetFlags(pdb, flags); if (error != 0 && pdb != IntPtr.Zero) { methods.Close(pdb, 0); pdb = IntPtr.Zero; } return error; }
private static BDbMethods GetMethodsInternal(BerkeleyDbType dbType) { switch (dbType) { case BerkeleyDbType.DB_BTREE: return _btree; case BerkeleyDbType.DB_HASH: return _hash; case BerkeleyDbType.DB_RECNO: return _recno; case BerkeleyDbType.DB_QUEUE: return _queue; case BerkeleyDbType.DB_UNKNOWN: return _unknown; case BerkeleyDbType.DB_HEAP: return _hash; default: throw new ArgumentOutOfRangeException("dbType", dbType.ToString()); } }
public static BDbMethods GetMethods(BerkeleyDbType dbType) { BDbMethods methods = GetMethodsInternal(dbType); if (methods == null) throw new InvalidOperationException("must call DbMethods.Create"); return methods; }
public static BerkeleyDbError Create(BDbOffsetOf offsetOf, IntPtr pdb, BerkeleyDbType dbType, BerkeleyDbCursorFlags flags, out IntPtr pdbc) { BDbMethods dbMethods = BDbMethods.GetMethods(dbType); BerkeleyDbError error = dbMethods.Cursor(pdb, flags, out pdbc); if (error == 0) CreateMethods(dbType, pdbc, offsetOf); return error; }
public BerkeleyDb(BerkeleyDbMethodsAsync methods, BerkeleyDbType dbType, BerkeleyDbFlags flags) { _methods = methods; _dbType = dbType; _flags = flags; }