private void InitializeSqlStatements(IHiLoConfiguration config) { _sqlStatementToGetLatestNextHiValue = PrepareSqlStatement("SELECT {1} FROM {0} WHERE {2} = {3}", config); _sqlStatementToUpdateNextHiValue = PrepareSqlStatement("UPDATE {0} SET {1} = {1} + 1 WHERE {2} = {3}", config); _sqlStatementToCreateRepository = PrepareSqlStatement("CREATE TABLE IF NOT EXISTS `{0}` ( `{2}` varchar(100) NOT NULL, `{1}` BIGINT NOT NULL, PRIMARY KEY (`{2}`));", config); _sqlStatementToInitializeEntity = PrepareSqlStatement("INSERT IGNORE INTO `{0}` SET {2} = {3}, {1} = 1;", config); }
private void InitializeSqlStatements(IHiLoConfiguration config) { _sqlStatementToSelectAndUpdateNextHiValue = PrepareSqlStatement("SELECT {1} FROM {0} WHERE {2} = {3};UPDATE {0} SET {1} = {1} + 1 WHERE {2} = {3};", config); _sqlStatementToCreateRepository = PrepareSqlStatement(SQLSERVERCREATESTRUCTURE, config); _sqlStatementToInitializeEntity = PrepareSqlStatement(SQLSERVERINITIALIZEENTITY, config); _sqlStatementToCheckSelectPermission = PrepareSqlStatement("SELECT * FROM [dbo].[{0}]", config); }
// internal Func<string, DbProviderFactory> DbFactoryCreator { private get; set; } // for testability public AgnosticHiLoRepository(IDatabase db, string entityName, IHiLoConfiguration config) { database = db; _entityName = entityName; _config = config; //DbFactoryCreator = (providerName) => DbProviderFactories.GetFactory(providerName); }
private void InitializeSqlStatements(IHiLoConfiguration config) { _sqlStatementToSelectAndUpdateNextHiValue = PrepareSqlStatement("SELECT {1} FROM {0} WHERE {2} = {3};UPDATE {0} SET {1} = {1} + 1 WHERE {2} = {3};", config); _sqlStatementToCreateRepository = PrepareSqlStatement( @"IF NOT EXISTS(SELECT 1 FROM SYS.OBJECTS WHERE NAME = '{0}' AND TYPE = 'U') BEGIN CREATE TABLE [dbo].[{0}]( [{2}] [nvarchar](100) NOT NULL, [{1}] [bigint] NOT NULL, CONSTRAINT [PK_{0}] PRIMARY KEY CLUSTERED ( [{2}] ASC ) ); SELECT 1; END ELSE SELECT 0;", config); _sqlStatementToInitializeEntity = PrepareSqlStatement( @"SET NOCOUNT ON; IF NOT EXISTS(SELECT 1 FROM {0} WHERE {2} = {3}) BEGIN INSERT INTO {0} VALUES ({3}, 1); END", config); }
public SqlServerSequenceHiLoRepository(IHiLoConfiguration config) : base(config, Microsoft.Data.SqlClient.SqlClientFactory.Instance) { if (!string.IsNullOrEmpty(config.ObjectPrefix)) { _objectPrefix = config.ObjectPrefix; } }
private static IHiLoRepository GetSqlServerRepository(IHiLoConfiguration config) { if (config.StorageType == Common.Config.HiLoStorageType.Sequence) { return(new SqlServerSequenceHiLoRepository(config)); } return(new SqlServerHiLoRepository(config)); }
private void InitializeSqlStatements(IHiLoConfiguration config) { _sqlStatementToGetLatestNextHiValue = PrepareSqlStatement("SELECT {1} FROM {0} WHERE {2} = {3}", config); _sqlStatementToUpdateNextHiValue = PrepareSqlStatement("UPDATE {0} SET {1} = {1} + 1 WHERE {2} = {3}", config); _sqlStatementToCreateRepository = PrepareSqlStatement("CREATE TABLE IF NOT EXISTS {0} ( {2} VARCHAR(100) NOT NULL PRIMARY KEY, {1} BIGINT NOT NULL );", config); _sqlStatementToInitializeEntity = PrepareSqlStatement("INSERT INTO {0}({2}, {1}) SELECT {3}, 1 FROM {0} WHERE NOT EXISTS(SELECT 1 FROM {0} WHERE {2} = {3});", config); }
// private Regex _entityNameValidator = new Regex(@"^[a-zA-Z]+[a-zA-Z0-9_]*$"); public SqlServerSequenceHiLoRepository(IDatabase db, string entityName, IHiLoConfiguration config) : base(db, entityName, config) { if (!string.IsNullOrEmpty(config.ObjectPrefix)) { _objectPrefix = config.ObjectPrefix; } }
public IHiLoRepository GetRepository(string entityName, IHiLoConfiguration config) { IHiLoRepository repository = null; repository = _factoryFunction(entityName, config); repository.PrepareRepository(); return(repository); }
private void InitializeSqlStatements(IHiLoConfiguration config) { _sqlStatementToUpdateNextHiValue = PrepareSqlStatement("UPDATE {0} SET {1} = {1} + 1 WHERE {2} = {3}", config); _sqlStatementToGetLatestNextHiValue = PrepareSqlStatement("SELECT {1} FROM {0} WHERE {2} = {3}", config); _sqlStatementToCheckIfNHilosTableExists = PrepareSqlStatement("SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{0}' AND TABLE_TYPE = 'TABLE'", config); _sqlStatementToCreateNHiloTable = PrepareSqlStatement("CREATE TABLE {0} ({2} NVARCHAR(100) PRIMARY KEY NOT NULL, {1} BIGINT NOT NULL)", config); _sqlStatementToCheckIfEntityExists = PrepareSqlStatement("SELECT 1 FROM {0} WHERE {2} = {3}", config); _sqlStatementToInsertNewEntityToNHilosTable = PrepareSqlStatement("INSERT INTO {0} ({2}, {1}) VALUES ({3}, 1)", config); }
//private Regex _entityNameValidator = new Regex(@"^[a-zA-Z]+[a-zA-Z0-9]*$"); public HiLoGeneratorFactory(IDatabase database, Action <IHiLoConfiguration> config) { _config = new HiLoConfiguration(); if (config != null) { config(_config); } _repositoryFactory = new HiLoRepositoryFactory(database); }
private HiLoGeneratorFactory(IHiLoRepositoryFactory repositoryFactory, IConfiguration configuration) { if (configuration == null) { var builder = new ConfigurationBuilder() .Add(new NETConfigConfigurationProvider()) .AddEnvironmentVariables(); configuration = builder.Build(); } _config = new HiLoConfigurationBuilder(new ConfigurationManagerWrapper(configuration)).Build(); _repositoryFactory = repositoryFactory ?? new HiLoRepositoryFactory(); }
public IHiLoRepository GetRepository(string entityName, IHiLoConfiguration config) { string provider = config.ProviderName; if (string.IsNullOrWhiteSpace(provider)) { throw new NHiLoException(ErrorCodes.NoProviderName); } if (!_factoryFunctions.ContainsKey(provider)) { throw new NHiLoException(ErrorCodes.ProviderNotImplemented).WithInfo("Provider Name", provider); } var repository = new ExceptionWrapperRepository(() => _factoryFunctions[provider](config)); repository.PrepareRepository(entityName); return(repository); }
private void InitializeSqlStatements(IHiLoConfiguration config) { _sqlStatementToGetLatestNextHiValue = PrepareSqlStatement("SELECT {1} FROM {0} WHERE {2} = {3}", config); _sqlStatementToUpdateNextHiValue = PrepareSqlStatement("UPDATE {0} SET {1} = {1} + 1 WHERE {2} = {3}", config); _sqlStatementToCreateRepository = PrepareSqlStatement("DECLARE vCOUNT NUMBER; " + "BEGIN " + "SELECT COUNT(*) INTO vCOUNT FROM USER_TABLES WHERE TABLE_NAME = '{0}'; " + "IF vCOUNT = 0 THEN " + " EXECUTE IMMEDIATE 'CREATE TABLE {0} ({2} VARCHAR2(100) NOT NULL, {1} NUMBER(19) NOT NULL, CONSTRAINT PK_{0} PRIMARY KEY ({2}))'; " + "END IF; " + "END;", config); _sqlStatementToInitializeEntity = PrepareSqlStatement("DECLARE vCOUNT NUMBER; " + "BEGIN " + "SELECT COUNT(*) INTO vCOUNT FROM {0} WHERE {2} = {3}; " + "IF vCOUNT = 0 THEN " + " INSERT INTO {0} ({2}, {1}) VALUES ({3}, 1); " + "END IF; " + "END;", config); }
public AgnosticHiLoRepository(IHiLoConfiguration config, DbProviderFactory provider) { _config = config; DbFactoryCreator = (providerName) => provider; }
private ConnectionStringSettings FindConnectionStringToBeUsedByHiLoConfiguration(IHiLoConfiguration hiloConfig) { ConnectionStringSettings connectionStringSettings; if (!string.IsNullOrEmpty(hiloConfig.ConnectionStringId)) { connectionStringSettings = _connectionStringsConfig.ConnectionStrings[hiloConfig.ConnectionStringId]; if (connectionStringSettings == null) { throw new NHiLoException(ErrorCodes.NoSpecifiedConnectionStringWasFound).WithInfo("ConnectionStringId", hiloConfig.ConnectionStringId); } } else { connectionStringSettings = _connectionStringsConfig.ConnectionStrings[_connectionStringsConfig.ConnectionStrings.Count - 1]; // or get the last connection string } CheckConsistenceOfConnectionStringsSettings(connectionStringSettings); return(connectionStringSettings); }
private IHiLoConfiguration PrepareHiLoConfigurationWithConnectionString(IHiLoConfiguration hiloConfig, ConnectionStringSettings connectionStringSettings) { hiloConfig.ConnectionString = connectionStringSettings.ConnectionString; hiloConfig.ProviderName = connectionStringSettings.ProviderName; return(hiloConfig); }
public MySqlHiLoRepository(IHiLoConfiguration config) : base(config, MySql.Data.MySqlClient.MySqlClientFactory.Instance) { InitializeSqlStatements(config); }
/// <summary> /// Prepare the SQL statement provided these information: /// {0} - table name /// {1} - nexthi column name /// {2} - entity column name /// {3} - parameter name /// </summary> /// <param name="rawStatement">The SQL statement which will be filled with custom information.</param> /// <param name="config">Object that holds the database information.</param> /// <returns></returns> protected string PrepareSqlStatement(string rawStatement, IHiLoConfiguration config) { return(string.Format(rawStatement, config.TableName, config.NextHiColumnName, config.EntityColumnName, EntityParameterName)); }
public PostgreSQLHiLoRepository(IDatabase db, string entityName, IHiLoConfiguration config) : base(db, entityName, config) { InitializeSqlStatements(config); }
public OracleHiLoRepository(IHiLoConfiguration config) : base(config, Oracle.ManagedDataAccess.Client.OracleClientFactory.Instance) { InitializeSqlStatements(config); }
public SqlServerHiLoRepository(IHiLoConfiguration config) : base(config, Microsoft.Data.SqlClient.SqlClientFactory.Instance) { InitializeSqlStatements(config); }
public TestableHiLoRepository(IHiLoConfiguration config, DbProviderFactory provider) : base(config, provider) { }
internal HiLoGeneratorFactory(IHiLoRepositoryFactory repositoryFactory, IDatabase database, IHiLoConfiguration config) { _config = config ?? new HiLoConfiguration(); _repositoryFactory = repositoryFactory ?? new HiLoRepositoryFactory(database); }