小编Cas*_*sey的帖子

如何使用现代Spring Boot + Data JPA和Hibernate设置生成ddl创建脚本?

目前,我正在使用@SpringBootApplication具有以下属性的默认注释application.properties:

spring.datasource.url=jdbc:mysql://localhost/dbname
spring.datasource.username=X
spring.datasource.password=X
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.naming_strategy=my.package.CustomNamingStrategy
Run Code Online (Sandbox Code Playgroud)

从JPA 2.1开始,我应该可以使用这些javax.persistence.schema-generation.*属性,但是在我的application.properties中设置它们似乎没有任何效果.

我见过的例子是这样那丝了一大堆额外的豆子,但他们没有使用MySQL.无论如何,这样做需要我配置春天为我提供的许多选项.

我的目标是:

  • 在MYSQL方言中生成模式创建sql脚本
  • 没有数据库连接是必需的
  • 输出构建目录中的脚本
  • 同时生成hibernate envers表也是一个巨大的优势.

我不想:

  • 在实时数据库上创建/删除模式

Lib版本:

   hibernate          : 4.3.11.FINAL
   spring framework   : 4.2.5.RELEASE
   spring-boot        : 1.3.3.RELEASE
   spring-data-jpa    : 1.10.1.RELEASE   // for  querydsl 4 support
   spring-data-commons: 1.12.1.RELEASE   // for  querydsl 4 support
Run Code Online (Sandbox Code Playgroud)

(使用gradle,而不是maven)

hibernate spring-data spring-data-jpa spring-boot

44
推荐指数
3
解决办法
4万
查看次数

适用于Linux桌面的代码片段管理器?

本着/sf/ask/234499331/的精神

Linux有哪些优秀的代码片段管理器?

我的快速搜索没有发现太多.Eclipse,emacs,vim,Kate和KDevelop都提供了自己的集成代码片段管理器,但我正在寻找一些更通用的CodeCollectorSnippets,理想情况下可以选择CLI接口.

即使是纯粹的CLI工具也是可以接受的(甚至可能更好).

linux code-snippets

8
推荐指数
1
解决办法
4277
查看次数

什么是"s!" Perl的运营商呢?

我有一个脚本的Perl片段,我正在翻译成Python.我不知道"s!" 操作员正在做; 某种正则表达式替换.不幸的是,搜索谷歌或Stackoverflow这样的运营商并没有产生很多有用的结果.

 $var =~ s!<foo>.+?</foo>!!;
 $var =~ s!;!/!g;
Run Code Online (Sandbox Code Playgroud)

每条线路做什么?我想知道以防我再次遇到这个操作员.

而且,Python中的等效语句是什么?

python regex perl

4
推荐指数
3
解决办法
423
查看次数

如何将RTL文本(阿拉伯语)绘制到位图并正确排序?

我正在尝试将阿拉伯文字绘制到位图上以供显示:

Bitmap img = Bitmap.createBitmap( (int) f+100, 300, Config.RGB_565);
Canvas c = new Canvas();
c.setBitmap(  img );
mFace = Typeface.createFromAsset(getAssets(),"DejaVuSansCondensed.ttf");
mPaint.setTypeface(mFace);
content = "????";
content = ArabicUtilities.reshape( content );
System.out.println("Drawing text: " + content);
c.drawText(content, 30, 30, mPaint);
Run Code Online (Sandbox Code Playgroud)

ArabicUtilities类是一个重塑unicode文本的工具,因此字母是连接的.请参阅:http://github.com/agawish/Better-Arabic-Reshaper/

但是,生成的位图如下所示:

alt text http://imagebin.ca/img/J1EB8DWc.jpg

它应该看起来像يجري

我相信这个问题是因为,与TextView不同,Bitmap类不支持BiDi,所以它从左边开始绘制字母.

尽我所能,我无法弄清楚如何以正确的顺序绘制文本.

android bidi right-to-left

4
推荐指数
1
解决办法
1万
查看次数

使用Spring Boot和Data JPA,尽管有OpenSesionInViewFilter,仍然会获得LazyInitializationException

我正在使用带有弹簧启动的tapestry 5,使用这个很棒的小库:https://github.com/code8/tapestry-boot

然而,尽管我使用了OpenSesionInViewFilter,但我得到了臭名昭着的LazyInitializationException.除了OpenSesionInViewFilter的优点和缺点之外,我还想在OpenSesionInViewFilter中使用它,因为我正在移植一个大型遗留应用程序.

我的春季启动配置是

@SpringBootApplication
public class Launcher {
    public static void main(String[] args) {
        new SpringApplicationBuilder(Launcher.class)
                .web(true)
                .run(args);
    }
    @Bean
    public HibernateJpaSessionFactoryBean sessionFactory() {
        return new HibernateJpaSessionFactoryBean();
    }

    @Bean
    public FilterRegistrationBean registerOpenSessionInViewFilterBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        OpenSessionInViewFilter filter = new OpenSessionInViewFilter();
        registrationBean.setFilter(filter);
        registrationBean.setOrder(5);
        return registrationBean;
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经确保在TapestryFilter之前加载了OpenSessionInViewFilter,并在启动时通过spring的输出验证了这一点.我在TapestryFilter上编辑了tapestry-boot库到setOrder(10).

我还通过调试验证了OpenSessionInViewFilter实际上正在创建一个会话.

在下面的LIE的示例堆栈跟踪中,您可以看到正在使用OpenSessionInViewFilter.

我有2级服务层:

Tapestry Pages --> XXManagerImpl (e.g, UserManager) --> JpaRepository
Run Code Online (Sandbox Code Playgroud)

我的经理服务注释如下:

@Service
@Transactional(propagation = Propagation.REQUIRED)
public class UserManagerImpl implements UserManager, Serializable
Run Code Online (Sandbox Code Playgroud)

我的JpaRepositories没有注释@Transactional和@Repository(如果它很重要).

初始数据访问按预期工作,但是当我尝试访问Lazy初始化字段时,我得到了LIE.

根异常:

Caused …
Run Code Online (Sandbox Code Playgroud)

hibernate tapestry spring-data spring-data-jpa spring-boot

4
推荐指数
1
解决办法
1757
查看次数

如何存储和推送模拟状态,同时最低限度地影响每秒更新?

我的应用程序由两个线程组成:

  1. GUI线程(使用Qt)
  2. 模拟线程

我使用两个线程的原因是保持GUI响应,同时让Sim线程尽可能快地旋转.

在我的GUI线程中,我在SIM卡中以30-60的FPS渲染实体; 但是,我希望我的SIM卡能够"紧缩" - 可以这么说 - 并最终排队游戏状态(想想流媒体视频,你有一个缓冲区).

现在,对于我渲染的每个帧,我需要相应的模拟"状态".所以我的sim线程看起来像:

while(1) {
    simulation.update();
    SimState* s = new SimState;
    simulation.getAgents( s->agents ); // store agents
    // store other things to SimState here..
    stateStore.enqueue(s); // stateStore is a QQueue<SimState*>
    if( /* some threshold reached */ )
        // push stateStore
}
Run Code Online (Sandbox Code Playgroud)

SimState 好像:

struct SimState {
    std::vector<Agent> agents;
    //other stuff here
};
Run Code Online (Sandbox Code Playgroud)

而Simulation :: getAgents看起来像:

void Simulation::getAgents(std::vector<Agent> &a) const
{
    // mAgents is a std::vector<Agent>
    std::vector<Agent> a_tmp(mAgents);
    a.swap(a_tmp);
}
Run Code Online (Sandbox Code Playgroud)

Agent本身就是一些复杂的课程.成员是一堆 …

c++ simulation performance qt multithreading

3
推荐指数
1
解决办法
681
查看次数

简单的@Configurable与现代spring-boot + gradle

我的目标是获得一个简单的facej + spring aop设置,这样我就可以在一个类上使用@Configurable.另一个限制是它需要使用加载时编织,因为Lombok不能与CTW一起使用.

好消息:我有它的工作!

坏消息:控制台充斥着[Xlint:cantFindType]错误.见下面的结果部分.

环境

我有一个单独的类注释@Configurable.它是杰克逊使用和实例化的一个类,因此需要AOP.它不是很有趣所以我不会在这里展示它.它只是一个普通的类,带有Configurable的单个注释,@Autowired里面有一个bean.

SpringBootApplication

我的Application类具有通常的注释:

@SpringBootApplication
@EnableSpringConfigured
@EnableLoadTimeWeaving
public class MyApplication {
Run Code Online (Sandbox Code Playgroud)

的build.gradle

我的build.gradle有所有常见的嫌疑人.样品:

configurations {
    springinstrument
}

dependencies {
    compile('org.projectlombok:lombok')

    compile('org.springframework.boot:spring-boot-starter-aop')
    compile("org.springframework.boot:spring-boot-starter-data-rest")
    compile('org.springframework.data:spring-data-rest-hal-browser')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-devtools')
    compile('org.springframework.plugin:spring-plugin:1.2.0.RELEASE')
..snip..
    runtime('org.springframework:spring-instrument:4.+')
    springinstrument "org.springframework:spring-instrument:4.+"
    runtime configurations.springinstrument.dependencies
}

test.doFirst {
    jvmArgs "-javaagent:${configurations.springinstrument.asPath}"
}
Run Code Online (Sandbox Code Playgroud)

jvm args

我正在使用以下args运行JUnit测试(通过Intellij的运行配置)

-ea
-javaagent:/Users/me/.gradle/caches/modules-2/files-2.1/org.springframework/spring-instrument/4.3.3.RELEASE/5db399fa5546172b9c107817b4abaae6b379bb8c/spring-instrument-4.3.3.RELEASE.jar
Run Code Online (Sandbox Code Playgroud)

aop.xml文件

我有一个src/main/resources/META-INF/aop.xml包含:

<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
        <weaver options="-Xreweavable -showWeaveInfo">
        <!-- only weave classes with @Configurable interface -->
        <include within="@org.springframework.beans.factory.annotation.Configurable …
Run Code Online (Sandbox Code Playgroud)

spring spring-aop gradle load-time-weaving spring-boot

3
推荐指数
1
解决办法
2091
查看次数