我正在尝试使用jOOQ库在PostgreSQL中执行UPSERT.
为此,我目前正在尝试在jOOQ中实现以下SQL语句:https://stackoverflow.com/a/6527838
到目前为止我的代码看起来像这样:
public class UpsertExecutor {
private static final Logger logger = LoggerFactory.getLogger(UpsertExecutor.class);
private final JOOQContextProvider jooqProvider;
@Inject
public UpsertExecutor(JOOQContextProvider jooqProvider) {
Preconditions.checkNotNull(jooqProvider);
this.jooqProvider = jooqProvider;
}
@Transactional
public <T extends Record> void executeUpsert(Table<T> table, Condition condition, Map<? extends Field<?>, ?> recordValues) {
/*
* All of this is for trying to do an UPSERT on PostgreSQL. See:
* https://stackoverflow.com/a/6527838
*/
SelectConditionStep<Record1<Integer>> notExistsSelect = jooqProvider.getDSLContext().selectOne().from(table).where(condition);
SelectConditionStep<Record> insertIntoSelect = jooqProvider.getDSLContext().select(recordValues).whereNotExists(notExistsSelect);
try {
int[] result = jooqProvider.getDSLContext().batch(
jooqProvider.getDSLContext().update(table).set(recordValues).where(condition),
jooqProvider.getDSLContext().insertInto(table).select(insertIntoSelect) …Run Code Online (Sandbox Code Playgroud) 我有一个PostgreSQL数据库,我试图总结一下收银机的收入.收银机可以具有状态ACTIVE或INACTIVE,但我只想总结在给定时间段内处于ACTIVE状态时创建的收益.
我有两张桌子; 一个标志着收入,另一个标志着收银机状态:
CREATE TABLE counters
(
id bigserial NOT NULL,
"timestamp" timestamp with time zone,
total_revenue bigint,
id_of_machine character varying(50),
CONSTRAINT counters_pkey PRIMARY KEY (id)
)
CREATE TABLE machine_lifecycle_events
(
id bigserial NOT NULL,
event_type character varying(50),
"timestamp" timestamp with time zone,
id_of_affected_machine character varying(50),
CONSTRAINT machine_lifecycle_events_pkey PRIMARY KEY (id)
)
Run Code Online (Sandbox Code Playgroud)
每1分钟添加一个计数器条目,而total_revenue仅增加.每次机器状态发生变化时,都会添加machine_lifecycle_events条目.
我添加了一个说明问题的图像.应该总结蓝色时期的收入.

我创建了一个查询,它可以在给定的瞬间为我提供总收入:
SELECT total_revenue
FROM counters
WHERE timestamp < '2014-03-05 11:00:00'
AND id_of_machine='1'
ORDER BY
timestamp desc
LIMIT 1
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何想法?
示例数据: …
sql postgresql aggregate-functions date-arithmetic window-functions
我正在尝试使用Guice Persist创建一个带有@Transactional注释方法的简单服务类:
public class TestServiceImpl implements TestService {
@Inject
private Provider<EntityManager> entityManager;
@Override
@Transactional
public Long createEvent(String name) {
Event event = new Event(name);
System.out.println("Is transaction active? " + entityManager.get().getTransaction().isActive() );
entityManager.get().persist(event);
return event.getId();
}
}
Run Code Online (Sandbox Code Playgroud)
遗憾的是,Guice Persist没有创建任何交易.日志输出可以在这里看到:http://pastebin.com/Mh5BkqSC
请注意第450行的打印:
交易是否有效?假
结果是数据库中没有存储任何内容:
mydb=# \d
List of relations
Schema | Name | Type | Owner
--------+--------------------+----------+----------
public | events | table | postgres
public | hibernate_sequence | sequence | postgres
(2 rows)
mydb=# select * from events;
id | …Run Code Online (Sandbox Code Playgroud) 我想在Dart中实现以下代码:
var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
}
});
Run Code Online (Sandbox Code Playgroud)
我的Dart实现如下所示:
class HelloWorldScene {
HelloWorldScene() {
var sceneCollectionJS = new JsObject.jsify({ "onEnter": _onEnter});
context["HelloWorldScene"] = context["cc"]["Scene"].callMethod("extend", [sceneCollectionJS]);
}
void _onEnter() {
context["this"].callMethod("_super");
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,运行代码时出现以下错误:
null对象没有方法'callMethod'
在以下行:
context ["this"].callMethod("_ super",[]);
context ["this"]似乎是null,所以我的问题是:如何从Dart引用"this"变量?
更新1:完整的示例代码可以在github上找到:https: //github.com/uldall/DartCocos2dTest
我试图通过在Swagger YAML中描述它来创建REST服务.
该服务有三条路径:
我当前描述这些路径的YAML文件如下所示:
swagger: '2.0'
info:
version: '0.0.1'
title: Test API
host: api.test.com
basePath: /
schemes:
- https
consumes:
- application/json
produces:
- application/json
paths:
/versions:
post:
responses:
'201':
description: Returns all versions.
default:
description: unexpected error
/partners/{partnerId}/users/{userId}/sessions:
parameters:
- name: partnerId
in: path
type: integer
- name: userId
in: path
type: string
post:
responses:
'201':
description: Returns a UserSession object with info about the …Run Code Online (Sandbox Code Playgroud) java ×2
postgresql ×2
sql ×2
dart ×1
hibernate ×1
javascript ×1
jooq ×1
jpa ×1
rest ×1
swagger ×1
swagger-2.0 ×1
transactions ×1
upsert ×1
yaml ×1