小编Joh*_*rts的帖子

休眠左外连接

我有一个Hibernate服务方法:"SELECT sc FROM SecurityContact sc WHERE sc.securityId=:securityId2".securityId2由用户传入.每个SecurityContact与Contact都有多对一的关系,因此Hibernate会在运行此查询时自动调用连接.但是,Hibernate总是运行的连接是一个内部连接,它不能用于我的目的.有没有办法强制Hibernate在内部生成左外连接?以下是SecurityContact类的代码:

/**
 * The persistent class for the SecurityContact database table.
 * 
 */
@Entity
@FXClass(kind=FXClassKind.REMOTE)
public class SecurityContact implements Serializable {
    private static final long serialVersionUID = 1L;
    @Transient private String uid;
    @FXIgnore
    public String getUid() {
        if (uid == null) {
            uid = "" + securityContactId;
        }
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="securityContact_id")
    private Long securityContactId;

    @Column(name="security_id")
    private String securityId;

    @Column(name="create_date")
    private …
Run Code Online (Sandbox Code Playgroud)

java hibernate

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

作业调度算法

在面试中得到了这个问题.想知道是否有更好的解决方案:

给定N个任务以及它们之间的依赖关系,请提供执行序列,以确保在不违反依赖关系的情况下执行作业.

示例文件:

1 <4

3 <2

4 <5

第一行是总任务的数量.1 <4表示任务1必须在任务4之前执行.

一个可能的顺序是:1 4 5 3 2

我的解决方案使用DAG存储所有数字,然后进行拓扑排序.是否有一种不那么严厉的方法来解决这个问题?:

    DirectedAcyclicGraph<Integer, DefaultEdge> dag = new DirectedAcyclicGraph<Integer, DefaultEdge>(DefaultEdge.class); 
    Integer [] hm = new Integer[6];
    //Add integer objects to storage array for later edge creation and add vertices to DAG
    for(int x = 1; x <= numVertices; x++){
        Integer newInteger = new Integer(x);
        hm[x] = newInteger;
        dag.addVertex(newInteger);
    }
    for(int x = 1; x < lines.size()-1; x++){
        //Add edges between vertices
        String[] parts = lines.get(x).split("<"); …
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

聆听流程开始和结束

我是Windows API编程的新手.我知道有办法检查进程是否已经运行(通过枚举).但是,我想知道是否有一种方法可以监听进程何时开始和结束(例如,notepad.exe),然后在检测到该进程的开始或结束时执行某些操作.我假设可以为每个边际单位时间运行连续枚举和检查循环,但我想知道是否有更清洁的解决方案.

c++ winapi visual-c++

7
推荐指数
1
解决办法
3428
查看次数

如何在Windows上使用Flex

如果这是一个愚蠢的问题我很抱歉,但我对这个工具有0次经验,想知道我是否正在使用它.我已经下载了flex,在编译我的lex文件时,会生成一个C文件,然后需要单独编译.这是最好的方法吗?

c windows lex flex-lexer

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

制作语法LL(1)

我有以下语法:

S→a S b S | b S a S | ε

因为我正在尝试为它编写一个小编译器,所以我想把它变成LL(1).我看到这里似乎存在FIRST/FOLLOW冲突,我知道我必须使用替换来解决它,但我不确定如何解决它.这是我提出的语法,但我不确定它是否正确:

S-> aSbT | 小量

T-> bFaF | 小量

F-> epsilon

有人可以帮忙吗?

grammar parsing programming-languages context-free-grammar ll-grammar

7
推荐指数
1
解决办法
3101
查看次数

使用SSL避免登陆页面重定向

我最近对我的网站进行了Google PageSpeed分析,并收到以下消息:

避免登陆页面重定向

您的页面有2个重定向.重定向会在加载页面之前引入其他延迟.

避免对以下重定向网址链的目标网页重定向.

http://example.net/

https://example.net/

https://www.example.net/

我能做些什么(比如以某种方式修改我的htaccess文件),或者这是不可避免的后果?

这是我的htaccess以防万一:

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Run Code Online (Sandbox Code Playgroud)

url performance .htaccess ssl redirect

7
推荐指数
1
解决办法
6181
查看次数

查找数组中单词之间的最小距离

例:

WordDistanceFinder finder = new WordDistanceFinder(Arrays.asList("the","quick","brown","fox","quick"));

断言(finder.distance("fox","the")== 3);

断言(finder.distance("quick","fox")== 1);

我有以下解决方案,似乎是O(n),但我不确定是否有更好的解决方案.有没有人有任何想法?

String targetString = "fox";
String targetString2 = "the";
double minDistance = Double.POSITIVE_INFINITY;
for(int x = 0; x < strings.length; x++){
    if(strings[x].equals(targetString)){
        for(int y = x; y < strings.length; y++){
            if(strings[y].equals(targetString2))
                if(minDistance > (y - x))
                    minDistance = y - x;
        }
        for(int y = x; y >=0; y--){
            if(strings[y].equals(targetString2))
                if(minDistance > (x - y))
                    minDistance = x - y;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java algorithm

7
推荐指数
1
解决办法
7248
查看次数

获取本地Android项目文件的文件路径

我想以编程方式访问将包含在我的项目文件夹中的特定文件。有没有办法做到这一点?如果是这样,我将文件放在项目文件夹中的什么位置,获取其文件路径的简单代码是什么?

private void saveFileToDrive() {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    java.io.File spreadsheet = new java.io.File("Untitled spreadsheet.xlsx");
                    String filePath = spreadsheet.getAbsolutePath();
                    System.out.println("file path is"+filePath);

                    URL fileURL = getClass().getClassLoader().getResource("Untitled spreadsheet.xlsx");
                    String filePath2 = fileURL.getPath();
                    System.out.println("file path2 is"+filePath2);

                    java.io.File fileContent = new java.io.File(filePath);
                    FileContent mediaContent = new FileContent("application/vnd.ms-excel", fileContent);

                    File body = new File();
                    body.setTitle(fileContent.getName());
                    body.setMimeType("application/vnd.ms-excel");


                    File file = service.files().insert(body, mediaContent).setConvert(true).execute();

                    if (file != null) {
                        showToast("File uploaded: " + file.getTitle());
                    }
                    else
                             ; …
Run Code Online (Sandbox Code Playgroud)

java android file

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

C++ - 为什么在删除后将对象设置为null?

我正在查看我在网上找到的以下链接列表代码:

void DeleteAfter(Node **head){
      if(*head==NULL){
            return;
      }else{
            Node *temp = NULL;
            temp = (*head)->next;
            (*head)->next = (*head)->next->next;
            delete temp;
            temp=NULL;
      }
}
Run Code Online (Sandbox Code Playgroud)

我不熟悉C++,所以这可能是一个糟糕的问题,但为什么temp被删除后被设置为NULL?这是必要的一步吗?

c++

6
推荐指数
1
解决办法
8080
查看次数

二进制数的正则表达式可被3整除

我是自学正则表达式,并在网上发现了一个有趣的练习题,包括编写一个正则表达式来识别所有可被3整除的二进制数(只有这样的数字).说实话,问题是要为这样的场景构建DFA,但我认为使用正则表达式应该是等效的.

我知道有一个小规则来确定二进制数是否可被3整除:取数字中偶数位的1的数量,并减去数字中奇数位的1的数量 - 如果这等于零,该数字可被3整除(例如:偶数2个时隙中的110-1和奇数1个时隙中的1).但是,我在修改正则表达式方面遇到了一些麻烦.

我最接近的是意识到数字可以是0,所以这将是第一个状态.我还看到所有可被3整除的二进制数从1开始,所以这将是第二个状态,但我从那里被卡住了.有人可以帮忙吗?

regex dfa

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