本文整理汇总了Java中com.holonplatform.core.beans.BeanPropertySet类的典型用法代码示例。如果您正苦于以下问题:Java BeanPropertySet类的具体用法?Java BeanPropertySet怎么用?Java BeanPropertySet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BeanPropertySet类属于com.holonplatform.core.beans包,在下文中一共展示了BeanPropertySet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:20,代码来源:DefaultTableItemListingBuilder.java
示例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));
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:20,代码来源:DefaultGridItemListingBuilder.java
示例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);
}
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:29,代码来源:DefaultJpaDatastore.java
示例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));
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:20,代码来源:TestBase.java
示例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;
}
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:18,代码来源:DefaultBeanIntrospector.java
示例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();
});
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:33,代码来源:DefaultJpaDatastore.java
示例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();
});
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:41,代码来源:DefaultJpaDatastore.java
示例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;
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:8,代码来源:AbstractBeanConverter.java
示例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);
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:16,代码来源:DefaultBeanIntrospector.java
示例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);
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:28,代码来源:TestBeanIntrospector.java
示例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());
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:9,代码来源:TestProperty.java
示例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);
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:28,代码来源:TestProperty.java
示例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;
}
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:19,代码来源:BeanResultSetConverter.java
示例14: setPropertySet
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
public void setPropertySet(BeanPropertySet<T> propertySet) {
this.propertySet = propertySet;
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:4,代码来源:DefaultBeanListing.java
示例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();
});
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:70,代码来源:JpaBulkInsert.java
示例16: BeanTupleConverter
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
public BeanTupleConverter(BeanPropertySet<T> beanPropertySet, Path<?>[] selection,
Map<Path<?>, String> selectionAlias) {
super(beanPropertySet, selection, selectionAlias);
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:5,代码来源:BeanTupleConverter.java
示例17: BeanResultArrayConverter
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
public BeanResultArrayConverter(BeanPropertySet<T> beanPropertySet, Path<?>[] selection,
Map<Path<?>, String> selectionAlias) {
super(beanPropertySet, selection, selectionAlias);
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:5,代码来源:BeanResultArrayConverter.java
示例18: beanProperties
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@Test
public void beanProperties() {
// Obtain the PropertySet of the TestBean class
final BeanPropertySet<TestBean> BEAN_PROPERTIES = BeanPropertySet.create(TestBean.class);
// A BeanPropertySet is a standard PropertySet
PropertySet<?> set = BEAN_PROPERTIES;
int size = set.size();
// expect 5 properties
assertEquals(5, size);
// Get a bean property as a typed PathProperty
PathProperty<Long> ID = BEAN_PROPERTIES.getProperty("id", Long.class).orElse(null);
assertNotNull(ID);
// check all expected properties are in the set
assertTrue(BEAN_PROPERTIES.contains(ID));
assertTrue(BEAN_PROPERTIES.contains(BEAN_PROPERTIES.requireProperty("description")));
assertTrue(BEAN_PROPERTIES.contains(BEAN_PROPERTIES.requireProperty("category")));
assertTrue(BEAN_PROPERTIES.contains(BEAN_PROPERTIES.requireProperty("unitPrice")));
assertTrue(BEAN_PROPERTIES.contains(BEAN_PROPERTIES.requireProperty("withdrawn")));
// The @Caption annotation can be used to set property (localizable) captions
String caption = ID.getMessage();
assertEquals("Product ID", caption);
String translationMessageCode = ID.getMessageCode();
assertEquals("product.id", translationMessageCode);
// Read and write single bean property values
TestBean bean = new TestBean();
bean.setDescription("Bean description");
// write the ID property value
BEAN_PROPERTIES.write(ID, Long.valueOf(2), bean);
// write the ID property value using the "id" path
BEAN_PROPERTIES.write("id", Long.valueOf(2), bean);
// read the ID property value
Long idValue = BEAN_PROPERTIES.read(ID, bean);
assertEquals(Long.valueOf(2), idValue);
// The PropertyBox API is fully supported to get and set bean property values
// read the bean instance as a PropertyBox
PropertyBox box = BEAN_PROPERTIES.read(bean);
assertEquals(Long.valueOf(2), box.getValue(ID));
assertEquals("Bean description", box.getValue(BEAN_PROPERTIES.requireProperty("description")));
// write a PropertyBox into a TestBean instance
Property<Double> PRICE = BEAN_PROPERTIES.requireProperty("unitPrice", Double.class);
PropertyBox box2 = PropertyBox.builder(BEAN_PROPERTIES).set(ID, 3L)
.set(PRICE, Double.valueOf(12.65)).build();
TestBean bean2 = BEAN_PROPERTIES.write(box2, new TestBean());
assertEquals(Long.valueOf(3), bean2.getId());
assertEquals(Double.valueOf(12.65), bean2.getUnitPrice());
}
开发者ID:holon-platform,项目名称:holon-examples,代码行数:66,代码来源:TestPropertyModel.java
示例19: introspect
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
public void introspect() {
// tag::introspector[]
BeanIntrospector introspector = BeanIntrospector.get(); // <1>
BeanPropertySet<MyBean> properties = introspector.getPropertySet(MyBean.class); // <2>
// end::introspector[]
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:7,代码来源:ExampleBeans.java
示例20: testDataTarget
import com.holonplatform.core.beans.BeanPropertySet; //导入依赖的package包/类
@Test
public void testDataTarget() {
TestBoxBeanPk pk = new TestBoxBeanPk();
pk.setCode(1L);
TestBoxBean bean = new TestBoxBean();
bean.setPk(pk);
bean.setStr("test");
final DataTarget<String> TARGET = DataTarget.named("testTarget");
PathProperty<Long> CODE = TARGET.property("pk.code", Long.class);
PathProperty<String> STR = TARGET.property("str", String.class);
PropertySet<?> SET = PropertySet.of(CODE, STR);
BeanPropertySet<TestBoxBean> beanProperties = BeanIntrospector.get().getPropertySet(TestBoxBean.class);
PropertyBox box = beanProperties.read(PropertyBox.create(SET), bean);
assertNotNull(box);
assertEquals(Long.valueOf(1), box.getValue(CODE));
assertEquals("test", box.getValue(STR));
TestBoxBean written = beanProperties.write(box, new TestBoxBean());
assertNotNull(written);
assertEquals(1L, written.getPk().getCode());
assertEquals("test", written.getStr());
// with parent pk
PathProperty<TestBoxBeanPk> PK = TARGET.property("pk", TestBoxBeanPk.class);
CODE = TARGET.property("code", Long.class).parent(PK);
STR = TARGET.property("str", String.class);
SET = PropertySet.of(PK, CODE, STR);
box = BeanIntrospector.get().read(PropertyBox.create(SET), bean);
assertNotNull(box);
assertEquals(Long.valueOf(1), box.getValue(CODE));
assertEquals("test", box.getValue(STR));
assertEquals(pk, box.getValue(PK));
written = BeanIntrospector.get().write(box, new TestBoxBean());
assertNotNull(written);
assertEquals(1L, written.getPk().getCode());
assertEquals("test", written.getStr());
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:51,代码来源:TestQueryData.java
注:本文中的com.holonplatform.core.beans.BeanPropertySet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论