本文整理汇总了Java中com.holonplatform.core.beans.BeanPropertySet类的典型用法代码示例。如果您正苦于以下问题:Java BeanPropertySet类的具体用法?Java BeanPropertySet怎么用?Java BeanPropertySet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BeanPropertySet类属于com.holonplatform.core.beans包,在下文中一共展示了BeanPropertySet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DefaultTableItemListingBuilder
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public DefaultTableItemListingBuilder(Class<T> beanType) {
super(new DefaultBeanListing<>(RenderingMode.TABLE));
ObjectUtils.argumentNotNull(beanType, "Item bean type must be not null");
// setup datasource
BeanPropertySet<T> ps = BeanPropertySet.create(beanType);
getInstance().setPropertySet(ps);
final List<String> nested = new LinkedList<>();
ps.forEach(p -> {
final String name = p.fullName();
dataSourceBuilder.withProperty(name, p.getType());
if (p.getParent().isPresent()) {
nested.add(p.relativeName());
}
});
// item adapter
dataSourceBuilder.itemAdapter(new BeanItemAdapter(nested));
}
示例2: DefaultGridItemListingBuilder
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public DefaultGridItemListingBuilder(Class<T> beanType) {
super(new DefaultBeanListing<>(RenderingMode.GRID));
ObjectUtils.argumentNotNull(beanType, "Item bean type must be not null");
// setup datasource
BeanPropertySet<T> ps = BeanPropertySet.create(beanType);
getInstance().setPropertySet(ps);
final List<String> nested = new LinkedList<>();
ps.forEach(p -> {
final String name = p.fullName();
dataSourceBuilder.withProperty(name, p.getType());
if (p.getParent().isPresent()) {
nested.add(p.relativeName());
}
});
// item adapter
dataSourceBuilder.itemAdapter(new BeanItemAdapter(nested));
}
示例3: setInsertedIds
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
/**
* Set the entity id values of given <code>entity</code> instance to be returned as an {@link OperationResult}.
* @param result OperationResult in which to set the ids
* @param entityManager EntityManager
* @param set Entity bean property set
* @param entity Entity class
* @param instance Entity instance
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void setInsertedIds(OperationResult.Builder result, EntityManager entityManager,
BeanPropertySet<Object> set, Class<?> entity, Object instance, boolean bringBackGeneratedIds,
PropertyBox propertyBox) {
try {
getIds(entityManager, set, entity).forEach(p -> {
Object keyValue = set.read(p, instance);
result.withInsertedKey(p, keyValue);
if (bringBackGeneratedIds && keyValue != null) {
// set in propertybox
Property property = getPropertyForPath(p, propertyBox);
if (property != null) {
propertyBox.setValue(property, keyValue);
}
}
});
} catch (Exception e) {
LOGGER.warn("Failed to obtain entity id(s) value", e);
}
}
示例4: testBeanPropertyPostProcessors
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@Test
public void testBeanPropertyPostProcessors() {
BeanPropertySet<TestJpaDomain> set = BeanPropertySet.create(TestJpaDomain.class);
assertTrue(set.getProperty("dateValue").isPresent());
assertEquals(TemporalType.DATE,
set.getProperty("dateValue").get().getConfiguration().getTemporalType().orElse(null));
assertTrue(set.getProperty("enumValue").isPresent());
assertTrue(set.getProperty("enumValue").get().getConverter().isPresent());
assertEquals(EnumByOrdinalConverter.class, set.getProperty("enumValue").get().getConverter().get().getClass());
assertEquals("enmv", set.getProperty("enumValue").get().getConfiguration()
.getParameter(JpaPropertyConfiguration.COLUMN_NAME).orElse(null));
assertEquals("nested", set.getProperty("nested").get().getConfiguration()
.getParameter(JpaPropertyConfiguration.COLUMN_NAME).orElse(null));
}
示例5: getPropertySet
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T> BeanPropertySet<T> getPropertySet(Class<? extends T> beanClass, Path<?> parentPath) {
ObjectUtils.argumentNotNull(beanClass, "Bean class must be not null");
LOGGER.debug(() -> "Get BeanPropertySet for bean class [" + beanClass + "]");
synchronized (cache) {
if (CACHE_ENABLED && cache.containsKey(beanClass)) {
return cache.get(beanClass);
}
BeanPropertySet beanPropertySet = buildBeanPropertySet(beanClass, parentPath);
if (CACHE_ENABLED) {
BeanPropertySet existing = cache.putIfAbsent(beanClass, beanPropertySet);
return (existing != null ? existing : beanPropertySet);
}
return beanPropertySet;
}
}
示例6: insert
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@Override
public OperationResult insert(DataTarget<?> target, PropertyBox propertyBox, WriteOption... options) {
ObjectUtils.argumentNotNull(target, "DataTarget must be not null");
ObjectUtils.argumentNotNull(propertyBox, "PropertyBox must be not null");
return withEntityManager(entityManager -> {
// get entity class
Class<?> entity = getEntityClass(target, entityManager);
// create a new instance
Object instance = entity.newInstance();
// Bean property set
final BeanPropertySet<Object> set = getBeanIntrospector().getPropertySet(entity);
// persist entity
entityManager.persist(set.write(propertyBox, instance));
// check auto-flush
if (isAutoFlush() || JpaDatastoreUtils.isFlush(options)) {
entityManager.flush();
}
OperationResult.Builder result = OperationResult.builder().type(OperationType.INSERT).affectedCount(1);
// get ids
setInsertedIds(result, entityManager, set, entity, instance, isBringBackGeneratedIds(options), propertyBox);
return result.build();
});
}
示例7: save
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@Override
public OperationResult save(DataTarget<?> target, PropertyBox propertyBox, WriteOption... options) {
ObjectUtils.argumentNotNull(target, "DataTarget must be not null");
ObjectUtils.argumentNotNull(propertyBox, "PropertyBox must be not null");
return withEntityManager(entityManager -> {
// get entity class
Class<?> entity = getEntityClass(target, entityManager);
OperationResult.Builder result = OperationResult.builder().affectedCount(1);
// Bean property set
final BeanPropertySet<Object> set = getBeanIntrospector().getPropertySet(entity);
// create instance and write values
Object instance = set.write(propertyBox, entity.newInstance());
// check has identifier
if (entityManager.getEntityManagerFactory().getPersistenceUnitUtil().getIdentifier(instance) == null) {
result.type(OperationType.INSERT);
entityManager.persist(instance);
} else {
result.type(OperationType.UPDATE);
entityManager.merge(instance);
}
// check auto-flush
if (isAutoFlush() || JpaDatastoreUtils.isFlush(options)) {
entityManager.flush();
}
// get ids
setInsertedIds(result, entityManager, set, entity, instance, isBringBackGeneratedIds(options), propertyBox);
return result.build();
});
}
示例8: AbstractBeanConverter
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
public AbstractBeanConverter(BeanPropertySet<T> beanPropertySet, Path<?>[] selection,
Map<Path<?>, String> selectionAlias) {
super();
this.beanPropertySet = beanPropertySet;
this.selection = selection;
this.selectionAlias = selectionAlias;
}
示例9: buildBeanPropertySet
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
/**
* Build a new {@link BeanPropertySet} for given bean class
* @param beanClass Bean class for which to build the BeanPropertySet
* @param parentPath Optional parent path to set as bean root properties parent path
* @return BeanPropertySet instance
* @throws BeanIntrospectionException Error during bean introspection
*/
private <T> BeanPropertySet<T> buildBeanPropertySet(Class<? extends T> beanClass, Path<?> parentPath)
throws BeanIntrospectionException {
LOGGER.debug(() -> "Build BeanPropertySet for bean class [" + beanClass + "]");
List<BeanProperty<?>> properties = resolveBeanProperties(beanClass, parentPath, null);
// sort
properties.sort(SEQUENCE_COMPARATOR);
return new DefaultBeanPropertySet<>(beanClass, properties);
}
示例10: testPropertyReadWrite
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@Test
public void testPropertyReadWrite() {
BeanPropertySet<TestBeanPropertyBean> set = BeanIntrospector.get().getPropertySet(TestBeanPropertyBean.class);
TestBeanPropertyBean instance = new TestBeanPropertyBean();
set.write("name", "test", instance);
set.write("lng", 7L, instance);
set.write("notneg", 1, instance);
set.write("numbool", Boolean.TRUE, instance);
set.write("enm", TestEnum2.B, instance);
set.write("enmOrdinal", TestEnum.ONE, instance);
assertEquals("test", set.read("name", instance));
assertEquals(Boolean.TRUE, set.read("numbool", instance));
assertEquals(TestEnum2.B, set.read("enm", instance));
assertEquals(TestEnum.ONE, set.read("enmOrdinal", instance));
assertEquals(Long.valueOf(7), set.read("lng", instance));
assertEquals(Integer.valueOf(1), set.read("notneg", instance));
PathProperty<Integer> modelEnum = PathProperty.create("enmOrdinal", Integer.class);
PropertyBox pb = PropertyBox.create(modelEnum);
set.read(pb, instance);
}
示例11: testBeanPropertiesNone
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@Test
public void testBeanPropertiesNone() {
BeanPropertySet<Object> ctx = BeanIntrospector.get().getPropertySet(Object.class);
assertNotNull(ctx);
assertEquals(0, ctx.size());
}
示例12: testIgnoreProperty
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@SuppressWarnings("boxing")
@Test
public void testIgnoreProperty() {
BeanPropertySet<TestBean> testBeanContext = BeanIntrospector.get().getPropertySet(TestBean.class);
BeanPropertySet<TestBean2> testBean2Context = BeanIntrospector.get().getPropertySet(TestBean2.class);
assertFalse(testBeanContext.getProperty("internalToIgnore").isPresent());
assertFalse(testBean2Context.getProperty("nested").isPresent());
assertFalse(testBean2Context.getProperty("nested.nestedId").isPresent());
assertFalse(testBean2Context.getProperty("nested.nestedDate").isPresent());
Date date = new Date();
TestBean2 testMock = mock(TestBean2.class);
when(testMock.getSomeDecimal()).thenReturn(new BigDecimal(2.7));
TestNested testNested = mock(TestNested.class);
when(testNested.getNestedId()).thenReturn(2L);
when(testNested.getNestedDate()).thenReturn(date);
when(testMock.getNested()).thenReturn(testNested);
Object value = testBean2Context.read("someDecimal", testMock);
assertEquals(new BigDecimal(2.7), value);
}
示例13: BeanResultSetConverter
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
/**
* Constructor
* @param dialect Dialect (not null)
* @param beanPropertySet Bean property set (not null)
* @param pathSelection Query selection (not null)
*/
public BeanResultSetConverter(JdbcDialect dialect, BeanPropertySet<T> beanPropertySet,
Map<String, Path<?>> pathSelection) {
super();
ObjectUtils.argumentNotNull(dialect, "Dialect must be not null");
ObjectUtils.argumentNotNull(beanPropertySet, "Bean property set must be not null");
ObjectUtils.argumentNotNull(pathSelection, "Selection must be not null");
this.dialect = dialect;
this.beanPropertySet = beanPropertySet;
this.pathSelection = pathSelection;
}
示例14: setPropertySet
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
public void setPropertySet(BeanPropertySet<T> propertySet) {
this.propertySet = propertySet;
}
示例15: execute
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@Override
public OperationResult execute() {
if (values.isEmpty()) {
throw new DataAccessException("No values to insert");
}
return context.withEntityManager(entityManager -> {
// try to detect batch size
int batchSize = 0;
Map<String, Object> properties = entityManager.getEntityManagerFactory().getProperties();
if (properties != null) {
try {
Object hibernateBatchSize = properties.get("hibernate.jdbc.batch_size");
if (hibernateBatchSize != null) {
if (hibernateBatchSize instanceof Number) {
batchSize = ((Number) hibernateBatchSize).intValue();
} else if (hibernateBatchSize instanceof String) {
batchSize = Integer.valueOf((String) hibernateBatchSize);
}
}
if (batchSize <= 0) {
Object eclipselinkBatchSize = properties.get("eclipselink.jdbc.batch-writing.size");
if (eclipselinkBatchSize instanceof Number) {
batchSize = ((Number) eclipselinkBatchSize).intValue();
} else if (eclipselinkBatchSize instanceof String) {
batchSize = Integer.valueOf((String) eclipselinkBatchSize);
}
}
} catch (Exception e) {
LOGGER.warn("Failed to detect batch insert size", e);
}
}
// Get the JPA entity class
final JpaResolutionContext resolutionContext = JpaResolutionContext.create(
context.getEntityManagerFactory(), context.getORMPlatform().orElse(null), this,
AliasMode.UNSUPPORTED);
JpaEntity<?> jpaEntity = resolutionContext.resolve(target, JpaEntity.class, resolutionContext).orElseThrow(
() -> new InvalidExpressionException("Failed to resolve data target [" + target + "]"));
jpaEntity.validate();
final Class<?> entity = jpaEntity.getEntityClass();
// Bean property set
final BeanPropertySet<Object> set = beanIntrospector.getPropertySet(entity);
int i = 0;
for (PropertyBox value : values) {
// persist entity
entityManager.persist(set.write(adapt(value), entity.newInstance()));
// check flush
if (batchSize > 0 && i % batchSize == 0) {
entityManager.flush();
entityManager.clear();
}
}
// check auto-flush
if (context.isAutoFlush() || JpaDatastoreUtils.isFlush(writeOptions)) {
entityManager.flush();
}
return OperationResult.builder().type(OperationType.INSERT).affectedCount(values.size()).build();
});
}