我希望为现有的java项目添加Groovy支持,这样我就可以使用invokedynamic无缝地编译混合的Java和Groovy代码,这样我就可以获得类似Java的执行速度,而不需要浪费过多的时间和冗长的Java语法
在看到gmaven插件不再支持编译 - 并且groovy eclipse编译器插件还不支持invokedynamic之后,我问自己,如果它编译不必要的慢速Groovy代码,为什么还要继续使用Maven?
因此,我决定尝试为Gradle删除maven,这样我就可以获得更快的代码,同时还将一些python部署脚本移植到Gradle任务,以便只需要一个代码库.
我有一些库存储在一个简单的密码保护的s3 maven存储库中(为了避免需要企业过度杀戮像artifactory).在做了一些基础研究之后,我发现Gradle没有内置支持添加自定义依赖关系管理,这是由这个堆栈overlow问题和这个支持论坛帖子确定的.
我确实设法找到了一个用于gradle的s3插件 - 但它没有处理依赖项的管理.
如果Gradle的整个要点比Maven更灵活,并且如果依赖管理/构建系统的核心目的是有效地管理来自各种源的依赖关系 - 那么缺乏对自定义存储库的支持似乎是一个相当重要的意义设计上的缺陷使我在Maven中遇到的任何问题都相形见绌.
但是,我很可能错过了一些东西,而且我已经投入了几个小时学习Gradle-我想我会看到是否有一些合理的方法来模拟这些s3依赖项的依赖关系管理,直到Gradle开发人员解决这个关键问题.否则,我将不得不得出这样的结论,我最好只使用Maven,直到编译器插件支持invokedynamic忍受较慢的Groovy代码.
基本上我需要一个解决方案,执行以下操作:
但是,我在文档中找不到任何可以给我一个线索的地方:
当我尝试使用Eclipse Moxy将类编组为JSON时,我遇到了一个非常恼人的错误.
我的一个域类中有一个具有以下值的属性:"the City’s original city site"
其中包含代码点u + 2019(')
当Jaxb试图编组这个值时,我莫名其妙地找回了一个奇怪的控件: "Citys original city site"
这会导致无效的JSON在解码时返回空值.我和杰克逊一起尝试了这个,并且收到了一个ascii转义字符,这仍然是错误的,但它至少会产生有效的JSON!
Moxy应该能够正确输出,因为'是一个有效的unicode字符,并且在JSON中是有效的.我能做些什么来正确输出'(和任何其他unicode字符),最好将这个不必要的字符转换为常规撇号.
这是我的提供者类:
@Provider
@Component("customMOXyJsonProvider")
public class CustomMOXyJsonProvider extends MOXyJsonProvider {
@Override
protected void preWriteTo(Object object, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, Marshaller marshaller)
throws JAXBException {
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING,"UTF-8");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Moxy的2.5.1版本.
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.5.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的系统中有几个组件理论上可能搞砸了这些值(postgres,jdbc,hibernate,cxf和tomcat),但我已经通过测试确定该值正确存储在我的域类中 - 然后损坏,就像Elliot Spitzer一样在编组阶段,拜访一名妓女.
我一直在努力让postgis 2.0在ubuntu-maverick-amd64 linux服务器上运行大约一周.我正在寻求光栅和拓扑支持.
我使用以下配置:
sudo ./configure --with-raster --with-topology --with-jsondir=/home/zonabili/json-c-0.9
Run Code Online (Sandbox Code Playgroud)
下面的配置文件描述了我的规格.
PostGIS is now configured for x86_64-unknown-linux-gnu
-------------- Compiler Info -------------
C compiler: gcc -g -O2
C++ compiler: g++ -g -O2
-------------- Dependencies --------------
GEOS config: /usr/local/bin/geos-config
GEOS version: 3.3.1
GDAL config: /usr/bin/gdal-config
GDAL version: 1.8.0
PostgreSQL config: /usr/bin/pg_config
PostgreSQL version: PostgreSQL 9.1.2
PROJ4 version: 47
Libxml2 config: /usr/bin/xml2-config
Libxml2 version: 2.7.7
JSON-C support: Yes
PostGIS debug level: 0
-------------- Extensions --------------
PostGIS Raster: 0.1.6d
PostGIS Topology
-------- Documentation Generation -------- …
Run Code Online (Sandbox Code Playgroud) 我希望能够添加一个请求范围的属性(一个 JAX-RS,ContainerRequestContext
因为我宁愿使用 Jackson 将我的参数转换为对象,而不是 JAX-RS 的构思和笨拙ParameterConverterProviders
)到 aDeserializationContext
以便它可以从内部获取一个JsonDeserializer
。我必须调用convertValue()
而不是简单地readValue()
(不处理实际的 JSON),所以我无法ObjectReader
在每个线程中创建一个,除非我愿意先将我的映射序列化为一个 JSON 字符串,然后再读回来 - 这将是非常低效的。
我希望能够以按请求的方式完成以下任务:
ObjectMapper om = new ObjectMapper();
//in request-scoped context:
om.getDeserializationContext().setAttribute("requestContext",containerRequestContext)
Map<String,Object> mapOfRequestParameters = ...
BeanOfVastImportance bean = om.convertValue(mapOfRequestParameters,BeanOfVastImportance.class)
Run Code Online (Sandbox Code Playgroud)
如何在不需要为每个单独的请求线程创建新的 ObjectMapper 的大量多余开销的情况下实现这一点?
我试图在这里指定的codehaus快照存储库中使用Groovy编译器的快照版本- 但似乎无法使maven看到存储库中的工件.
我有以下插件配置:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- 2.8.0-01 and later require maven-compiler-plugin 3.1 or higher -->
<version>3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<!-- set verbose to be true if you want lots of uninteresting messages -->
<!-- <verbose>true</verbose> -->
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.0-01-SNAPSHOT</version>
</dependency>
<!-- for 2.8.0-01 and later you must have an explicit dependency on groovy-eclipse-batch -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.2.1-01-SNAPSHOT</version>
<!-- or choose a different compiler version -->
<!-- <version>1.8.6-01</version> -->
<!-- <version>1.7.10-06</version> -->
</dependency>
</dependencies>
</plugin>
<plugin> …
Run Code Online (Sandbox Code Playgroud) 我有一个包含少量行的表,其中一个非常昂贵的函数需要在单独的工作进程中的每一行上运行,因为该函数非常占用 CPU。我可以通过将存储参数设置parallel_workers
为max_worker_processes
我在下面创建了一个易于重现的示例来强制对表进行并行顺序扫描,唯一的显着区别是值列的大小实际上是多个 MB。
CREATE OR REPLACE FUNCTION very_expensive_operation(value anyelement, sleep_time integer=2) RETURNS integer as $$
BEGIN
perform pg_sleep(sleep_time);
return sleep_time;
END;
$$ LANGUAGE plpgsql immutable strict parallel safe cost 10000;
CREATE UNLOGGED TABLE expensive_rows (
id serial PRIMARY KEY,
value uuid
) WITH (parallel_workers = 8);
INSERT INTO expensive_rows(value) select gen_random_uuid() identifier from generate_series(1,16);
EXPLAIN ANALYSE VERBOSE
SELECT
very_expensive_operation(value,2)
FROM
expensive_rows
;
Run Code Online (Sandbox Code Playgroud)
Gather (cost=0.00..5312.12 rows=1700 width=4) (actual time=2010.650..32042.558 rows=16 loops=1)
" Output: (very_expensive_operation(value, 2))"
Workers Planned: …
Run Code Online (Sandbox Code Playgroud) groovy ×2
postgresql ×2
amazon-s3 ×1
artifact ×1
build.gradle ×1
geos ×1
gradle ×1
jackson ×1
jax-rs ×1
jaxb ×1
jersey-2.0 ×1
json ×1
linux ×1
marshalling ×1
maven ×1
moxy ×1
pom.xml ×1
postgis ×1
repository ×1
ubuntu ×1
utf-8 ×1
web-services ×1