小编Tom*_*ský的帖子

在表上添加触发器时,PSQLException和锁定问题

更新:我从问题中消除了休眠。我完全重新编写了对问题的描述,以尽可能地简化它。

我有master带noop触发器的detail表和带masterdetail表之间的两个关系的表:

create table detail (
  id bigint not null,
  code varchar(255) not null,
  primary key (id)
);

create table master (
  id bigint not null,
  name varchar(255),
  detail_id bigint, -- "preferred" detail is one-to-one relation
  primary key (id),
  unique (detail_id),
  foreign key (detail_id) references detail(id)
);

create table detail_candidate ( -- "candidate" details = many-to-many relation modeled as join table
  master_id bigint not null,
  detail_id bigint not null,
  primary key (master_id, …
Run Code Online (Sandbox Code Playgroud)

postgresql triggers locking

12
推荐指数
1
解决办法
336
查看次数

为什么嵌套类型不能看到泛型类型参数的注释?

我没有得到以下代码的行为:https: //gist.github.com/tomaszalusky/3e3777b4fd0c6096f3f707bb19b50b52 - 请参阅embedded:

import java.lang.reflect.*;
import java.util.*;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


public class AnnotationOnTypeArgument {

    @Target({ElementType.FIELD,ElementType.PARAMETER,ElementType.METHOD,ElementType.TYPE_USE})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface Anno {

    }

    interface Nested<T> {

    }

    Toplevel<@Anno Integer> toplevel;

    Nested<@Anno Integer> nested;

    public static void main(String[] args) throws Exception {
        print(AnnotationOnTypeArgument.class.getDeclaredField("toplevel"));
        print(AnnotationOnTypeArgument.class.getDeclaredField("nested"));
    }

    private static void print(Field field) {
        AnnotatedType annotatedType = field.getAnnotatedType();
        AnnotatedParameterizedType annotatedParameterizedType = (AnnotatedParameterizedType)annotatedType;
        ParameterizedType parameterizedType = (ParameterizedType)annotatedParameterizedType.getType();
        AnnotatedType argType = annotatedParameterizedType.getAnnotatedActualTypeArguments()[0];
        System.out.printf("field %s%ntype=%s%nannotatedType=%s%nannotations=%s%ntype=%s%n%n",
                field.getName(), parameterizedType, argType, Arrays.asList(argType.getDeclaredAnnotations()), argType.getType());
    } …
Run Code Online (Sandbox Code Playgroud)

java generics reflection annotations java-8

6
推荐指数
2
解决办法
914
查看次数

Log4j2 滚动附加程序 - 文件名根据模式“滑动”

我寻找侧翻策略,其中当前的日志(有源输出目标手动文件名的术语)是不固定的,而是由一个模式指定,或-更确切地说-相同的图案,在filePattern属性。

我想在今天的日志所在的地方实现每日更新,log-2015-05-05.log并且在午夜框架停止写入它并开始写入log-2015-05-06.log. 但是,AFAIK,当前配置只允许

<RollingFile name="ROLFILE"
    fileName="log.log"
    filePattern="log-%d{yyyy-MM-dd}.log"
>
Run Code Online (Sandbox Code Playgroud)

fileName属性中指定相同的值不起作用(导致文件中的敏感字符按字面解释)。我注意到没有这样一个动态值的示例或 SO 问题fileName。请注意,这fileName="log-${date:yyyy-MM-dd}.log"并不能解决问题,因为表达式仅在启动时进行评估,即使它们的时间戳与表达式不匹配,事件仍会发送到文件中。

我正在从 Log4j 1.2 迁移到 Log4j 2.2。在旧版本中,可以使用所需的行为

<appender name="ROLFILE" class="org.apache.log4j.rolling.RollingFileAppender">
    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
        <param name="FileNamePattern" value="log-%d{yyyy-MM-dd}.log" />
    </rollingPolicy>
    ...
Run Code Online (Sandbox Code Playgroud)

我更喜欢保留当前方式,因为一些日志分析工具依赖于它。在 Log4j2 中可能吗?谢谢。

java logging log4j2

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

Oracle 更改表删除约束删除索引在语法上是否有效?

我有 Oracle 11.2.0.2.0 和一个由以下脚本创建的具有唯一约束的表:

    create table foo (id varchar(26) not null, name varchar(50) not null);
    alter table foo add constraint pk_foo primary key (id);
    /**/
    alter table foo add constraint un_foo unique (name); 
Run Code Online (Sandbox Code Playgroud)

我需要删除唯一约束,这很容易:

    alter table foo drop constraint un_foo;
Run Code Online (Sandbox Code Playgroud)

麻烦的是:当数据库在 SQL Developer 中备份然后恢复时,un_foo唯一索引是通过放置在行的显式命令创建的/**/

    CREATE UNIQUE INDEX un_foo ON foo (name);
Run Code Online (Sandbox Code Playgroud)

上面的alter 命令不会删除这种显式创建的索引。我意识到以下命令有效:

    alter table foo drop constraint un_foo drop index;
Run Code Online (Sandbox Code Playgroud)

对于主键,类似的命令alter table foo drop primary key drop index文档Oracle …

oracle syntax alter-table oracle11g

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

SQL聚合函数选择唯一值

我有一个包含两列的行集:technical_idnatural_id。行集实际上是复杂查询的结果。假定列中的值之间的映射是双射(即,对于两行相同technical_idnatural_ids为相同也为不同的technical_idS中的natural_ids为不同太)。(technical_id,natural_id)由于原始查询中的连接,这些对在行集中不是唯一的。例子:

with t (technical_id, natural_id, val) as (values
  (1, 'a', 1),
  (1, 'a', 2),
  (2, 'b', 3),
  (2, 'b', 2),
  (3, 'c', 0),
  (3, 'c', 1),
  (4, 'd', 1)
)
Run Code Online (Sandbox Code Playgroud)

不幸的是,双射仅由应用程序逻辑强制执行。的natural_id实际上是从多个表收集并使用由coalesce基于表达式,以便它的独特性几乎可以通过分贝约束来执行。

我需要通过technical_id假设natural_id是唯一的来聚合行集的行。如果不是(例如,如果将元组(4, 'x', 1)添加到示例数据中),则查询应该失败。在理想的 SQL 世界中,我会使用一些假设的聚合函数:

select technical_id, only(natural_id), sum(val)
from t
group by technical_id;
Run Code Online (Sandbox Code Playgroud)

我知道 SQL 中没有这样的功能。有什么替代方法或解决方法吗?Postgres 特定的解决方案也可以。

请注意,group by technical_id, natural_idor select …

sql postgresql aggregate unique aggregate-functions

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

强制 Oracle 在远程数据库站点上处理递归 CTE(可能使用 DRIVING_SITE 提示)

我正在尝试从远程表中获取数据。使用递归 CTE 从本地表中的种子数据集扩展数据。查询非常慢(300 个种子行到 800 个最终行需要 7 分钟)。

对于其他“微小的本地,巨大的远程” -没有递归查询的情况,DRIVING_SITE提示效果很好。我还尝试将种子集从本地表导出到remotedb具有相同结构的辅助表中,并且 - 已登录remotedb- 作为纯本地查询(my_tableas pmy_table_seed_copyas i)运行查询。花了 4 秒,这鼓励我相信强制查询到远程站点会使查询更快。

强制 Oracle 在远程站点上执行递归查询的正确方法是什么?

with s (id, data) as (
  select p.id, p.data
  from my_table@remotedb p
  where p.id in (select i.id from my_table i)
  union all
  select p.id, p.data
  from s
  join my_table@remotedb p on ...
)
select /*+DRIVING_SITE(p)*/ s.*
from s;
Run Code Online (Sandbox Code Playgroud)

在上面的查询中,我试过

  • select /*+DRIVING_SITE(p)*/ s.* 在主要选择
  • select /*+DRIVING_SITE(s)*/ s.* 在主要选择 …

sql oracle database-link recursive-query oracle11g

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