Esempio n. 1
0
 public BiggyDocumentStore(DbCache dbCache)
 {
     this.DbCache      = dbCache;
     this.Model        = this.getModel();
     this.TableMapping = this.getTableMappingForT();
     SetFullTextColumns();
     TryLoadData();
 }
Esempio n. 2
0
 public BiggyDocumentStore(DbCache dbCache, string tableName)
 {
     _userDefinedTableName = tableName;
     this.DbCache          = dbCache;
     this.Model            = this.getModel();
     this.TableMapping     = this.getTableMappingForT();
     SetFullTextColumns();
     TryLoadData();
 }
Esempio n. 3
0
        public DBTableMapping getTableMappingForT()
        {
            var result = new DBTableMapping(this.DbCache.DbDelimiterFormatString);

            result.DBTableName = this.DecideTableName();
            var pk = this.getPrimaryKeyForT();

            result.PrimaryKeyMapping.Add(pk);
            result.ColumnMappings.Add(pk);
            result.ColumnMappings.Add("body", "body");
            result.ColumnMappings.Add("search", "search");
            return(result);
        }
Esempio n. 4
0
 public BiggyRelationalStore(DbCache dbCache)
 {
     this.Cache        = dbCache;
     this.TableMapping = this.getTableMappingForT();
 }
Esempio n. 5
0
        public virtual DBTableMapping getTableMappingFor <T>() where T : new()
        {
            var result     = new DBTableMapping(this.DbDelimiterFormatString);
            var item       = new T();
            var itemType   = item.GetType();
            var properties = itemType.GetProperties();

            string replaceString = "[^a-zA-Z1-9]";
            var    rgx           = new Regex(replaceString);

            string flattenedItemTypeName = rgx.Replace(itemType.Name.ToLower(), "");
            string plural      = Inflector.Inflector.Pluralize(flattenedItemTypeName);
            var    dbTableName = this.DbTableNames.FirstOrDefault(t => rgx.Replace(t.ToLower(), "") == flattenedItemTypeName);

            if (dbTableName == null)
            {
                dbTableName = this.DbTableNames.FirstOrDefault(t => rgx.Replace(t.ToLower(), "") == plural);
            }
            else
            {
                var tableNameAttribute = itemType.GetCustomAttributes(false).FirstOrDefault(a => a.GetType() == typeof(DbTableAttribute)) as DbTableAttribute;
                if (tableNameAttribute != null)
                {
                    dbTableName = tableNameAttribute.Name;
                }
            }

            result.DBTableName    = dbTableName;
            result.MappedTypeName = itemType.Name;

            var dbColumnInfo = from c in this.DbColumnsList where c.TableName == dbTableName select c;

            foreach (var property in properties)
            {
                string          flattenedPropertyName = rgx.Replace(property.Name.ToLower(), "");
                DbColumnMapping columnMapping         = dbColumnInfo.FirstOrDefault(c => rgx.Replace(c.ColumnName.ToLower(), "") == flattenedPropertyName);
                if (columnMapping != null)
                {
                    columnMapping.PropertyName = property.Name;
                    columnMapping.DataType     = itemType;
                }
                else
                {
                    // Look for a custom column name attribute:
                    DbColumnAttribute mappedColumnAttribute = null;
                    var attribute = property.GetCustomAttributes(false).FirstOrDefault(a => a.GetType() == typeof(DbColumnAttribute));
                    if (attribute != null)
                    {
                        // Use the column name found in the attribute:
                        mappedColumnAttribute = attribute as DbColumnAttribute;
                        string matchColumnName = mappedColumnAttribute.Name;
                        columnMapping = dbColumnInfo.FirstOrDefault(c => c.ColumnName == matchColumnName);
                        columnMapping.PropertyName = property.Name;
                        columnMapping.DataType     = itemType;
                    }
                }
                if (columnMapping != null)
                {
                    result.ColumnMappings.Add(columnMapping);
                    if (columnMapping.IsPrimaryKey)
                    {
                        result.PrimaryKeyMapping.Add(columnMapping);
                    }
                }
            }
            return(result);
        }