我创建了一个Hibernate(3.5)Criteria查询:
Criteria criteria = db.getSession().createCriteria(Vendor.class);
criteria.add(Restrictions.isEmpty("models"));
Run Code Online (Sandbox Code Playgroud)
当使用Criteria.list执行时,Hibernate会生成以下SQL(为了便于阅读而简化):
SELECT this_.*
FROM VENDOR this_
left outer join MODEL models1_
ON this_.id = models1_.VENDOR_ID
WHERE NOT EXISTS (SELECT 1
FROM MODEL
WHERE this_.id = VENDOR_ID)
Run Code Online (Sandbox Code Playgroud)
我想要做的是在"不存在"部分中添加一个限制,以便SQL查询看起来像这样
Run Code Online (Sandbox Code Playgroud)
SELECT this_.* FROM VENDOR this_
left outer join MODEL models1_
ON this_.id = models1_.VENDOR_ID
WHERE
NOT EXISTS (SELECT 1
FROM MODEL
WHERE this_.id = VENDOR_ID AND DEPRECATED = 0 )
是否可以使用Hibernate Criteria API,如果可以,怎么做?或者是否有其他可能实现相同的结果(但仍然使用Criteria API)?
我们有一个项目,在Tomcat应用程序中通过JacoZoom访问第三方DLL .显然DLL泄漏内存(由供应商确认),但供应商无意修复此问题.内存泄漏迫使Tomcat定期重启,这对用户来说自然是一个很大的不便.
解决这个问题的最佳方法是什么?我们考虑的一个选项是拥有Tomcat服务器的两个实例并定期重新启动另一个实例,并将用户重定向到另一个实例.
编辑:通过创建另一个DLL来解决,该DLL在需要时杀死并重新创建供应商DLL.基本上这三个kernel32调用用于完成功能:
Private Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleW" (ByVal DllName As Long) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
幸运的是,JacoZoom JAR文件似乎并不介意DLL被杀死并重新创建.
我试图模仿strtok功能,但得到分段错误.请帮帮我.
这是我的代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char argv[])
{
int i=0;
char c[]="get the hell out of here";
char *p;
char *temp=(char *)malloc(100);
while(c[i]!='\0')
{
if(c[i]!=' ')
{
*temp=c[i];
temp++;
i++;
}
else
{
*temp='\0';
printf("printing tokenn");
puts(temp);
i++;
temp="";
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 嗨,我是java的新手,因为我知道set collection不会重复,当contains已经存在于collection中时,它的contains方法应该返回true.我试图在程序下运行,但我得到了意想不到的结果.
public class UserDefinedName {
private final String first, last;
public UserDefinedName(String first, String last) {
this.first = first;
this.last = last;
}
public boolean equals(Object o) {
if (!(o instanceof UserDefinedName))
return false;
UserDefinedName n = (UserDefinedName) o;
return n.first.equals(first) && n.last.equals(last);
}
public static void main(String[] args) {
Set<UserDefinedName> s = new HashSet<UserDefinedName>();
s.add(new UserDefinedName("Carballo", "Videl"));
System.out.println(s.contains(new UserDefinedName("Carballo", "Videl")));
}
}
Run Code Online (Sandbox Code Playgroud)
我期待输出为true但程序打印为false.我做错了什么?
当我执行命令
echo '<test>' | sed -e 's/<\(.*\)>/\1/g'
Run Code Online (Sandbox Code Playgroud)
我得到了字符串
test
Run Code Online (Sandbox Code Playgroud)
回.当我执行命令
echo 'Jun 10 13:23:16 server /opt/app/introdedaemon/sbin/mq2init[14150]: Debug 1433935396.995245: (XMLRPCConnector.cpp)(MQMessage)(98)[domt initrode.om]: encoded string: <aGVyZSBpcyBub3RoaW5n c3RpbGwgbm90aGluZw== > (size 908)' | sed -e 's/<\(.*\)>/\1/g'
Run Code Online (Sandbox Code Playgroud)
我希望得到这个字符串
aGVyZSBpcyBub3RoaW5n c3RpbGwgbm90aGluZw==
Run Code Online (Sandbox Code Playgroud)
回来了,但不是我得到的字符串
Jun 10 13:23:16 server /opt/app/introdedaemon/sbin/mq2init[14150]: Debug 1433935396.995245: (XMLRPCConnector.cpp)(MQMessage)(98)[domt initrode.om]: encoded string: aGVyZSBpcyBub3RoaW5n c3RpbGwgbm90aGluZw== (size 908)
Run Code Online (Sandbox Code Playgroud)
背部.为什么会发生这种情况,并且我可以将正则表达式返回到字符串的"<"和">"之间
Jun 10 13:23:16 server /opt/app/introdedaemon/sbin/mq2init[14150]: Debug 1433935396.995245: (XMLRPCConnector.cpp)(MQMessage)(98)[domt initrode.om]: encoded string: <aGVyZSBpcyBub3RoaW5n c3RpbGwgbm90aGluZw== > (size 908)
Run Code Online (Sandbox Code Playgroud)
?
我试图从类UserHelper中的方法importUsers抛出(自定义)ImportException.我可以在调试器中看到执行了throw子句,但调用importUsers方法的方法从不捕获异常.
这是抛出异常的方法:
public static AccessorValidator importUsers(List<String> data, WebUser actor) throws ImportException {
//(irrelevant code removed)
try {
isSuccess = insertUserData(st, blocks, db, actor);
} catch (Exception e) {
throw new ImportException("Could not insert user on line " + rowCounter);
}
Run Code Online (Sandbox Code Playgroud)
}
在这里,我尝试从AccessorValidator类中的execute方法捕获抛出的异常失败:
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
//(irrelevant code removed)
try{
av = UserHelper.importUsers(data, admin);
System.out.print("test2");
} catch (ImportException ie) {
System.out.print("testE");
returnMessageValue = ie.getMessage();
} catch (Exception e) {
System.out.print("testE2");
} …Run Code Online (Sandbox Code Playgroud) 我习惯于使用MSSQL以及企业管理器和查询分析器.现在使用Oracle 9.2并且不得不使用SQL Plus进行查询,我正在寻找一些更好的选择.是否有用于此目的的免费或低成本工具?
我在JavaScript中有一组对象,如下所示:
Object collection = new Object();
collection[123] = new Item(); //another object
collection[425] = new Item();
collection[2134] = new Item();
//etc. etc.
//TODO: sort items
Run Code Online (Sandbox Code Playgroud)
我想根据集合中Item对象的属性对此集合进行排序.JS Array中有很好的内置排序功能,所以我的第一个想法是随后修改代码:
Object collection = new Array();
collection[123] = new Item(); //another object
collection[425] = new Item();
collection[2134] = new Item();
//etc. etc.
collection.sort(comparisonFunction); //where comparisonfunction handles the sorting logic
Run Code Online (Sandbox Code Playgroud)
现在集合很好地排序 - 但是,我无法使用属性访问项目,我曾经用它来设置它们,即
collection[2134]
Run Code Online (Sandbox Code Playgroud)
是null,因为JS数组不包含那么多元素(即使它会,它的结果也不会如预期的那样)
我需要的是
编辑:对象不需要像数组一样运行,也不是自然数组.我需要的是非常接近Java TreeMap - 一个集合,它维护一个特定的顺序,也是一个地图.或者以另一种方式解释,我需要一个普通的旧JavaScript对象(有些人称之为"关联数组"),其包含的用户创建的元素可以被排序.
编辑2:我最终使用的解决方案是Anatoliy,稍加修改.基本上我创建了一个数组,我在其中复制"集合"并映射两个对象(数组和集合)以获得两者的好处.还要感谢Roatin Marth指出迭代对象不能保证以任何顺序发生(我在修改Anatoliy的解决方案时考虑过这一点).
这是我的测试:
var test = function () {
$.each([1, 2], function () {
if(true !== false) { // it is just an example
alert('I am here');
return false; // how should I make the function test to stop or to exit here?
}
});
return true;
}?;
alert(test());
Run Code Online (Sandbox Code Playgroud)
我希望test函数返回false但它返回true.
为什么?我该如何修复代码?请参阅评论以获取更多详细信息.
我有一个清单
List<FeatureHolder> featureHolderList;
Run Code Online (Sandbox Code Playgroud)
由FeatureHolder对象组成
public class FeatureHolder {
private String flag;
private String value;
}
Run Code Online (Sandbox Code Playgroud)
现在,我需要从featureSetList中提取Map。当然,解决方案很简单:
Map<String, String> map = new HashMap<>();
for(FeatureHolder fh: featureHolderList){
map.put(fh.getFlag(), fh.getValue());
}
Run Code Online (Sandbox Code Playgroud)
问题是,在Java 7中是否有更好(更短)的方法?我已经研究了例如Google Collections和方法Maps.uniqueIndex,但是以这种方式执行转换所需的代码将更长,并且可读性可能较低。
我在Oracle数据库中有一个包含日期字段EXPIRYDATE的表.我需要从表格中选择所有记录,其中日期字段的小时和分钟部分设置为0(即午夜).我怎样才能做到这一点?
我尝试使用提取功能(http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions050.htm),但显然它只接受YEAR,MONTH或DAY作为日期字段的参数.
我在未排序的集合中有一组分层项.这些项目中的每一项都有一个字段previousItem:
public class Item{
public Item previousItem;
}
Run Code Online (Sandbox Code Playgroud)
处理这些项目的最有效方法是什么,以便输出是一个集合,其中没有任何previousItem的Item是集合中的第一个Item,而每个后续项目的previousItem是集合中的前一个项目?
我的第一个想法是在Item类中实现Comparable接口:
public int compareTo(Item that) {
final int BEFORE = -1;
final int EQUAL = 0;
final int AFTER = 1;
if(this.previousItem==null){
return BEFORE;
}
if(that.previousItem==null){
return AFTER;
}
if(this.previousItem.equals(that){
return AFTER;
}else if(that.previousItem.equals(this){
return BEFORE;
}
return EQUAL;
}
Run Code Online (Sandbox Code Playgroud)
然后遍历项目并将它们添加到TreeSet:
SortedSet<Item> itemSortedSet = new TreeSet<Item>();
for (Item item : itemCollection) {
itemSortedSet.add(item);
}
Run Code Online (Sandbox Code Playgroud)
是否有更有效的方法(处理所需的时间更少/需要的迭代次数)来订购集合,使它们处于逻辑层次顺序?