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

Public Member Functions

TypeMappingConfiguration< T > Map< T > ()
 
TypeMappingConfiguration< T > Map< T > (TypeMappingConfiguration< T > configuration)
 

Package Functions

 MappingContext ()
 
MappingModel CreateModel ()
 

Properties

INamingConvention TableNameConvention [get, set]
 
INamingConvention ColumnNameConvention [get, set]
 

Private Member Functions

string GetTableName (ITypeMappingConfiguration configuration)
 
TypeMapping CreateTypeMapping (MappingModel model, ITypeMappingConfiguration configuration)
 
MemberMapping MapMember (TypeMapping mapping, IMemberMappingConfiguration configuration)
 
string GetColumnName (IMemberMappingConfiguration configuration)
 
SqlType FormSqlType (IMemberMappingConfiguration configuration)
 
SqlTypeCode DiscoverSqlType (MemberInfo member)
 

Private Attributes

Dictionary< Type, ITypeMappingConfigurationconfigurations
 

Detailed Description

Definition at line 10 of file MappingContext.cs.

Constructor & Destructor Documentation

Deveel.Data.Mapping.MappingContext.MappingContext ( )
inlinepackage

Definition at line 13 of file MappingContext.cs.

13  {
14  TableNameConvention = RuledNamingConvention.SqlNaming;
15  ColumnNameConvention = RuledNamingConvention.SqlNaming;
16  }
INamingConvention ColumnNameConvention

Member Function Documentation

MappingModel Deveel.Data.Mapping.MappingContext.CreateModel ( )
inlinepackage

Definition at line 47 of file MappingContext.cs.

47  {
48  var model = new MappingModel();
49  if (configurations != null) {
50  foreach (var configuration in configurations.Values) {
51  var mapping = CreateTypeMapping(model, configuration);
52 
53  // TODO: make relationships...
54 
55  model.Map(mapping);
56  }
57  }
58 
59  return model;
60  }
Dictionary< Type, ITypeMappingConfiguration > configurations
TypeMapping CreateTypeMapping(MappingModel model, ITypeMappingConfiguration configuration)
TypeMapping Deveel.Data.Mapping.MappingContext.CreateTypeMapping ( MappingModel  model,
ITypeMappingConfiguration  configuration 
)
inlineprivate

Definition at line 73 of file MappingContext.cs.

73  {
74  var tableName = GetTableName(configuration);
75  var mapping = new TypeMapping(model, configuration.ElementType, tableName);
76 
77  foreach (var pair in configuration.Members) {
78  var member = pair.Value;
79  var memberMapping = MapMember(mapping, member);
80  mapping.AddMember(memberMapping);
81  }
82 
83  return mapping;
84  }
string GetTableName(ITypeMappingConfiguration configuration)
MemberMapping MapMember(TypeMapping mapping, IMemberMappingConfiguration configuration)
SqlTypeCode Deveel.Data.Mapping.MappingContext.DiscoverSqlType ( MemberInfo  member)
inlineprivate

Definition at line 122 of file MappingContext.cs.

122  {
123  var memberType = TypeHelper.GetMemberType(member);
124  if (memberType == typeof(bool))
125  return SqlTypeCode.Boolean;
126  if (memberType == typeof(byte))
127  return SqlTypeCode.TinyInt;
128  if (memberType == typeof(short))
129  return SqlTypeCode.SmallInt;
130  if (memberType == typeof(int))
131  return SqlTypeCode.Integer;
132  if (memberType == typeof (long))
133  return SqlTypeCode.BigInt;
134 
135  if (memberType == typeof(string))
136  return SqlTypeCode.VarChar;
137 
138  throw new NotSupportedException();
139  }
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
SqlType Deveel.Data.Mapping.MappingContext.FormSqlType ( IMemberMappingConfiguration  configuration)
inlineprivate

Definition at line 108 of file MappingContext.cs.

108  {
109  var sqlType = configuration.ColumnType;
110  if (sqlType == null)
111  sqlType = DiscoverSqlType(configuration.Member);
112 
113  var meta = new List<DataTypeMeta>();
114  if (configuration.Size != null)
115  meta.Add(new DataTypeMeta("Size", configuration.Size.Value.ToString()));
116  if (configuration.Precision != null)
117  meta.Add(new DataTypeMeta("Precision", configuration.Precision.Value.ToString()));
118 
119  return SqlType.Resolve(sqlType.Value, meta.ToArray());
120  }
SqlTypeCode DiscoverSqlType(MemberInfo member)
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
static SqlType Resolve(SqlTypeCode typeCode)
Definition: SqlType.cs:441
string Deveel.Data.Mapping.MappingContext.GetColumnName ( IMemberMappingConfiguration  configuration)
inlineprivate

Definition at line 97 of file MappingContext.cs.

97  {
98  var columnName = configuration.ColumnName;
99  if (String.IsNullOrEmpty(columnName))
100  columnName = configuration.Member.Name;
101 
102  if (ColumnNameConvention != null)
103  columnName = ColumnNameConvention.FormatName(columnName);
104 
105  return columnName;
106  }
INamingConvention ColumnNameConvention
A long string in the system.
string FormatName(string inputName)
string Deveel.Data.Mapping.MappingContext.GetTableName ( ITypeMappingConfiguration  configuration)
inlineprivate

Definition at line 62 of file MappingContext.cs.

62  {
63  var tableName = configuration.TableName;
64  if (String.IsNullOrEmpty(tableName))
65  tableName = configuration.ElementType.Name;
66 
67  if (TableNameConvention != null)
68  tableName = TableNameConvention.FormatName(tableName);
69 
70  return tableName;
71  }
A long string in the system.
string FormatName(string inputName)
TypeMappingConfiguration<T> Deveel.Data.Mapping.MappingContext.Map< T > ( )
inline
Type Constraints
T :class 

Definition at line 22 of file MappingContext.cs.

22  : class {
23  return Map<T>(null);
24  }
TypeMappingConfiguration< T > Map< T >()
TypeMappingConfiguration<T> Deveel.Data.Mapping.MappingContext.Map< T > ( TypeMappingConfiguration< T >  configuration)
inline
Type Constraints
T :class 

Definition at line 26 of file MappingContext.cs.

26  : class {
27  if (configurations == null)
28  configurations = new Dictionary<Type, ITypeMappingConfiguration>();
29 
30  var type = typeof (T);
31 
32  if (configuration == null) {
33  ITypeMappingConfiguration config;
34  if (!configurations.TryGetValue(type, out config)) {
35  configuration = new TypeMappingConfiguration<T>();
36  configurations[type] = configuration;
37  } else {
38  configuration = (TypeMappingConfiguration<T>) config;
39  }
40  } else {
41  configurations[type] = configuration;
42  }
43 
44  return configuration;
45  }
Dictionary< Type, ITypeMappingConfiguration > configurations
MemberMapping Deveel.Data.Mapping.MappingContext.MapMember ( TypeMapping  mapping,
IMemberMappingConfiguration  configuration 
)
inlineprivate

Definition at line 86 of file MappingContext.cs.

86  {
87  // TODO: unique key, that is not UNIQUE
88  var sqlType = FormSqlType(configuration);
89  var notNull = (configuration.ColumnConstraints & ColumnConstraints.NotNull) != 0;
90  var primary = (configuration.ColumnConstraints & ColumnConstraints.PrimaryKey) != 0;
91  var unique = (configuration.ColumnConstraints & ColumnConstraints.Unique) != 0;
92  bool uniqueKey = mapping.IsUniqueKey(configuration.Member.Name);
93  var columnName = GetColumnName(configuration);
94  return new MemberMapping(mapping, configuration.Member, columnName, sqlType, notNull, primary, unique, uniqueKey);
95  }
string GetColumnName(IMemberMappingConfiguration configuration)
SqlType FormSqlType(IMemberMappingConfiguration configuration)

Member Data Documentation

Dictionary<Type, ITypeMappingConfiguration> Deveel.Data.Mapping.MappingContext.configurations
private

Definition at line 11 of file MappingContext.cs.

Property Documentation

INamingConvention Deveel.Data.Mapping.MappingContext.ColumnNameConvention
getset

Definition at line 20 of file MappingContext.cs.

INamingConvention Deveel.Data.Mapping.MappingContext.TableNameConvention
getset

Definition at line 18 of file MappingContext.cs.


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