Exemple #1
0
 public void Add(IFeatureSchema feature)
 {
     if (!_features.ContainsKey(feature.StorageType))
     {
         _features[feature.StorageType] = feature;
     }
 }
Exemple #2
0
 public static void AssertValidNames(this IFeatureSchema schema, StoreOptions options)
 {
     foreach (var objectName in schema.Objects.SelectMany(x => x.AllNames()))
     {
         options.AssertValidIdentifier(objectName.Name);
     }
 }
Exemple #3
0
 public static void WriteDropStatements(this IFeatureSchema schema, DdlRules rules, StringWriter writer)
 {
     foreach (var schemaObject in schema.Objects)
     {
         schemaObject.WriteDropStatement(rules, writer);
     }
 }
Exemple #4
0
        private void generateOrUpdateFeature(Type featureType, IFeatureSchema feature)
        {
            lock (_updateLock)
            {
                using (var conn = _factory.Create())
                {
                    conn.Open();

                    var patch = new SchemaPatch(_options.DdlRules);
                    patch.Apply(conn, _options.AutoCreateSchemaObjects, feature.Objects);
                    patch.AssertPatchingIsValid(_options.AutoCreateSchemaObjects);

                    var ddl = patch.UpdateDDL;
                    if (patch.Difference != SchemaPatchDifference.None && ddl.IsNotEmpty())
                    {
                        var cmd = conn.CreateCommand(ddl);
                        try
                        {
                            cmd.ExecuteNonQuery();
                            _options.Logger().SchemaChange(ddl);
                            RegisterCheck(featureType, feature);
                        }
                        catch (Exception e)
                        {
                            throw new MartenCommandException(cmd, e);
                        }
                    }
                    else if (patch.Difference == SchemaPatchDifference.None)
                    {
                        RegisterCheck(featureType, feature);
                    }
                }
            }
        }
Exemple #5
0
 private void RegisterCheck(Type featureType, IFeatureSchema feature)
 {
     _checks[featureType] = true;
     if (feature.StorageType != featureType)
     {
         _checks[feature.StorageType] = true;
     }
 }
Exemple #6
0
        public static void Write(this IFeatureSchema schema, DdlRules rules, StringWriter writer)
        {
            foreach (var schemaObject in schema.Objects)
            {
                schemaObject.Write(rules, writer);
            }

            schema.WritePermissions(rules, writer);
        }
Exemple #7
0
        public static void RemoveAllObjects(this IFeatureSchema schema, DdlRules rules, NpgsqlConnection conn)
        {
            var writer = new StringWriter();

            schema.WriteDropStatements(rules, writer);

            var sql = writer.ToString();
            var cmd = conn.CreateCommand(sql);

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw MartenCommandExceptionFactory.Create(cmd, e);
            }
        }
Exemple #8
0
 /// <summary>
 /// Register custom storage features
 /// </summary>
 /// <param name="feature"></param>
 public void Add(IFeatureSchema feature)
 {
     _features.Add(feature.StorageType, feature);
 }
Exemple #9
0
 public static void AssertValidNames(this IFeatureSchema schema, StoreOptions options)
 {
     AssertValidNames(schema.Objects, options);
 }
Exemple #10
0
 private void store(IFeatureSchema feature)
 {
     _features.Add(feature.StorageType, feature);
 }