DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Static Public Member Functions | Static Package Functions | Static Private Member Functions | List of all members
Deveel.Data.DatabaseExtensions Class Reference

Static Public Member Functions

static ITransaction CreateTransaction (this IDatabase database, IsolationLevel isolation)
 
static ITransaction FindTransactionById (this IDatabase database, int commidId)
 
static ISession CreateUserSession (this IDatabase database, User user)
 
static ISession CreateUserSession (this IDatabase database, string userName, string password)
 
static void CreateAdminUser (this IDatabase database, IQuery context, string adminName, string adminPassword)
 
static User Authenticate (this IDatabase database, string username, string password)
 

Static Package Functions

static ITransaction CreateSafeTransaction (this IDatabase database, IsolationLevel isolation)
 
static ISession CreateInitialSystemSession (this IDatabase database)
 
static ISession CreateSystemSession (this IDatabase database)
 

Static Private Member Functions

static ISession CreateUserSession (this IDatabase database, User user, IsolationLevel isolation)
 
static ISession CreateSystemSession (this IDatabase database, IsolationLevel isolation)
 
static ISession OpenUserSession (this IDatabase database, int commitId, User user)
 

Detailed Description

Definition at line 25 of file DatabaseExtensions.cs.

Member Function Documentation

static User Deveel.Data.DatabaseExtensions.Authenticate ( this IDatabase  database,
string  username,
string  password 
)
inlinestatic

Definition at line 120 of file DatabaseExtensions.cs.

120  {
121  // Create a temporary connection for authentication only...
122  using (var session = database.CreateSystemSession()) {
123  session.CurrentSchema(SystemSchema.Name);
124 
125  using (var queryContext = session.CreateQuery()) {
126  return queryContext.Authenticate(username, password);
127  }
128  }
129  }
static void Deveel.Data.DatabaseExtensions.CreateAdminUser ( this IDatabase  database,
IQuery  context,
string  adminName,
string  adminPassword 
)
inlinestatic

Definition at line 101 of file DatabaseExtensions.cs.

101  {
102  try {
103  var user = context.CreateUser(adminName, adminPassword);
104 
105  // This is the admin user so add to the 'secure access' table.
106  context.AddUserToGroup(adminName, SystemGroups.SecureGroup);
107 
108  context.GrantToUserOnSchema(database.Context.DefaultSchema(), user.Name, Privileges.SchemaAll, true);
109  context.GrantToUserOnSchema(SystemSchema.Name, user.Name, Privileges.SchemaRead);
110  context.GrantToUserOnSchema(InformationSchema.SchemaName, user.Name, Privileges.SchemaRead);
111 
112  SystemSchema.GrantToPublic(context);
113  } catch (DatabaseSystemException) {
114  throw;
115  } catch (Exception ex) {
116  throw new DatabaseSystemException("Could not create the database administrator.", ex);
117  }
118  }
const string SecureGroup
THe name of the secure access group.
Definition: SystemGroups.cs:46
static ISession Deveel.Data.DatabaseExtensions.CreateInitialSystemSession ( this IDatabase  database)
inlinestaticpackage

Definition at line 64 of file DatabaseExtensions.cs.

64  {
65  var transaction = database.CreateSafeTransaction(IsolationLevel.Serializable);
66  return new SystemSession(transaction, SystemSchema.Name);
67  }
static ITransaction Deveel.Data.DatabaseExtensions.CreateSafeTransaction ( this IDatabase  database,
IsolationLevel  isolation 
)
inlinestaticpackage

Definition at line 39 of file DatabaseExtensions.cs.

39  {
40  return database.TransactionFactory.CreateTransaction(isolation);
41  }
static ISession Deveel.Data.DatabaseExtensions.CreateSystemSession ( this IDatabase  database,
IsolationLevel  isolation 
)
inlinestaticprivate

Definition at line 59 of file DatabaseExtensions.cs.

59  {
60  var transaction = database.CreateTransaction(isolation);
61  return new SystemSession(transaction, SystemSchema.Name);
62  }
static ISession Deveel.Data.DatabaseExtensions.CreateSystemSession ( this IDatabase  database)
inlinestaticpackage

Definition at line 69 of file DatabaseExtensions.cs.

69  {
70  return database.CreateSystemSession(IsolationLevel.Serializable);
71  }
static ITransaction Deveel.Data.DatabaseExtensions.CreateTransaction ( this IDatabase  database,
IsolationLevel  isolation 
)
inlinestatic

Definition at line 28 of file DatabaseExtensions.cs.

28  {
29  if (!database.IsOpen)
30  throw new InvalidOperationException(String.Format("Database '{0}' is not open.", database.Name));
31 
32  return database.CreateSafeTransaction(isolation);
33  }
A long string in the system.
static ISession Deveel.Data.DatabaseExtensions.CreateUserSession ( this IDatabase  database,
User  user,
IsolationLevel  isolation 
)
inlinestaticprivate

Definition at line 47 of file DatabaseExtensions.cs.

47  {
48  if (user == null)
49  throw new ArgumentNullException("user");
50 
51  // TODO: if the isolation is not specified, use a configured default one
52  if (isolation == IsolationLevel.Unspecified)
53  isolation = IsolationLevel.Serializable;
54 
55  var transaction = database.CreateTransaction(isolation);
56  return new Session(transaction, user);
57  }
static ISession Deveel.Data.DatabaseExtensions.CreateUserSession ( this IDatabase  database,
User  user 
)
inlinestatic

Definition at line 73 of file DatabaseExtensions.cs.

73  {
74  // TODO: get the pre-configured default transaction isolation
75  return database.CreateUserSession(user, IsolationLevel.Unspecified);
76  }
static ISession Deveel.Data.DatabaseExtensions.CreateUserSession ( this IDatabase  database,
string  userName,
string  password 
)
inlinestatic

Definition at line 78 of file DatabaseExtensions.cs.

78  {
79  var user = database.Authenticate(userName, password);
80  if (user == null)
81  throw new InvalidOperationException(String.Format("Unable to create a session for user '{0}': not authenticated.", userName));
82 
83  return database.CreateUserSession(user);
84  }
A long string in the system.
static ITransaction Deveel.Data.DatabaseExtensions.FindTransactionById ( this IDatabase  database,
int  commidId 
)
inlinestatic

Definition at line 35 of file DatabaseExtensions.cs.

35  {
36  return database.TransactionFactory.OpenTransactions.FindById(commidId);
37  }
static ISession Deveel.Data.DatabaseExtensions.OpenUserSession ( this IDatabase  database,
int  commitId,
User  user 
)
inlinestaticprivate

Definition at line 86 of file DatabaseExtensions.cs.

86  {
87  if (commitId < 0)
88  throw new ArgumentException("Invalid commit reference specified.");
89 
90  var transaction = database.FindTransactionById(commitId);
91  if (transaction == null)
92  throw new InvalidOperationException(String.Format("The request transaction with ID '{0}' is not open.", commitId));
93 
94  return new Session(transaction, user);
95  }
A long string in the system.

The documentation for this class was generated from the following file: