java.lang.Class.getInterfaces返回所有直接实现的接口,即不遍历类树以获取所有父类型的所有接口.例如,层次结构
public interface A {}
public interface B {}
public interface C extends B {}
public class Foo implements A {} // Foo.class.getInterfaces() returns [A]
public class Bar implements C {} // Bar.class.getInterfaces() returns [C], note B is not included.
Run Code Online (Sandbox Code Playgroud)
因为Bar我想得到[B, C],但对于任意树深度.
我自己可以写这个,但我确定一个图书馆必须存在才能做到这一点,任何想法?
CollectionUtils :: removeAll()Commons Collections 3.2.1
我一定是要疯了,因为看起来这个方法正在做与文档状态相反的方法:
从集合中删除remove中的元素.也就是说,此方法返回一个集合,其中包含c中未删除的所有元素.
这个小JUnit测试
@Test
public void testCommonsRemoveAll() throws Exception {
String str1 = "foo";
String str2 = "bar";
String str3 = "qux";
List<String> collection = Arrays.asList(str1, str2, str3);
System.out.println("collection: " + collection);
List<String> remove = Arrays.asList(str1);
System.out.println("remove: " + remove);
Collection result = CollectionUtils.removeAll(collection, remove);
System.out.println("result: " + result);
assertEquals(2, result.size());
}
Run Code Online (Sandbox Code Playgroud)
失败了
java.lang.AssertionError:expected:<2>但是:<1>
和打印
collection: [foo, bar, qux]
remove: [foo]
result: [foo]
Run Code Online (Sandbox Code Playgroud)
从我读到的文档我应该期待[bar, qux].我错过了什么?
Found non-empty schema "public" without metadata table! Use init() or set initOnMigrate to true to initialize the metadata table.
public名为schema的模式中创建一个表spatial_ref_sys.当我flyway migrate在这个数据库上运行时,我得到了上述错误.运行init似乎创建public.schema_version表并将版本1标记为SUCCEDED而不实际运行迁移文件.我也尝试过initOnMigrate没有成功的组合.Flyway未配置为管理任何架构.
关于如何在这种情况下运行迁移的任何想法?
我test-jar使用此设置设置了使用普通jar 构建的项目:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这个问题是每当我升级pom中的项目版本时,我需要使用测试进行构建,否则maven将无法在test-compile短语中找到具有正确版本的测试jar .很多时候我只想跳过测试,但是由于测试罐丢失,这个test-compile短语会失败.
我尝试使用-Dmaven.test.skip=true,但似乎没有跳过这test-compile句话.有没有办法跳过这个?
我正在尝试在开发过程中为我的JS文件设置合理的缓存过期.我有标准设置,HTML,CSS和JS都在static目录下.
该文档也提到这一点,但我的生活,我不能得到这个工作.我先尝试过隐含的两种方法
class MyFlask(flask.Flask):
def get_send_file_max_age(self, name):
if name.lower().endswith('.js'):
return 60
return flask.Flask.get_send_file_max_age(self, name)
app = MyFlask(__name__)
Run Code Online (Sandbox Code Playgroud)
和
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 60
Run Code Online (Sandbox Code Playgroud)
两者都没有效果,我在/ static下的JS文件仍然会返回默认的缓存超时,
Cache-Control: public, max-age=43200
Run Code Online (Sandbox Code Playgroud)
任何指针赞赏.
我只想针对特定的mongodb数据库运行.js脚本,但似乎无法获得正确的语法.
echo "print(db.address.find().limit(1));" > test.js
mongo test.js
Run Code Online (Sandbox Code Playgroud)
如何选择将要执行的数据库,我尝试了各种组合,但use foo没有成功.
> show dbs
admin (empty)
local (empty)
foo 0.203125GB
bar 0.203125GB
Run Code Online (Sandbox Code Playgroud)
我想foo在这种情况下使用.
符合ISO8601标准的日期时间
2004-10-19 10:23:54+02
Run Code Online (Sandbox Code Playgroud)
是否可以将具有+02偏移量的值反映在存储的列值中,并在选择时保留该值?
从我阅读文档的相应部分 Postgres的默认行为是转换为UTC,此时原始偏移量将丢失.这当然是我所看到的.
通过无法添加任何特殊tz转换的ORM访问数据,因此我真的需要简单地将日期时间与原始偏移量一起存储,并在选择时反映该值.
对于任何想要告诉我它是时间相同的实例的人来说,保留这个值对这些数据具有重要意义.
要求是简单地获得给定时区的当前墙壁时间(包括正确的DST调整).
似乎有一些问题在这里徘徊,但我似乎无法找到一个直接的答案(在SO,Joda doco或谷歌搜索)与低摩擦的方式来获得墙上的时间.看起来像给定的输入(当前UTC时间和期望的TZ)我应该能够从Joda Time库链接一些方法来实现我想要的但是在所述示例中似乎希望评估+处理偏移/应用程序代码中的转换 - 我希望尽可能避免这种情况,并根据其可用的静态TZ规则集使用Jodas尽力而为.
出于这个问题的目的,我们假设我不会使用任何其他第三方服务(基于网络或其他二进制文件),只有JDK和JodaTime库提供的服务.
任何指针赞赏.
更新: 这实际上是代表我的失误.我根据请求经度得到了一个计算的 UTC偏移量,而这显然你需要区域信息来获得正确的DST调整.
double aucklandLatitude = 174.730423;
int utcOffset = (int) Math.round((aucklandLatitude * DateTimeConstants.HOURS_PER_DAY) / 360);
System.out.println("Offset: " + utcOffset);
DateTimeZone calculatedDateTimeZone = DateTimeZone.forOffsetHours(utcOffset);
System.out.println("Calculated DTZ: " + calculatedDateTimeZone);
System.out.println("Calculated Date: " + new DateTime(calculatedDateTimeZone));
System.out.println();
DateTimeZone aucklandDateTimeZone = DateTimeZone.forID("Pacific/Auckland");
System.out.println("Auckland DTZ: " + aucklandDateTimeZone);
System.out.println("Auckland Date: " + new DateTime(aucklandDateTimeZone));
Run Code Online (Sandbox Code Playgroud)
版画
Offset: 12
Calculated DTZ: +12:00
Calculated Date: 2012-02-08T11:20:04.741+12:00
Auckland DTZ: Pacific/Auckland
Auckland Date: 2012-02-08T12:20:04.803+13:00
Run Code Online (Sandbox Code Playgroud)
因此,在阳光明媚的奥克兰,新西兰,我们在夏令时期为+12但是+13. …
特别是我对使用PostgreSQLs json类型感兴趣.
问题的核心似乎是Eclipselink中没有内部映射来json 键入.因此,使用一种天真的方法:
@Column(name = "json", columnDefinition = "json")
public String getJson() {
return json;
}
Run Code Online (Sandbox Code Playgroud)
...并尝试插入一个对象,我得到一个例外:
Internal Exception: org.postgresql.util.PSQLException: ERROR: column "json" is of type json but expression is of type character varying
Run Code Online (Sandbox Code Playgroud)
我觉得很公平.
通过EclipseLink文档,似乎适用的自定义(转换映射,本机查询,转换器)依赖于由支持的映射(数字,日期,字符串等)组成的数据,因此使得使用它变得非常尴尬供应商特定类型.
这是如此令人沮丧的主要原因是jsonposgresql 中的类型表达与text/varchar相同,我相信(目前,但不是永远)只是该类型的别名 - 因此驱动程序能够传输这个,这只是我的验证规则.
就解决方案而言,我不介意丢失可移植性(在数据库不可知和使用供应商特定类型方面),但只是想要一个允许我json在普通JPA实体上使用类型作为属性并保留所有它习惯的其他行为(模式生成,合并,持久化,事务代码
问题与此大致相同,但是我想让django将详细的请求信息记录到我的logging.FileHandler- 即不必查看我的webservers日志.我已经尝试并且未能设置默认记录器django.requests以向处理程序写入除4xx和5xx请求信息之外的其他内容.
所以我在完成文档和摆弄记录器和级别之后得出的结论是,django实际上并没有制作大量的日志语句 - 所以我想确认django没有在内部记录非错误的情况要求.
java ×3
postgresql ×2
timezone ×2
build ×1
collections ×1
compilation ×1
django ×1
eclipselink ×1
flask ×1
flyway ×1
jdbc ×1
jodatime ×1
jpa ×1
json ×1
logging ×1
maven ×1
mongo-shell ×1
mongodb ×1
python ×1
reflection ×1
skip ×1
static-files ×1
testing ×1
timestamp ×1