我有以下集合类型:
Map<String, Collection<String>> map;
Run Code Online (Sandbox Code Playgroud)
我想map.size()从每个Key的集合中的单个值创建每个组的唯一组合.
例如,假设地图如下所示:
A, {a1, a2, a3, ..., an}
B, {b1, b2, b3, ..., bn}
C, {c1, c2, c3, ..., cn}
Run Code Online (Sandbox Code Playgroud)
我希望获得的List<Set<String>>结果是一个结果,看起来类似于(排序并不重要,它只需要是一个由所有可能的组合组成的'完整'结果):
{a1, b1, c1},
{a1, b1, c2},
{a1, b1, c3},
{a1, b2, c1},
{a1, b2, c2},
{a1, b2, c3},
...
{a2, b1, c1},
{a2, b1, c2},
...
{a3, b1, c1},
{a3, b1, c2},
...
{an, bn, cn}
Run Code Online (Sandbox Code Playgroud)
这基本上是一个计数问题,但我想看看是否可以使用Java 8流解决方案.
我正在使用Jersey Test Framework,但是,即使在代码进入我的测试之前,JerseyTest构造函数也会失败:
Mar 06, 2014 6:40:44 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.6 2014-02-18 21:52:53...
A MultiException has 3 exceptions. They are:
1. java.lang.NullPointerException
2. java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
3. java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
MultiException stack 1 of 3
java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(AbstractJAXBProvider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.invoke(ReflectionHelper.java:1017)
at org.jvnet.hk2.internal.ClazzCreator.methodMe(ClazzCreator.java:375)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:428)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)
at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:69)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2445)
Run Code Online (Sandbox Code Playgroud)
我的测试非常简单:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/applicationContext-test.xml"})
public class BidAPITest …Run Code Online (Sandbox Code Playgroud) 我们的实体之一是使用 @Where 注释定义的,以处理“软删除”。
@Entity
@Where(clause="user_type_cd != 'X'")
public class User {
...
Run Code Online (Sandbox Code Playgroud)
现在,我们意识到有时我们仍然想找到这样的实体。不幸的是,@Where 注释按设计工作,因此我们在 JPARepository 中定义的查找器无法查找已删除的用户。
例如,
@Repository("userRepo")
public interface UserRepository extends JpaRepository<User, Long> {
User findByLoginId(String login);
}
Run Code Online (Sandbox Code Playgroud)
如果用户已被删除,则如果 user_type_cd 等于 'X',则 findByLoginIs() 方法将不会返回用户。
但是,有时我们还是想找到这样的用户,所以我想把
@Where(clause="user_type_cd != 'X'")
Run Code Online (Sandbox Code Playgroud)
从实体到存储库的注释。这样,我不必更新存储库中的所有方法,它会自动将此标准添加到所有查找器。然后,我可以创建另一个存储库,该存储库将在不考虑软删除的情况下找到所有用户。
但是,我无法弄清楚可以用来使所有查找器自动附加
clause="user_type_cd != 'X'"
Run Code Online (Sandbox Code Playgroud)
存储库的所有方法的标准,而我不必为每个 finder 方法显式编写自定义 @Query("... and user_type_cd != 'X'") 。
因此,简而言之,我正在寻找所有自动生成的 findBy 以及将 user_type_cd != 'X' 附加到生成的每个 find 的方法。
关于如何在不使用自定义 @Query 注释的情况下完成此操作的任何想法?
我正在使用Spring Data for MongoDB,我需要能够在运行时配置集合.
我的存储库定义为:
@Repository
public interface EventDataRepository extends MongoRepository<EventData, String> {
}
Run Code Online (Sandbox Code Playgroud)
我试过这个愚蠢的例子:
@Document(collection = "${mongo.event.collection}")
public class EventData implements Serializable {
Run Code Online (Sandbox Code Playgroud)
但是mongo.event.collection没有像使用@Value注释那样解析为名称.
多一点调试和搜索,我尝试了以下内容:@Document(collection ="#{$ {mongo.event.collection}}")
这产生了一个例外:
Caused by: org.springframework.expression.spel.SpelParseException: EL1041E:(pos 1): After parsing a valid expression, there is still more data in the expression: 'lcurly({)'
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:129)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:60)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:32)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpressions(TemplateAwareExpressionParser.java:154)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseTemplate(TemplateAwareExpressionParser.java:85)
Run Code Online (Sandbox Code Playgroud)
也许我只是不知道如何使用SPel来访问Spring的Property Configurer中的值.
单步执行代码时,我发现有一种方法可以指定集合名称甚至表达式,但是,我不确定应该将哪个注释用于此目的或如何执行.
谢谢.-AP_
我找到了一个如何使用类映射进行单表继承的示例。
http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#single-table-inheritance
但是对于我的生活,我找不到如何使用经典映射器执行此操作的示例,以便我可以将我的类和持久映射分开。
如何将此示例转换为经典映射?我很清楚创建表,只是不确定如何实际构建映射器。
在示例中,定义了以下类型:
class Employee(Base):
class Manager(Employee):
class Engineer(Employee):
Run Code Online (Sandbox Code Playgroud)
假设我已经创建了适当的表:
employee = Table(...Column(type...))
Run Code Online (Sandbox Code Playgroud)
我如何为映射器编写代码,以便经理和工程师都生活在同一个表中(单表继承),按类型(“经理”、“工程师”或其他员工)区分?
谢谢。
python inheritance sqlalchemy single-table-inheritance mapper
java ×2
spring ×2
exception ×1
inheritance ×1
java-8 ×1
java-stream ×1
jersey ×1
jpql ×1
mapper ×1
mongodb ×1
null ×1
pointers ×1
python ×1
repository ×1
spring-data ×1
sqlalchemy ×1
testing ×1