Skip to content

Commit

Permalink
Cleanup unneeded code (#246)
Browse files Browse the repository at this point in the history
* remove some unnecessary stuff
  • Loading branch information
ChrisJollyAU committed Jun 26, 2024
1 parent 2d5930a commit d20cafa
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 528 deletions.
90 changes: 0 additions & 90 deletions src/EFCore.Jet/Extensions/JetModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,95 +126,5 @@ public static void SetValueGenerationStrategy([NotNull] this IMutableModel model
/// <returns> The <see cref="ConfigurationSource" /> for the default <see cref="JetValueGenerationStrategy" />. </returns>
public static ConfigurationSource? GetJetValueGenerationStrategyConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(JetAnnotationNames.ValueGenerationStrategy)?.GetConfigurationSource();

/// <summary>
/// Returns the suffix to append to the name of automatically created sequences.
/// </summary>
/// <param name="model">The model.</param>
/// <returns>The name to use for the default key value generation sequence.</returns>
public static string GetJetSequenceNameSuffix(this IReadOnlyModel model)
=> (string?)model[JetAnnotationNames.SequenceNameSuffix]
?? DefaultSequenceNameSuffix;

/// <summary>
/// Sets the suffix to append to the name of automatically created sequences.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="name">The value to set.</param>
public static void SetJetSequenceNameSuffix(this IMutableModel model, string? name)
{
Check.NullButNotEmpty(name, nameof(name));

model.SetOrRemoveAnnotation(JetAnnotationNames.SequenceNameSuffix, name);
}

/// <summary>
/// Sets the suffix to append to the name of automatically created sequences.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="name">The value to set.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetJetSequenceNameSuffix(
this IConventionModel model,
string? name,
bool fromDataAnnotation = false)
=> (string?)model.SetOrRemoveAnnotation(
JetAnnotationNames.SequenceNameSuffix,
Check.NullButNotEmpty(name, nameof(name)),
fromDataAnnotation)?.Value;

/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for the default value generation sequence name suffix.
/// </summary>
/// <param name="model">The model.</param>
/// <returns>The <see cref="ConfigurationSource" /> for the default key value generation sequence name.</returns>
public static ConfigurationSource? GetJetSequenceNameSuffixConfigurationSource(this IConventionModel model)
=> model.FindAnnotation(JetAnnotationNames.SequenceNameSuffix)?.GetConfigurationSource();

/// <summary>
/// Returns the schema to use for the default value generation sequence.
/// <see cref="JetPropertyBuilderExtensions.UseSequence" />
/// </summary>
/// <param name="model">The model.</param>
/// <returns>The schema to use for the default key value generation sequence.</returns>
public static string? GetJetSequenceSchema(this IReadOnlyModel model)
=> (string?)model[JetAnnotationNames.SequenceSchema];

/// <summary>
/// Sets the schema to use for the default key value generation sequence.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="value">The value to set.</param>
public static void SetJetSequenceSchema(this IMutableModel model, string? value)
{
Check.NullButNotEmpty(value, nameof(value));

model.SetOrRemoveAnnotation(JetAnnotationNames.SequenceSchema, value);
}

/// <summary>
/// Sets the schema to use for the default key value generation sequence.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="value">The value to set.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetJetSequenceSchema(
this IConventionModel model,
string? value,
bool fromDataAnnotation = false)
=> (string?)model.SetOrRemoveAnnotation(
JetAnnotationNames.SequenceSchema,
Check.NullButNotEmpty(value, nameof(value)),
fromDataAnnotation)?.Value;

/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for the default key value generation sequence schema.
/// </summary>
/// <param name="model">The model.</param>
/// <returns>The <see cref="ConfigurationSource" /> for the default key value generation sequence schema.</returns>
public static ConfigurationSource? GetJetSequenceSchemaConfigurationSource(this IConventionModel model)
=> model.FindAnnotation(JetAnnotationNames.SequenceSchema)?.GetConfigurationSource();
}
}
172 changes: 0 additions & 172 deletions src/EFCore.Jet/Extensions/JetPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,177 +376,5 @@ public static bool IsCompatibleWithValueGeneration([NotNull] IReadOnlyProperty p
return (type.IsInteger()
|| type == typeof(decimal));
}

/// <summary>
/// Returns the name to use for the key value generation sequence.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>The name to use for the key value generation sequence.</returns>
public static string? GetJetSequenceName(this IReadOnlyProperty property)
=> (string?)property[JetAnnotationNames.SequenceName];

/// <summary>
/// Returns the name to use for the key value generation sequence.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="storeObject">The identifier of the store object.</param>
/// <returns>The name to use for the key value generation sequence.</returns>
public static string? GetJetSequenceName(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
{
var annotation = property.FindAnnotation(JetAnnotationNames.SequenceName);
if (annotation != null)
{
return (string?)annotation.Value;
}

return property.FindSharedStoreObjectRootProperty(storeObject)?.GetJetSequenceName(storeObject);
}

/// <summary>
/// Sets the name to use for the key value generation sequence.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="name">The sequence name to use.</param>
public static void SetJetSequenceName(this IMutableProperty property, string? name)
=> property.SetOrRemoveAnnotation(
JetAnnotationNames.SequenceName,
Check.NullButNotEmpty(name, nameof(name)));

/// <summary>
/// Sets the name to use for the key value generation sequence.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="name">The sequence name to use.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetJetSequenceName(
this IConventionProperty property,
string? name,
bool fromDataAnnotation = false)
=> (string?)property.SetOrRemoveAnnotation(
JetAnnotationNames.SequenceName,
Check.NullButNotEmpty(name, nameof(name)),
fromDataAnnotation)?.Value;

/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for the key value generation sequence name.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>The <see cref="ConfigurationSource" /> for the key value generation sequence name.</returns>
public static ConfigurationSource? GetJetSequenceNameConfigurationSource(this IConventionProperty property)
=> property.FindAnnotation(JetAnnotationNames.SequenceName)?.GetConfigurationSource();

/// <summary>
/// Returns the schema to use for the key value generation sequence.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>The schema to use for the key value generation sequence.</returns>
public static string? GetJetSequenceSchema(this IReadOnlyProperty property)
=> (string?)property[JetAnnotationNames.SequenceSchema];

/// <summary>
/// Returns the schema to use for the key value generation sequence.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="storeObject">The identifier of the store object.</param>
/// <returns>The schema to use for the key value generation sequence.</returns>
public static string? GetJetSequenceSchema(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
{
var annotation = property.FindAnnotation(JetAnnotationNames.SequenceSchema);
if (annotation != null)
{
return (string?)annotation.Value;
}

return property.FindSharedStoreObjectRootProperty(storeObject)?.GetJetSequenceSchema(storeObject);
}

/// <summary>
/// Sets the schema to use for the key value generation sequence.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="schema">The schema to use.</param>
public static void SetJetSequenceSchema(this IMutableProperty property, string? schema)
=> property.SetOrRemoveAnnotation(
JetAnnotationNames.SequenceSchema,
Check.NullButNotEmpty(schema, nameof(schema)));

/// <summary>
/// Sets the schema to use for the key value generation sequence.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="schema">The schema to use.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetJetSequenceSchema(
this IConventionProperty property,
string? schema,
bool fromDataAnnotation = false)
=> (string?)property.SetOrRemoveAnnotation(
JetAnnotationNames.SequenceSchema,
Check.NullButNotEmpty(schema, nameof(schema)),
fromDataAnnotation)?.Value;

/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for the key value generation sequence schema.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>The <see cref="ConfigurationSource" /> for the key value generation sequence schema.</returns>
public static ConfigurationSource? GetGetSequenceSchemaConfigurationSource(this IConventionProperty property)
=> property.FindAnnotation(JetAnnotationNames.SequenceSchema)?.GetConfigurationSource();

/// <summary>
/// Finds the <see cref="ISequence" /> in the model to use for the key value generation pattern.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>The sequence to use, or <see langword="null" /> if no sequence exists in the model.</returns>
public static IReadOnlySequence? FindJetSequence(this IReadOnlyProperty property)
{
var model = property.DeclaringType.Model;

var sequenceName = property.GetJetSequenceName()
?? model.GetJetSequenceNameSuffix();

var sequenceSchema = property.GetJetSequenceSchema()
?? model.GetJetSequenceSchema();

return model.FindSequence(sequenceName, sequenceSchema);
}

/// <summary>
/// Finds the <see cref="ISequence" /> in the model to use for the key value generation pattern.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="storeObject">The identifier of the store object.</param>
/// <returns>The sequence to use, or <see langword="null" /> if no sequence exists in the model.</returns>
public static IReadOnlySequence? FindJetSequence(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
{
var model = property.DeclaringType.Model;

var sequenceName = property.GetJetSequenceName(storeObject)
?? model.GetJetSequenceNameSuffix();

var sequenceSchema = property.GetJetSequenceSchema(storeObject)
?? model.GetJetSequenceSchema();

return model.FindSequence(sequenceName, sequenceSchema);
}

/// <summary>
/// Finds the <see cref="ISequence" /> in the model to use for the key value generation pattern.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>The sequence to use, or <see langword="null" /> if no sequence exists in the model.</returns>
public static ISequence? FindJetSequence(this IProperty property)
=> (ISequence?)((IReadOnlyProperty)property).FindJetSequence();

/// <summary>
/// Finds the <see cref="ISequence" /> in the model to use for the key value generation pattern.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="storeObject">The identifier of the store object.</param>
/// <returns>The sequence to use, or <see langword="null" /> if no sequence exists in the model.</returns>
public static ISequence? FindJetSequence(this IProperty property, in StoreObjectIdentifier storeObject)
=> (ISequence?)((IReadOnlyProperty)property).FindJetSequence(storeObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,6 @@ public class JetValueGenerationStrategyConvention : IModelInitializedConvention,
&& declaringTable.Name != null)
{
property.Builder.HasValueGenerationStrategy(strategy);

if (strategy == JetValueGenerationStrategy.Sequence)
{
var sequence = modelBuilder.HasSequence(
property.GetJetSequenceName(declaringTable)
?? entityType.GetRootType().ShortName() + modelBuilder.Metadata.GetJetSequenceNameSuffix(),
property.GetJetSequenceSchema(declaringTable)
?? modelBuilder.Metadata.GetJetSequenceSchema()).Metadata;

property.Builder.HasDefaultValueSql(
RelationalDependencies.UpdateSqlGenerator.GenerateObtainNextSequenceValueOperation(
sequence.Name, sequence.Schema));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public JetByteArrayMethodTranslator(ISqlExpressionFactory sqlExpressionFactory)
{
if (method == ByteArrayLength)
{
var isBinaryMaxDataType = GetProviderType(arguments[1]) == "varbinary(max)" || arguments[1] is SqlParameterExpression;
var isBinaryMaxDataType = arguments[1] is SqlParameterExpression;
SqlExpression dataLengthSqlFunction = _sqlExpressionFactory.Function(
"LENB",
new[] { arguments[1] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,29 +301,12 @@ public JetStringMethodTranslator(ISqlExpressionFactory sqlExpressionFactory)

var argumentsPropagateNullability = Enumerable.Repeat(true, charIndexArguments.Count);

SqlExpression charIndexExpression;
var storeType = stringTypeMapping.StoreType;
if (string.Equals(storeType, "nvarchar(max)", StringComparison.OrdinalIgnoreCase)
|| string.Equals(storeType, "varchar(max)", StringComparison.OrdinalIgnoreCase))
{
charIndexExpression = _sqlExpressionFactory.Function(
"INSTR",
charIndexArguments,
nullable: true,
argumentsPropagateNullability,
typeof(long));

charIndexExpression = _sqlExpressionFactory.Convert(charIndexExpression, typeof(int));
}
else
{
charIndexExpression = _sqlExpressionFactory.Function(
"INSTR",
charIndexArguments,
nullable: true,
argumentsPropagateNullability,
method.ReturnType);
}
SqlExpression charIndexExpression = charIndexExpression = _sqlExpressionFactory.Function(
"INSTR",
charIndexArguments,
nullable: true,
argumentsPropagateNullability,
method.ReturnType);

charIndexExpression = _sqlExpressionFactory.Subtract(charIndexExpression, _sqlExpressionFactory.Constant(1));

Expand Down
8 changes: 0 additions & 8 deletions src/EFCore.Jet/Storage/Internal/JetTypeMappingSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public class JetTypeMappingSource : RelationalTypeMappingSource
{"binary", new []{_fixedLengthBinary}},

{"varbinary", new []{_variableLengthBinary}},
{"varbinary(max)", new[] { _variableLengthMaxBinary }},
{"binary varying", new[] { _variableLengthBinary }},
{"bit varying", new[] { _variableLengthBinary }},

Expand Down Expand Up @@ -172,13 +171,6 @@ public class JetTypeMappingSource : RelationalTypeMappingSource
{"national char varying", new[] { _variableLengthUnicodeString }},
{"national character varying", new[] { _variableLengthUnicodeString }},

{"varchar(max)", new[] { _variableLengthMaxUnicodeString }},
{"string(max)", new[] { _variableLengthMaxUnicodeString }},
{"char varying(max)", new[] { _variableLengthMaxUnicodeString }},
{"character varying(max)", new[] { _variableLengthMaxUnicodeString }},
{"national char varying(max)", new[] { _variableLengthMaxUnicodeString }},
{"national character varying(max)", new[] { _variableLengthMaxUnicodeString }},

{"longchar", new[] { _unboundedUnicodeString }},
{"longtext", new[] { _unboundedUnicodeString }},
{"memo", new[] { _unboundedUnicodeString }},
Expand Down
Loading

0 comments on commit d20cafa

Please sign in to comment.