public AttributeTypeCollection Read(EntityType entityType, IEntityTypeRepository entityTypeRepository) { var attributes = new AttributeTypeCollection(); using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format( "SELECT * FROM hsck.EntityAttributeTypes WHERE ParentEntityTypeName='{0}'", entityType.Name); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { while (reader.Read()) { var entityTypeName = (string) reader["ChildEntityTypeName"]; var attributeName = (string) reader["Name"]; EntityType ofType = entityTypeName == entityType.Name ? entityType : entityTypeRepository.Read(entityTypeName); var entityAttributeType = new EntityAttributeType { Id = (int) reader["Id"], Name = attributeName, OfType = ofType }; attributes.Add(entityAttributeType); } } } } return attributes; }
public void Create(EntityAttributeType entityAttributeType, EntityType onEntity) { using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format( "INSERT INTO hsck.EntityAttributeTypes (Name, ChildEntityTypeName, ParentEntityTypeName)" + "VALUES ('{0}', '{1}', '{2}')", entityAttributeType.Name, entityAttributeType.OfType.Name, onEntity.Name); sqlCommand.ExecuteNonQuery(); } using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("ALTER TABLE hsco.{0} ADD {1} {2}", onEntity.Name, entityAttributeType.Name, _dataTypeConverter.ToSqlType(DataType.Entity)); sqlCommand.ExecuteNonQuery(); } } }
private void CreateCollectionIfNotExist(EntityType entityType) { if (!_entitites.Keys.Contains(entityType)) { _entitites.Add(entityType, new List<Entity>()); } }
public AttributeTypeCollection Read(EntityType entityType, IEntityTypeRepository entityTypeRepository) { var attributes = new AttributeTypeCollection(); using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("SELECT * FROM hsck.AttributeTypes WHERE EntityTypeId='{0}'", entityType.Id); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { while (reader.Read()) { var dataType = (DataType) Enum.Parse(typeof (DataType), (string) reader["DataType"]); var attributeType = new AttributeType { Id = (int) reader["Id"], Name = (string) reader["Name"], DataType = dataType }; attributes.Add(attributeType); } } } } attributes.Add(_entityAttributeTypeRepository.Read(entityType, entityTypeRepository)); return attributes; }
public Entity Read(EntityType entityType, int id) { CreateCollectionIfNotExist(entityType); if (_entitites[entityType].Any(e => e.Id == id)) { return _entitites[entityType][id]; } return null; }
public Entity(EntityType entityType) { if (entityType == null) { throw new OperationException(); } EntityType = entityType; Attributes = new AttributeCollection(entityType.Attributes); }
public void Create(AttributeTypeCollection attributeTypeCollection, EntityType onEntity) { foreach (AttributeType attributeType in attributeTypeCollection) { if (attributeType is EntityAttributeType) { Create(attributeType as EntityAttributeType, onEntity); } } }
public void PopulateWithMockTypes() { var person = new EntityType("Person"); person.Attributes.Add(new AttributeType("Name", DataType.String256)); person.Attributes.Add(new AttributeType("Age", DataType.Integer)); person.Attributes.Add(new AttributeType("IsMale", DataType.Boolean)); person.Attributes.Add(new EntityAttributeType("Spouse", person)); _entityTypeRepository.Create(person); }
public void Delete(EntityType entityType, int id) { CreateCollectionIfNotExist(entityType); if (_entitites[entityType].Any(e => e.Id == id)) { Entity target = Read(entityType, id); _entitites[entityType].Remove(target); } }
public void Create(AttributeType attributeType, EntityType onEntity) { if (attributeType.Name == "Id") { return; } if (attributeType is EntityAttributeType) { _entityAttributeTypeRepository.Create((EntityAttributeType) attributeType, onEntity); return; } CreateValueAttribute(attributeType, onEntity); }
public void Create(EntityType entityType) { using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = GetInsertKnowledgeQuery(entityType.Name); var id = (int) sqlCommand.ExecuteScalar(); entityType.Id = id; } using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = GetCreateOperationTableQuery(entityType.Name); sqlCommand.ExecuteNonQuery(); } _sqlAttributeTypeRepository.Create(entityType.Attributes, entityType); } }
public EntityType Read(string name) { var entityType = new EntityType(); using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("SELECT * FROM hsck.EntityTypes WHERE Name='{0}'", name); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { reader.Read(); entityType.Id = (int) reader["id"]; entityType.Name = (string) reader["Name"]; } } } entityType.AddAttributes(_sqlAttributeTypeRepository.Read(entityType, this)); return entityType; }
public List<Entity> ReadAll(EntityType entityType) { var entities = new List<Entity>(); using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("SELECT * FROM hsco.{0}", entityType.Name); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { var loadedEntitites = new List<Entity>(); while (reader.Read()) { Entity entity = ReadEntity(reader, entityType, loadedEntitites); entities.Add(entity); } } } } return entities; }
public void Create(AttributeTypeCollection attributeTypeCollection, EntityType entityType) { foreach (AttributeType attributeType in attributeTypeCollection) { Create(attributeType, entityType); } }
private Entity GetLoadedEntity(List<Entity> loadedEntities, EntityType entityType, int id) { foreach (Entity loadedEntity in loadedEntities) { if (loadedEntity.EntityType == entityType && loadedEntity.Id == id) { return loadedEntity; } } return null; }
public List<EntityType> ReadAll() { var entityTypes = new List<EntityType>(); using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = "SELECT * FROM hsck.EntityTypes"; using (SqlDataReader reader = sqlCommand.ExecuteReader()) { while (reader.Read()) { var entityType = new EntityType { Id = (int) reader["id"], Name = (string) reader["Name"] }; entityType.AddAttributes(_sqlAttributeTypeRepository.Read(entityType, this)); entityTypes.Add(entityType); } } } } return entityTypes; }
public void Delete(EntityType entityType, int id) { throw new NotImplementedException(); }
private void CreateValueAttribute(AttributeType attributeType, EntityType onEntity) { using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("INSERT INTO hsck.AttributeTypes (Name, DataType, EntityTypeId) " + "VALUES ('{0}', '{1}', {2})", attributeType.Name, attributeType.DataType, onEntity.Id); sqlCommand.ExecuteNonQuery(); } using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("ALTER TABLE hsco.{0} ADD {1} {2}", onEntity.Name, attributeType.Name, _dataTypeConverter.ToSqlType(attributeType.DataType)); sqlCommand.ExecuteNonQuery(); } } }
public Entity Read(EntityType entityType, int id) { return Get(entityType, id, new List<Entity>()); }
public void Create(EntityType entityType) { EntityTypes.Add(entityType); }
public void Udpate(EntityType entityType) { throw new NotImplementedException(); }
private Entity ReadEntity(SqlDataReader reader, EntityType entityType, List<Entity> loadingEntities) { List<string> fields = GetAttributes(reader); var entity = new Entity(entityType); foreach (string field in fields) { if (field == "Id") { entity.Id = (int) reader["Id"]; loadingEntities.Add(entity); continue; } if (entityType.Attributes[field].DataType == DataType.Entity) { var entityAttributeType = (EntityAttributeType) entityType.Attributes[field]; Entity child = Get(entityAttributeType.OfType, (int) reader[field], loadingEntities); entity.Attributes[field].Value = child; } else { entity.Attributes[field].Value = reader[field]; } } return entity; }
public List<Entity> ReadAll(EntityType entityType) { CreateCollectionIfNotExist(entityType); return _entitites[entityType]; }
public Entity Get(EntityType entityType, int id, List<Entity> loadingEntities) { Entity entity = GetLoadedEntity(loadingEntities, entityType, id); if (entity == null) { using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("SELECT * FROM hsco.{0} WHERE Id={1}", entityType.Name, id); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { reader.Read(); entity = ReadEntity(reader, entityType, loadingEntities); } } } } return entity; }
public void Update(EntityType entityType, AttributeType attributeType) { }