小编use*_*736的帖子

实体框架与TPH的多级继承

我正在使用遗留系统,为一定数量的项目实现TPH.所以目前的结构看起来像这样

 Abstract Class 1     Abstract Class 2     Abstract Class 3
         |                    |                    |
     ---------            ---------            ---------
    |    |    |          |    |    |          |    |    |
    T1   T2   T3        T4    T5   T6         T7   T8   T9
Run Code Online (Sandbox Code Playgroud)

因此Type(T*)是跨所有表的鉴别器,但由于某些类型共享公共列,因此存在大量不同的表.问题是所有这些项目实际上都有一个共同点,但没有办法将所有这些项目收集到一个集合中.实际上,层次结构实际上看起来应该更像这样.

          --------------- Base Abstract 1 ---------- 
         |                    |                    |
 Abstract Class 1     Abstract Class 2     Abstract Class 3
         |                    |                    |
     ---------            ---------            ---------
    |    |    |          |    |    |          |    |    |
    T1   T2   T3        T4    T5   T6         T7   T8   T9
Run Code Online (Sandbox Code Playgroud)

基本上我们所拥有的是TPT,其中每种类型的每个表都是TPH.对于一个真实世界的例子,这是我们需要的.

          ---------------  Vehicle   --------------- …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework table-per-type table-per-hierarchy

10
推荐指数
1
解决办法
856
查看次数

Java-用于预订的分布式JPA锁

我正在使用允许预定计划的旧系统。该应用程序是无状态REST,并且设计为可水平扩展。但是,数据库在所有实例之间共享。在进行有关设计和规模的讲座之前,这不是我的问题-必须充分利用糟糕的情况(或代码库)。最近,我们看到了一个重复预订的问题。我相信这是因为请求响应线程的性质。当前的过程是,接收请求,检查数据库是否有冲突的时间保留,如果没有,则插入。根据读取和插入之间的时间,有可能两者都插入。场景看起来像这样:

|------|-------|-------|
R1     C1      I1     RSP

-|--------|-------|---------|
R2       C2     I2   RSP
Run Code Online (Sandbox Code Playgroud)

其中R =请求,C = DB检查,I =插入。

因此,我相信我可以使用@Synchronized批注来强制所有线程进行排序。问题在于,有多个实例正在运行,因此无法正常运行整个实例。悲观或乐观的读写似乎并不适用,因为除非我完全误解,否则我们将尝试进行读写组合。有什么想法可以解决这个问题吗?宁愿通过表锁或类似方法在Java中处理它,而不是添加其他服务(kafka,redis等)。

编辑:数据库看起来像这样,在开发中使用h2,在生产中使用mysql。

 id |  start_time  | locationid | postingid | userid | durration
 --------------------------------------------------------------- 
Run Code Online (Sandbox Code Playgroud)

java concurrency spring jpa

10
推荐指数
1
解决办法
299
查看次数

使用配置类时,使用@PreAuthorize或@Secured与Jersey

我遇到类似于PreAuthorize注释的问题不适用于球衣.我为Spring Security创建了一个配置类,并且身份验证有效,但授权却没有.

这是我的代码

SpringSecurityConfig.java

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
@Order(1)
@ComponentScan({"com.foo.rest.resources.Template"})
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {

    private final UserService userService;
    private final TokenAuthenticationService tokenAuthenticationService;

    public SpringSecurityConfig() {
        super(true);
        this.userService = new UserService();
        tokenAuthenticationService = new TokenAuthenticationService("tooManySecrets", userService);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
            http
                .exceptionHandling().and()
                .anonymous().and()
                .servletApi().and()
                .headers().cacheControl().and()
                .authorizeRequests()
                // Allow anonymous logins
                .antMatchers("/auth/**").permitAll()
                // All other request need to be authenticated
                .anyRequest().authenticated().and()

                // Custom Token based authentication based …
Run Code Online (Sandbox Code Playgroud)

java rest spring jersey spring-security

5
推荐指数
1
解决办法
817
查看次数

HttpClient.getAsync()内存不足异常

我有一个从Web服务获取大量JSON的函数.这个数据有时可能很大,千兆字节.我的电话看起来像这样.

        try
        {
            using (var httpClient = NewHttpClient())
            {
                var response = httpClient.GetAsync(endpoint).Result;
                return response;
            }
        }
        catch(Exception ex)
        {
            //Do Stuff
        }
Run Code Online (Sandbox Code Playgroud)

当数据很大时,会抛出内存不足异常.我相信这是因为响应消息实际上比HttpResponseMessage允许它更大.有没有办法在一段时间内只得到一些消息?我确信它以前已经完成,但我无法找到谷歌和/或斜杠的任何东西.提前感谢您的建议.

c# json out-of-memory dotnet-httpclient

2
推荐指数
1
解决办法
2779
查看次数