예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public string QueryToString(DatabaseTypeEnum dataType, Func <string, string> findField)
        {
            string strWhere    = GetConditionsString(this, dataType, findField);
            string strNewWhere = "";

            //过滤前后多余的条件符
            if (strWhere.Trim().StartsWith("AND") || strWhere.Trim().StartsWith("OR"))
            {
                if (strWhere.Trim().StartsWith("AND"))
                {
                    strNewWhere = strWhere.Remove(0, " AND".Length);
                }
                if (strWhere.Trim().StartsWith("OR"))
                {
                    strNewWhere = strWhere.Remove(0, " OR".Length);
                }
                strWhere = strNewWhere;
            }
            if (strWhere.Trim().EndsWith("AND") || strWhere.Trim().EndsWith("OR"))
            {
                if (strWhere.Trim().EndsWith("AND"))
                {
                    strNewWhere = strWhere.Remove(strWhere.Length - "AND ".Length);
                }
                if (strWhere.Trim().EndsWith("OR"))
                {
                    strNewWhere = strWhere.Remove(strWhere.Length - "OR ".Length);
                }
                strWhere = strNewWhere;
            }
            return(strWhere);
        }
예제 #2
0
 public static Type GetBoxedType(this DatabaseTypeEnum value)
 {
     switch (value)
     {
         case DatabaseTypeEnum.BOOLEAN:
             return typeof(bool?);
         case DatabaseTypeEnum.BYTE:
             return typeof(byte?);
         case DatabaseTypeEnum.BYTE_ARRAY:
             return typeof(byte[]);
         case DatabaseTypeEnum.DECIMAL:
             return typeof(decimal?);
         case DatabaseTypeEnum.DOUBLE:
             return typeof(double?);
         case DatabaseTypeEnum.FLOAT:
             return typeof(float?);
         case DatabaseTypeEnum.INT32:
             return typeof(int?);
         case DatabaseTypeEnum.INT64:
             return typeof(long?);
         case DatabaseTypeEnum.INT16:
             return typeof(short?);
         case DatabaseTypeEnum.STRING:
             return typeof(string);
         case DatabaseTypeEnum.TIMESTAMP:
             return typeof(DateTime?);
         default:
             throw new ArgumentOutOfRangeException(nameof(value), value, null);
     }
 }
예제 #3
0
        public static void InitializeDatabaseType(DatabaseTypeEnum databaseType)
        {
            RepositoryRegister register = RepositoryRegister.getInstance();

            if (databaseType == DatabaseTypeEnum.ORACLE_DATABASE)
            {
                DatabaseService.Init(new OracleConnection());
                register.Register(typeof(PersonGateway), new OraclePersonGateway(DatabaseService.GetInstance()));
                register.Register(typeof(AddressGateway), new OracleAddressGateway(DatabaseService.GetInstance()));
                register.Register(typeof(CageGateway), new OracleCageGateway(DatabaseService.GetInstance()));
                register.Register(typeof(AnimalGateway), new OracleAnimalGateway(DatabaseService.GetInstance()));
                register.Register(typeof(AnimalGroupGateway), new OracleAnimalGroupGateway(DatabaseService.GetInstance()));
                register.Register(typeof(CompanyGateway), new OracleCompanyGateway(DatabaseService.GetInstance()));
                register.Register(typeof(EventGateway), new OracleEventGateway(DatabaseService.GetInstance()));
                register.Register(typeof(FoodOrderPendingGateway), new OracleFoodOrderPendingGateway(DatabaseService.GetInstance()));
                register.Register(typeof(FoodGateway), new OracleFoodGateway(DatabaseService.GetInstance()));
                register.Register(typeof(RoleGateway), new OracleRoleGateway(DatabaseService.GetInstance()));
            }
            else if (databaseType == DatabaseTypeEnum.SQL_SERVER_DATABASE)
            {
                DatabaseService.Init(new SqlConnection());
                register.Register(typeof(PersonGateway), new SqlServerPersonGateway(DatabaseService.GetInstance()));
                register.Register(typeof(AddressGateway), new SqlServerAddressGateway(DatabaseService.GetInstance()));
                register.Register(typeof(CageGateway), new SqlServerCageGateway(DatabaseService.GetInstance()));
                register.Register(typeof(AnimalGateway), new SqlServerAnimalGateway(DatabaseService.GetInstance()));
                register.Register(typeof(AnimalGroupGateway), new SqlServerAnimalGroupGateway(DatabaseService.GetInstance()));
                register.Register(typeof(CompanyGateway), new SqlServerCompanyGateway(DatabaseService.GetInstance()));
                register.Register(typeof(EventGateway), new SqlServerEventGateway(DatabaseService.GetInstance()));
                register.Register(typeof(FoodOrderPendingGateway), new SqlServerFoodOrderPendingGateway(DatabaseService.GetInstance()));
                register.Register(typeof(FoodGateway), new SqlServerFoodGateway(DatabaseService.GetInstance()));
                register.Register(typeof(RoleGateway), new SqlServerRoleGateway(DatabaseService.GetInstance()));
            }
            register.Register(typeof(AddressXmlGateway), new AddressXmlGatewayImpl());
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public ParameterCollection GetParams(DatabaseTypeEnum dataType)
        {
            ParameterCollection     list           = new ParameterCollection();
            List <ConditionsClause> listConditions = GetConditions(this);

            foreach (ConditionsClause p in listConditions)
            {
                if (p.Condition is Condition)
                {
                    Condition     c  = (Condition)p.Condition;
                    OperationType ot = c.OpType;
                    if (ot != OperationType.IsNull && ot != OperationType.In && ot != OperationType.NotIn && ot != OperationType.IsNotNull && ot != OperationType.NullOrEmpty && ot != OperationType.NotNullOrEmpty) //不需要参数的过滤掉
                    {
                        list.AddRange(c.OutParam(dataType));
                    }
                }
                else if (p.Condition is TermCondition)
                {
                    TermCondition t = (TermCondition)p.Condition;
                    if (t.DataParam != null)
                    {
                        list.AddRange(t.DataParam);
                    }
                }
            }

            return(list);
        }
예제 #5
0
 public static string MusicPlaylistDeleteSql(DatabaseTypeEnum type)
 {
     if (type == DatabaseTypeEnum.PostgreSql)
     {
         return("DELETE FROM \"MusicPlaylists\";");
     }
     return("DELETE FROM MusicPlaylists;");
 }
예제 #6
0
 public static string CurrencyDeleteSql(DatabaseTypeEnum type)
 {
     if (type == DatabaseTypeEnum.PostgreSql)
     {
         return("UPDATE \"DiscordUser\" SET \"CurrencyAmount\"=0; DELETE FROM \"CurrencyTransactions\";");
     }
     return("UPDATE DiscordUser SET CurrencyAmount=0; DELETE FROM CurrencyTransactions;");
 }
예제 #7
0
        public static DataCommand GetDataCommand(string name, string dataBaseName, DatabaseTypeEnum dataBasetype, bool supportTran)
        {
            DataCommand cmd = dataCommands[name].Clone() as DataCommand;

            cmd.ConnectionStrings  = ConfigManager.GetConfig <ConnectionStringConfigs>().DatabaseList[dataBaseName].ConnectionStringList[dataBasetype.ToString()].ConnectionStrings;
            cmd.SupportTransaction = supportTran;
            return(cmd);
        }
예제 #8
0
        public static string WaifusDeleteSql(DatabaseTypeEnum type)
        {
            if (type == DatabaseTypeEnum.PostgreSql)
            {
                return("DELETE FROM \"WaifuUpdates\";DELETE FROM \"WaifuItem\";DELETE FROM \"WaifuInfo\";");
            }

            return("DELETE FROM WaifuUpdates;DELETE FROM WaifuItem;DELETE FROM WaifuInfo;");;
        }
예제 #9
0
     public bool CreateConnection(DatabaseTypeEnum type)
     {
         T conn;
 
         if(type==DatabaseTye.Oracle)
         {
             //....
         }    
     }
예제 #10
0
        /// <summary>
        /// Adds the SQL types binding.
        /// </summary>
        /// <param name="sqlType">Type of the SQL.</param>
        /// <param name="desiredType">The desired type.</param>
        public void AddSqlTypeBinding(Type sqlType, Type desiredType)
        {
            DatabaseTypeEnum typeEnum = DatabaseTypeEnum.GetEnum(desiredType.FullName);

            if (typeEnum == null)
            {
                String supported = DatabaseTypeEnum.Values.Render();
                throw new ConfigurationException("Unsupported type '" + desiredType.FullName + "' when expecting any of: " + supported);
            }
            this.dataTypeMapping[sqlType] = desiredType;
        }
예제 #11
0
        public DatabaseDumper(Workspace workspace, DatabaseTypeEnum databaseTypeEnum, String path)
        {
            Workspace        = workspace;
            DatabaseTypeEnum = databaseTypeEnum;
            Path             = path;
            var constructor = SessionFactoryFactory
                              .GetDialectClass(DatabaseTypeEnum).GetConstructor(new Type[0]);

            Debug.Assert(constructor != null);
            Dialect = (Dialect)constructor.Invoke(new object[0]);
        }
예제 #12
0
 private string[] GetConnectionStringByName(string connectionStringName, DatabaseTypeEnum type)
 {
     try
     {
         return(ConfigManager.GetConfig <ConnectionStringConfigs>().DatabaseList[connectionStringName].ConnectionStringList[type.ToString()].ConnectionStrings);
     }
     catch (Exception ex)
     {
         throw new Exception("Can't find connectionString key: [{0}] in connectionString config.", ex);
     }
 }
예제 #13
0
        internal static BaseDataAccess CreateDataAccess(DatabaseTypeEnum databaseType)
        {
            switch (databaseType)
            {
            case DatabaseTypeEnum.SqlServer:
                return(new SqlDataAccess());

            case DatabaseTypeEnum.Oracle:
                return(new OracleDataAccess());
            }
            return(new SqlDataAccess());
        }
예제 #14
0
        public static void initializeDataAndServices()
        {
            DatabaseTypeEnum databaseType = DatabaseTypeEnum.SQL_SERVER_DATABASE;

            DatabaseTypeInitializer.InitializeDatabaseType(databaseType);
            ServiceRegister serviceRegister = ServiceRegister.getInstance();

            serviceRegister.Register(typeof(PersonService), new PersonServiceImpl());
            serviceRegister.Register(typeof(AnimalGroupService), new AnimalGroupServiceImpl());
            serviceRegister.Register(typeof(AnimalService), new AnimalServiceImpl());
            serviceRegister.Register(typeof(CageService), new CageServiceImpl());
            serviceRegister.Register(typeof(FoodService), new FoodServiceImpl());
            serviceRegister.Register(typeof(EventService), new EventServiceImpl());
            serviceRegister.Register(typeof(AddressService), new AddressServiceImpl());
        }
예제 #15
0
        public static string WaifuDeleteSql(DatabaseTypeEnum type)
        {
            if (type == DatabaseTypeEnum.PostgreSql)
            {
                return(@"DELETE FROM ""WaifuUpdates"" WHERE ""UserId""=(SELECT ""Id"" FROM ""DiscordUser"" WHERE ""UserId""={0});
                    DELETE FROM ""WaifuItem"" WHERE ""WaifuInfoId""=(SELECT ""Id"" FROM ""WaifuInfo"" WHERE ""WaifuId""=(SELECT ""Id"" FROM ""DiscordUser"" WHERE ""UserId""={0}));
                    UPDATE ""WaifuInfo"" SET ""ClaimerId""=NULL WHERE ""ClaimerId""=(SELECT ""Id"" FROM ""DiscordUser"" WHERE ""UserId""={0});
                    DELETE FROM ""WaifuInfo"" WHERE ""WaifuId""=(SELECT ""Id"" FROM ""DiscordUser"" WHERE ""UserId""={0});");
            }

            return(@"DELETE FROM WaifuUpdates WHERE UserId=(SELECT Id FROM DiscordUser WHERE UserId={0});
                    DELETE FROM WaifuItem WHERE WaifuInfoId=(SELECT Id FROM WaifuInfo WHERE WaifuId=(SELECT Id FROM DiscordUser WHERE UserId={0}));
                    UPDATE WaifuInfo SET ClaimerId=NULL WHERE ClaimerId=(SELECT Id FROM DiscordUser WHERE UserId={0});
                    DELETE FROM WaifuInfo WHERE WaifuId=(SELECT Id FROM DiscordUser WHERE UserId={0});");
        }
예제 #16
0
        public static Type GetDriverClass(DatabaseTypeEnum databaseTypeEnum)
        {
            switch (databaseTypeEnum)
            {
            case DatabaseTypeEnum.sqlite:
                return(typeof(SQLite20Driver));

            case DatabaseTypeEnum.mysql:
                return(typeof(MySqlDataDriver));

            case DatabaseTypeEnum.postgresql:
                return(typeof(NpgsqlDriver));
            }
            throw new ArgumentException();
        }
예제 #17
0
        public static Type GetDialectClass(DatabaseTypeEnum databaseTypeEnum)
        {
            switch (databaseTypeEnum)
            {
            case DatabaseTypeEnum.sqlite:
                return(typeof(SQLiteDialect));

            case DatabaseTypeEnum.mysql:
                return(typeof(MySQLDialect));

            case DatabaseTypeEnum.postgresql:
                return(typeof(PostgreSQL82Dialect));
            }
            throw new ArgumentException();
        }
예제 #18
0
        private IDataAccess CreateClass(DatabaseTypeEnum databaseType)
        {
            IDataAccess result;

            switch (databaseType)
            {
            case DatabaseTypeEnum.SQL:
            default:
                result = new MsDataAccess();

                break;
            }

            return(result);
        }
        internal static string UpdateStatements(UpdateStatementModel updateStatements, out List <string> columnValues)
        {
            DatabaseTypeEnum buildType = Connections.Instance.DatabaseModel.DatabaseType;

            IDataToSQL sql = null;

            switch (buildType)
            {
            case DatabaseTypeEnum.SQL:
            default:

                sql = new MsSQL();

                return(sql.UpdateStatements(updateStatements, out columnValues));
            }
        }
예제 #20
0
        public static Configuration GetConfiguration(DatabaseTypeEnum databaseTypeEnum, SessionFactoryFlags flags)
        {
            Assembly assembly = typeof(SessionFactoryFactory).Assembly;
            var configuration = new Configuration()
                .SetProperty("dialect", GetDialectClass(databaseTypeEnum).AssemblyQualifiedName)
                .SetProperty("connection.driver_class", GetDriverClass(databaseTypeEnum).AssemblyQualifiedName)
                .SetProperty("connection.provider",
                             typeof (NHibernate.Connection.DriverConnectionProvider).AssemblyQualifiedName)
                .SetProperty("command_timeout", "1800");
            if (databaseTypeEnum == DatabaseTypeEnum.mysql)
            {
                configuration.SetProperty("sessionVariables", "storage_engine=InnoDB");
            }
            configuration.AddInputStream(assembly.GetManifestResourceStream("pwiz.Topograph.Data.mapping.xml"));

            return configuration;
        }
예제 #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public ParameterCollection OutParam(DatabaseTypeEnum dataType)
        {
            ParameterCollection pc = new ParameterCollection();

            if (dataType == DatabaseTypeEnum.SqlServer)
            {
                pc.Add(GetParamString(), Value);
            }
            else if (dataType == DatabaseTypeEnum.MySql)
            {
                pc.Add(GetParamString(), Value);
            }
            else
            {
                throw new Exception("无指定数据处理类");
            }
            return(pc);
        }
예제 #22
0
        public static Configuration GetConfiguration(DatabaseTypeEnum databaseTypeEnum, SessionFactoryFlags flags)
        {
            Assembly assembly      = typeof(SessionFactoryFactory).Assembly;
            var      configuration = new Configuration()
                                     .SetProperty("dialect", GetDialectClass(databaseTypeEnum).AssemblyQualifiedName)
                                     .SetProperty("connection.driver_class", GetDriverClass(databaseTypeEnum).AssemblyQualifiedName)
                                     .SetProperty("connection.provider",
                                                  typeof(NHibernate.Connection.DriverConnectionProvider).AssemblyQualifiedName)
                                     .SetProperty("command_timeout", "1800");

            if (databaseTypeEnum == DatabaseTypeEnum.mysql)
            {
                configuration.SetProperty("sessionVariables", "storage_engine=InnoDB");
            }
            configuration.AddInputStream(assembly.GetManifestResourceStream("pwiz.Topograph.Data.mapping.xml"));

            return(configuration);
        }
        internal static string GetCanvasSQL(
            ReportColumnModel[] columns,
            List <WhereParameterModel> whereParameterModel,
            List <ReportXMLPrintParameterModel> reportFilters,
            Dictionary <string, ReportSQLReplaceHeaderModel> replacementColumns,
            string orderByString)
        {
            DatabaseTypeEnum buildType = Connections.Instance.DatabaseModel.DatabaseType;

            IDataToSQL sql = null;

            switch (buildType)
            {
            case DatabaseTypeEnum.SQL:
            default:

                sql = new MsSQL();

                return(sql.BuildSelectQuery(columns, whereParameterModel, reportFilters, replacementColumns, orderByString));
            }
        }
예제 #24
0
        public DataContext(string connectionString, string providerInvariantName, bool openConnection = false)
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[connectionString];

            if (settings != null)
            {
                if (!string.IsNullOrWhiteSpace(settings.ConnectionString))
                {
                    this._connectionString = settings.ConnectionString;
                }
                else
                {
                    this._connectionString = connectionString;
                }
                this._providerInvariantName = settings.ProviderName;
            }
            else
            {
                this._connectionString      = connectionString;
                this._providerInvariantName = providerInvariantName;
            }
            this._databaseType                = DatabaseFactory.GetDatabaseType(this._providerInvariantName);
            this._dataAccess                  = DatabaseFactory.CreateDataAccess(this._databaseType);
            this._providerFactory             = DbProviderFactories.GetFactory(this._providerInvariantName);
            this._connection                  = this._providerFactory.CreateConnection();
            this._connection.ConnectionString = this._connectionString;
            if (this._databaseType == DatabaseTypeEnum.Oracle)
            {
                this._provider = new ODPQueryProvider(this, _mapping, QueryPolicy.Default);
            }
            else
            {
                this._provider = new SqlQueryProvider(this, _mapping, QueryPolicy.Default);
            }
            if (openConnection)
            {
                this.Open();
            }
        }
예제 #25
0
        public static string XpDeleteSql(DatabaseTypeEnum type)
        {
            if (type == DatabaseTypeEnum.PostgreSql)
            {
                return(@"DELETE FROM ""UserXpStats"";
                    UPDATE ""DiscordUser""
                    SET ""ClubId""=NULL,
                        ""IsClubAdmin""=false,
                        ""TotalXp""=0;
                    DELETE FROM ""ClubApplicants"";
                    DELETE FROM ""ClubBans"";
                    DELETE FROM ""Clubs"";");
            }

            return(@"DELETE FROM UserXpStats;
                    UPDATE DiscordUser
                    SET ClubId=NULL,
                        IsClubAdmin=0,
                        TotalXp=0;
                    DELETE FROM ClubApplicants;
                    DELETE FROM ClubBans;
                    DELETE FROM Clubs;");
        }
 public AppErrLogController(DatabaseTypeEnum dbt = DatabaseTypeEnum.SqlServerTestDB) : base(dbt)
 {
 }
예제 #27
0
 public BoxModelResultController(DatabaseTypeEnum dbt = DatabaseTypeEnum.SqlServerTestDB) : base(dbt)
 {
 }
예제 #28
0
 public MikeSourceController(DatabaseTypeEnum dbt = DatabaseTypeEnum.SqlServerTestDB) : base(dbt)
 {
 }
예제 #29
0
 public static Type GetDialectClass(DatabaseTypeEnum databaseTypeEnum)
 {
     switch (databaseTypeEnum)
     {
         case DatabaseTypeEnum.sqlite:
             return typeof(SQLiteDialect);
         case DatabaseTypeEnum.mysql:
             return typeof(MySQLDialect);
         case DatabaseTypeEnum.postgresql:
             return typeof(PostgreSQL82Dialect);
     }
     throw new ArgumentException();
 }
 public ContactShortcutController(DatabaseTypeEnum dbt = DatabaseTypeEnum.SqlServerTestDB) : base(dbt)
 {
 }
예제 #31
0
 public static Type GetDriverClass(DatabaseTypeEnum databaseTypeEnum)
 {
     switch (databaseTypeEnum)
     {
         case DatabaseTypeEnum.sqlite:
             return typeof(SQLite20Driver);
         case DatabaseTypeEnum.mysql:
             return typeof(MySqlDataDriver);
         case DatabaseTypeEnum.postgresql:
             return typeof(NpgsqlDriver);
     }
     throw new ArgumentException();
 }
예제 #32
0
 public static DataCommand GetDataCommand(string name, string dataBaseName, DatabaseTypeEnum dataBasetype, bool supportTran)
 {
     DataCommand cmd = dataCommands[name].Clone() as DataCommand;
     cmd.ConnectionStrings = ConfigManager.GetConfig<ConnectionStringConfigs>().DatabaseList[dataBaseName].ConnectionStringList[dataBasetype.ToString()].ConnectionStrings;
     cmd.SupportTransaction = supportTran;
     return cmd;
 }
예제 #33
0
 public TideSiteController(DatabaseTypeEnum dbt = DatabaseTypeEnum.SqlServerTestDB) : base(dbt)
 {
 }
        /// <summary>
        /// 
        /// </summary>
		public DataOperationCommand()
		{
			commandType = CommandType.Text;
			timeOut = 300;
            databaseType = DatabaseTypeEnum.Query;
		}
예제 #35
0
 public TVItemController(DatabaseTypeEnum dbt = DatabaseTypeEnum.SqlServerTestDB) : base(dbt)
 {
 }
예제 #36
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="dataBaseName">DataBase.config里面的Customer</param>
 /// <returns></returns>
 public static DataCommand GetDataCommand(string name, string dataBaseName, DatabaseTypeEnum dataBasetype)
 {
     return GetDataCommand(name, dataBaseName, dataBasetype, false);
 }