/** * Add a discriminator value with its associated class. * @param value the value * @param type the class * @return the current builder */ public DiscriminatorJdbcSubBuilder when(String value, Class<? extends T> type) { return when(value, (Type)type); }
/** * Add a discriminator value with its associated class. * @param value the value * @param type the class * @return the current builder */ public DiscriminatorJdbcSubBuilder when(String value, Class<? extends T> type) { return when(value, (Type)type); }
/** * Add a discriminator value with its associated type specified by the type reference. * @param value the value * @param type the type reference * @return the current builder */ public DiscriminatorJdbcSubBuilder when(String value, TypeReference<? extends T> type) { return when(value, type.getType()); }
/** * Add a discriminator value with its associated type. * @param value the value * @param type the type * @return the current builder */ public DiscriminatorJdbcSubBuilder when(String value, Type type) { return when(new DiscriminatorPredicate(value), type); }
/** * Add a discriminator value with its associated type specified by the type reference. * @param value the value * @param type the type reference * @return the current builder */ public DiscriminatorJdbcSubBuilder when(String value, TypeReference<? extends T> type) { return when(value, type.getType()); }
/** * Add a discriminator value with its associated type. * @param value the value * @param type the type * @return the current builder */ public DiscriminatorJdbcSubBuilder when(String value, Type type) { return when(new DiscriminatorPredicate(value), type); }
@Test public void testJoinTableCNoAsmMultiThread() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(4); try { final JdbcMapper<Person> mapper = JdbcMapperFactoryHelper.noAsm() .addKeys("id", "students_id") .<Person>newDiscriminator("person_type") .when("student", StudentGS.class) .when("professor", ProfessorGS.class) .mapper(); List<Future<Object>> futures = new ArrayList<Future<Object>>(100); for (int i = 0; i <300; i++) { futures.add(executor.submit(new Callable<Object>() { @Override public Object call() throws Exception { validateMapper(mapper); return null; } })); } for(Future<Object> f : futures) { f.get(); } } finally { executor.shutdown(); } }
@Test public void testDiscriminatorNoAsm() throws Exception { JdbcMapper<Person> mapper = JdbcMapperFactoryHelper.noAsm() .addKeys("id", "students_id") .<Person>newDiscriminator("person_type") .when("student", StudentGS.class) .when("professor", ProfessorGS.class) .mapper(); validateMapper(mapper); }
@Test public void testDiscriminator() throws Exception { JdbcMapper<Person> mapper = JdbcMapperFactoryHelper.asm() .addKeys("id", "students_id") .<Person>newDiscriminator("person_type") .when("student", StudentGS.class) .addMapping("person_type") .addMapping("id") .addMapping("name", 3, FieldMapperColumnDefinition.<JdbcColumnKey>identity()) .when(new Predicate<String>() { @Override public boolean test(String s) { return "professor".equals(s); } }, ProfessorGS.class) .mapper(); validateMapper(mapper); }