summaryrefslogtreecommitdiff
path: root/product/database
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2009-10-23 13:09:04 -0600
committermo khan <mo@mokhan.ca>2009-10-23 13:09:04 -0600
commit9a3430b2a1f0445c0dbac703907762e225383421 (patch)
tree751d5742a199eae57ebb6d767e650bd6c803bdc3 /product/database
parentf76fe6ca01f3dc5fabc8bf16f299420ba9d7ef05 (diff)
renamed some components to something that is more descriptive.main
Diffstat (limited to 'product/database')
-rw-r--r--product/database/IConnectionFactory.cs2
-rw-r--r--product/database/ObjectDatabase.cs4
-rw-r--r--product/database/database.csproj12
-rw-r--r--product/database/db4o/ConnectionFactory.cs4
-rw-r--r--product/database/db4o/ObjectDatabaseConnection.cs (renamed from product/database/db4o/DatabaseConnection.cs)4
-rw-r--r--product/database/transactions/ChangeTracker.cs8
-rw-r--r--product/database/transactions/ChangeTrackerFactory.cs4
-rw-r--r--product/database/transactions/ChangeTrackerSpecs.cs10
-rw-r--r--product/database/transactions/DatabaseCommand.cs8
-rw-r--r--product/database/transactions/DatabaseCommandRegistry.cs11
-rw-r--r--product/database/transactions/DatabaseConnection.cs (renamed from product/database/transactions/IDatabaseConnection.cs)2
-rw-r--r--product/database/transactions/DeleteFromDatabase.cs17
-rw-r--r--product/database/transactions/IDatabase.cs2
-rw-r--r--product/database/transactions/IStatement.cs7
-rw-r--r--product/database/transactions/IStatementRegistry.cs11
-rw-r--r--product/database/transactions/ObjectDatabaseCommandRegistry.cs18
-rw-r--r--product/database/transactions/SaveOrUpdateFromDatabase.cs20
-rw-r--r--product/database/transactions/StatementRegistry.cs48
18 files changed, 101 insertions, 91 deletions
diff --git a/product/database/IConnectionFactory.cs b/product/database/IConnectionFactory.cs
index 25d37d0..0f0defa 100644
--- a/product/database/IConnectionFactory.cs
+++ b/product/database/IConnectionFactory.cs
@@ -5,6 +5,6 @@ namespace momoney.database
{
public interface IConnectionFactory
{
- IDatabaseConnection open_connection_to(File the_path_to_the_database_file);
+ DatabaseConnection open_connection_to(File the_path_to_the_database_file);
}
} \ No newline at end of file
diff --git a/product/database/ObjectDatabase.cs b/product/database/ObjectDatabase.cs
index b96ad20..9ee6c1b 100644
--- a/product/database/ObjectDatabase.cs
+++ b/product/database/ObjectDatabase.cs
@@ -28,11 +28,11 @@ namespace momoney.database
}
}
- public void apply(IStatement statement)
+ public void apply(DatabaseCommand command)
{
using (var connection = factory.open_connection_to(path_to_database()))
{
- statement.prepare(connection);
+ command.run(connection);
connection.commit();
}
}
diff --git a/product/database/database.csproj b/product/database/database.csproj
index df48913..252edd8 100644
--- a/product/database/database.csproj
+++ b/product/database/database.csproj
@@ -90,7 +90,7 @@
<Compile Include="db4o\ConfigureDatabaseStep.cs" />
<Compile Include="db4o\ConnectionFactory.cs" />
<Compile Include="ObjectDatabase.cs" />
- <Compile Include="db4o\DatabaseConnection.cs" />
+ <Compile Include="db4o\ObjectDatabaseConnection.cs" />
<Compile Include="IConnectionFactory.cs" />
<Compile Include="IDatabaseConfiguration.cs" />
<Compile Include="transactions\ChangeTracker.cs" />
@@ -101,22 +101,24 @@
<Compile Include="transactions\ContextFactory.cs" />
<Compile Include="transactions\ContextFactorySpecs.cs" />
<Compile Include="transactions\CurrentThread.cs" />
+ <Compile Include="transactions\DeleteFromDatabase.cs" />
<Compile Include="transactions\IChangeTracker.cs" />
<Compile Include="transactions\IChangeTrackerFactory.cs" />
<Compile Include="transactions\IContext.cs" />
<Compile Include="transactions\IDatabase.cs" />
- <Compile Include="transactions\IDatabaseConnection.cs" />
+ <Compile Include="transactions\DatabaseConnection.cs" />
<Compile Include="transactions\IdentityMapProxy.cs" />
<Compile Include="transactions\IdentityMapSpecs.cs" />
<Compile Include="transactions\IIdentityMap.cs" />
<Compile Include="transactions\IKey.cs" />
<Compile Include="transactions\IScopedStorage.cs" />
- <Compile Include="transactions\IStatement.cs" />
- <Compile Include="transactions\IStatementRegistry.cs" />
+ <Compile Include="transactions\DatabaseCommand.cs" />
+ <Compile Include="transactions\DatabaseCommandRegistry.cs" />
<Compile Include="transactions\IThread.cs" />
<Compile Include="transactions\PerThread.cs" />
<Compile Include="transactions\PerThreadScopedStorage.cs" />
<Compile Include="transactions\PerThreadScopedStorageSpecs.cs" />
+ <Compile Include="transactions\SaveOrUpdateFromDatabase.cs" />
<Compile Include="transactions\Session.cs" />
<Compile Include="transactions\SessionFactory.cs" />
<Compile Include="transactions\SessionFactorySpecs.cs" />
@@ -124,7 +126,7 @@
<Compile Include="transactions\SessionProvider.cs" />
<Compile Include="transactions\SessionSpecs.cs" />
<Compile Include="transactions\SingletonScopedStorage.cs" />
- <Compile Include="transactions\StatementRegistry.cs" />
+ <Compile Include="transactions\ObjectDatabaseCommandRegistry.cs" />
<Compile Include="transactions\TrackerEntry.cs" />
<Compile Include="transactions\TrackerEntryMapper.cs" />
<Compile Include="transactions\TrackerEntrySpecs.cs" />
diff --git a/product/database/db4o/ConnectionFactory.cs b/product/database/db4o/ConnectionFactory.cs
index e18895f..57260d5 100644
--- a/product/database/db4o/ConnectionFactory.cs
+++ b/product/database/db4o/ConnectionFactory.cs
@@ -17,11 +17,11 @@ namespace momoney.database.db4o
this.setup_container = setup_container;
}
- public IDatabaseConnection open_connection_to(File the_path_to_the_database_file)
+ public DatabaseConnection open_connection_to(File the_path_to_the_database_file)
{
var configuration = Db4oFactory.NewConfiguration();
setup.configure(configuration);
- return new DatabaseConnection(get_container(the_path_to_the_database_file, configuration));
+ return new ObjectDatabaseConnection(get_container(the_path_to_the_database_file, configuration));
}
IObjectContainer get_container(File the_path_to_the_database_file, IConfiguration configuration)
diff --git a/product/database/db4o/DatabaseConnection.cs b/product/database/db4o/ObjectDatabaseConnection.cs
index 9e8e57a..7149d25 100644
--- a/product/database/db4o/DatabaseConnection.cs
+++ b/product/database/db4o/ObjectDatabaseConnection.cs
@@ -5,11 +5,11 @@ using momoney.database.transactions;
namespace momoney.database.db4o
{
- public class DatabaseConnection : IDatabaseConnection
+ public class ObjectDatabaseConnection : DatabaseConnection
{
readonly IObjectContainer container;
- public DatabaseConnection(IObjectContainer container)
+ public ObjectDatabaseConnection(IObjectContainer container)
{
this.container = container;
}
diff --git a/product/database/transactions/ChangeTracker.cs b/product/database/transactions/ChangeTracker.cs
index 4bfd41a..b6d12f2 100644
--- a/product/database/transactions/ChangeTracker.cs
+++ b/product/database/transactions/ChangeTracker.cs
@@ -8,11 +8,11 @@ namespace momoney.database.transactions
public class ChangeTracker<T> : IChangeTracker<T> where T : Identifiable<Guid>
{
readonly ITrackerEntryMapper<T> mapper;
- readonly IStatementRegistry registry;
+ readonly DatabaseCommandRegistry registry;
readonly IList<ITrackerEntry<T>> items;
readonly IList<T> to_be_deleted;
- public ChangeTracker(ITrackerEntryMapper<T> mapper, IStatementRegistry registry)
+ public ChangeTracker(ITrackerEntryMapper<T> mapper, DatabaseCommandRegistry registry)
{
this.mapper = mapper;
this.registry = registry;
@@ -33,7 +33,7 @@ namespace momoney.database.transactions
public void commit_to(IDatabase database)
{
items.each(x => commit(x, database));
- to_be_deleted.each(x => database.apply(registry.prepare_command_for(x)));
+ to_be_deleted.each(x => database.apply(registry.prepare_for_deletion(x)));
}
public bool is_dirty()
@@ -48,7 +48,7 @@ namespace momoney.database.transactions
void commit(ITrackerEntry<T> entry, IDatabase database)
{
- if (entry.has_changes()) database.apply(registry.prepare_command_for(entry.current));
+ if (entry.has_changes()) database.apply(registry.prepare_for_flushing(entry.current));
}
}
} \ No newline at end of file
diff --git a/product/database/transactions/ChangeTrackerFactory.cs b/product/database/transactions/ChangeTrackerFactory.cs
index a346cf8..940b2f6 100644
--- a/product/database/transactions/ChangeTrackerFactory.cs
+++ b/product/database/transactions/ChangeTrackerFactory.cs
@@ -6,10 +6,10 @@ namespace momoney.database.transactions
{
public class ChangeTrackerFactory : IChangeTrackerFactory
{
- readonly IStatementRegistry statement_registry;
+ readonly DatabaseCommandRegistry statement_registry;
readonly DependencyRegistry registry;
- public ChangeTrackerFactory(IStatementRegistry statement_registry, DependencyRegistry registry)
+ public ChangeTrackerFactory(DatabaseCommandRegistry statement_registry, DependencyRegistry registry)
{
this.statement_registry = statement_registry;
this.registry = registry;
diff --git a/product/database/transactions/ChangeTrackerSpecs.cs b/product/database/transactions/ChangeTrackerSpecs.cs
index ef0cbb7..0a1d1bc 100644
--- a/product/database/transactions/ChangeTrackerSpecs.cs
+++ b/product/database/transactions/ChangeTrackerSpecs.cs
@@ -15,11 +15,11 @@ namespace momoney.database.transactions
context c = () =>
{
mapper = the_dependency<ITrackerEntryMapper<Identifiable<Guid>>>();
- registry = the_dependency<IStatementRegistry>();
+ registry = the_dependency<DatabaseCommandRegistry>();
};
static protected ITrackerEntryMapper<Identifiable<Guid>> mapper;
- static protected IStatementRegistry registry;
+ static protected DatabaseCommandRegistry registry;
}
[Concern(typeof (ChangeTracker<Identifiable<Guid>>))]
@@ -30,14 +30,14 @@ namespace momoney.database.transactions
context c = () =>
{
item = an<Identifiable<Guid>>();
- statement = an<IStatement>();
+ statement = an<DatabaseCommand>();
database = an<IDatabase>();
var entry = an<ITrackerEntry<Identifiable<Guid>>>();
when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(entry);
when_the(entry).is_told_to(x => x.has_changes()).it_will_return(true);
when_the(entry).is_told_to(x => x.current).it_will_return(item);
- when_the(registry).is_told_to(x => x.prepare_command_for(item)).it_will_return(statement);
+ when_the(registry).is_told_to(x => x.prepare_for_flushing(item)).it_will_return(statement);
};
because b = () =>
@@ -48,7 +48,7 @@ namespace momoney.database.transactions
static Identifiable<Guid> item;
static IDatabase database;
- static IStatement statement;
+ static DatabaseCommand statement;
}
[Concern(typeof (ChangeTracker<Identifiable<Guid>>))]
diff --git a/product/database/transactions/DatabaseCommand.cs b/product/database/transactions/DatabaseCommand.cs
new file mode 100644
index 0000000..0f1f283
--- /dev/null
+++ b/product/database/transactions/DatabaseCommand.cs
@@ -0,0 +1,8 @@
+using gorilla.commons.utility;
+
+namespace momoney.database.transactions
+{
+ public interface DatabaseCommand : ParameterizedCommand<DatabaseConnection>
+ {
+ }
+} \ No newline at end of file
diff --git a/product/database/transactions/DatabaseCommandRegistry.cs b/product/database/transactions/DatabaseCommandRegistry.cs
new file mode 100644
index 0000000..16f01c8
--- /dev/null
+++ b/product/database/transactions/DatabaseCommandRegistry.cs
@@ -0,0 +1,11 @@
+using System;
+using gorilla.commons.utility;
+
+namespace momoney.database.transactions
+{
+ public interface DatabaseCommandRegistry
+ {
+ DatabaseCommand prepare_for_deletion<T>(T entity) where T : Identifiable<Guid>;
+ DatabaseCommand prepare_for_flushing<T>(T entity) where T : Identifiable<Guid>;
+ }
+} \ No newline at end of file
diff --git a/product/database/transactions/IDatabaseConnection.cs b/product/database/transactions/DatabaseConnection.cs
index 98f79f4..19bd725 100644
--- a/product/database/transactions/IDatabaseConnection.cs
+++ b/product/database/transactions/DatabaseConnection.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace momoney.database.transactions
{
- public interface IDatabaseConnection : IDisposable
+ public interface DatabaseConnection : IDisposable
{
IEnumerable<T> query<T>();
IEnumerable<T> query<T>(Predicate<T> predicate);
diff --git a/product/database/transactions/DeleteFromDatabase.cs b/product/database/transactions/DeleteFromDatabase.cs
new file mode 100644
index 0000000..07c2879
--- /dev/null
+++ b/product/database/transactions/DeleteFromDatabase.cs
@@ -0,0 +1,17 @@
+namespace momoney.database.transactions
+{
+ public class DeleteFromDatabase<T> : DatabaseCommand
+ {
+ readonly T entity;
+
+ public DeleteFromDatabase(T entity)
+ {
+ this.entity = entity;
+ }
+
+ public void run(DatabaseConnection connection)
+ {
+ connection.delete(entity);
+ }
+ }
+} \ No newline at end of file
diff --git a/product/database/transactions/IDatabase.cs b/product/database/transactions/IDatabase.cs
index 433f52a..4401e64 100644
--- a/product/database/transactions/IDatabase.cs
+++ b/product/database/transactions/IDatabase.cs
@@ -7,6 +7,6 @@ namespace momoney.database.transactions
public interface IDatabase
{
IEnumerable<T> fetch_all<T>() where T : Identifiable<Guid>;
- void apply(IStatement statement);
+ void apply(DatabaseCommand command);
}
} \ No newline at end of file
diff --git a/product/database/transactions/IStatement.cs b/product/database/transactions/IStatement.cs
deleted file mode 100644
index ea2092f..0000000
--- a/product/database/transactions/IStatement.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace momoney.database.transactions
-{
- public interface IStatement
- {
- void prepare(IDatabaseConnection connection);
- }
-} \ No newline at end of file
diff --git a/product/database/transactions/IStatementRegistry.cs b/product/database/transactions/IStatementRegistry.cs
deleted file mode 100644
index e2b3b16..0000000
--- a/product/database/transactions/IStatementRegistry.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using System;
-using gorilla.commons.utility;
-
-namespace momoney.database.transactions
-{
- public interface IStatementRegistry
- {
- IStatement prepare_delete_statement_for<T>(T entity) where T : Identifiable<Guid>;
- IStatement prepare_command_for<T>(T entity) where T : Identifiable<Guid>;
- }
-} \ No newline at end of file
diff --git a/product/database/transactions/ObjectDatabaseCommandRegistry.cs b/product/database/transactions/ObjectDatabaseCommandRegistry.cs
new file mode 100644
index 0000000..8b2d97e
--- /dev/null
+++ b/product/database/transactions/ObjectDatabaseCommandRegistry.cs
@@ -0,0 +1,18 @@
+using System;
+using gorilla.commons.utility;
+
+namespace momoney.database.transactions
+{
+ public class ObjectDatabaseCommandRegistry : DatabaseCommandRegistry
+ {
+ public DatabaseCommand prepare_for_deletion<T>(T entity) where T : Identifiable<Guid>
+ {
+ return new DeleteFromDatabase<T>(entity);
+ }
+
+ public DatabaseCommand prepare_for_flushing<T>(T entity) where T : Identifiable<Guid>
+ {
+ return new SaveOrUpdateFromDatabase<T>(entity);
+ }
+ }
+} \ No newline at end of file
diff --git a/product/database/transactions/SaveOrUpdateFromDatabase.cs b/product/database/transactions/SaveOrUpdateFromDatabase.cs
new file mode 100644
index 0000000..c8babda
--- /dev/null
+++ b/product/database/transactions/SaveOrUpdateFromDatabase.cs
@@ -0,0 +1,20 @@
+using System;
+using gorilla.commons.utility;
+
+namespace momoney.database.transactions
+{
+ public class SaveOrUpdateFromDatabase<T> : DatabaseCommand where T : Identifiable<Guid>
+ {
+ readonly T entity;
+
+ public SaveOrUpdateFromDatabase(T entity)
+ {
+ this.entity = entity;
+ }
+
+ public void run(DatabaseConnection connection)
+ {
+ connection.store(entity);
+ }
+ }
+} \ No newline at end of file
diff --git a/product/database/transactions/StatementRegistry.cs b/product/database/transactions/StatementRegistry.cs
deleted file mode 100644
index 66ca362..0000000
--- a/product/database/transactions/StatementRegistry.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using System;
-using gorilla.commons.utility;
-
-namespace momoney.database.transactions
-{
- public class StatementRegistry : IStatementRegistry
- {
- public IStatement prepare_delete_statement_for<T>(T entity) where T : Identifiable<Guid>
- {
- return new DeletionStatement<T>(entity);
- }
-
- public IStatement prepare_command_for<T>(T entity) where T : Identifiable<Guid>
- {
- return new SaveOrUpdateStatement<T>(entity);
- }
- }
-
- public class SaveOrUpdateStatement<T> : IStatement where T : Identifiable<Guid>
- {
- readonly T entity;
-
- public SaveOrUpdateStatement(T entity)
- {
- this.entity = entity;
- }
-
- public void prepare(IDatabaseConnection connection)
- {
- connection.store(entity);
- }
- }
-
- public class DeletionStatement<T> : IStatement
- {
- readonly T entity;
-
- public DeletionStatement(T entity)
- {
- this.entity = entity;
- }
-
- public void prepare(IDatabaseConnection connection)
- {
- connection.delete(entity);
- }
- }
-} \ No newline at end of file