当前位置: 首页>>代码示例>>Java>>正文


Java BeanUtils类代码示例

本文整理汇总了Java中org.boon.core.reflection.BeanUtils的典型用法代码示例。如果您正苦于以下问题:Java BeanUtils类的具体用法?Java BeanUtils怎么用?Java BeanUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BeanUtils类属于org.boon.core.reflection包,在下文中一共展示了BeanUtils类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SQLDMLObject

import org.boon.core.reflection.BeanUtils; //导入依赖的package包/类
/**
 * Create a SQLDML query for the given instance
 *
 * @param documentInstance
 */
public SQLDMLObject(final T documentInstance,final FieldCriterionTransformer transformer,boolean forcedInsert) {

    this.documentMeta = DocumentMeta.fromAnnotation(documentInstance.getClass());
    fieldAccess = BeanUtils.getFieldsFromObject(documentInstance.getClass());

    Object id = BeanUtils.getPropertyValue(documentInstance, documentMeta.getIdField());
    extraValues  = generateExtraValues(documentInstance,true,this.documentMeta,fieldAccess);

    if ( id == null  ||  forcedInsert ) {
        if ( id == null ) {
            id = UUID.randomUUID().toString();
            fieldAccess.get(documentMeta.getIdField()).setObject(documentInstance,id);
        }
        sqlQuery = generateInsert(documentMeta,indexMapping);
    } else {
        sqlQuery = generateUpdate(documentInstance,documentMeta,indexMapping,transformer);
        extraValues.put(documentMeta.getIdField(),id);
    }



}
 
开发者ID:wmira,项目名称:nosql-jdbc,代码行数:28,代码来源:SQLDMLObject.java

示例2: generateUpdate

import org.boon.core.reflection.BeanUtils; //导入依赖的package包/类
public static <T> String generateUpdate(final T documentInstance,final DocumentMeta meta,final Map<Integer,String> indexMapping,final FieldCriterionTransformer transformer) {

        Object id = BeanUtils.getPropertyValue(documentInstance, meta.getIdField());
        String idStr;
        try {
            idStr = id.toString();
        } catch ( Exception e) {
            throw new RuntimeException("Unable to retrieve id field: " + e.getMessage(),e);
        }

        FieldCriterion fd = transformer.idFieldCriterion(meta,idStr);
        StringBuilder builder = new StringBuilder("UPDATE " + meta.getTableName() + " SET " + generateUpdateQuery(meta,indexMapping) + " WHERE " + fd.toSQLString(null));
        
        int lastIdx = 0;
        for ( Integer g : indexMapping.keySet() ) {
            if ( g > lastIdx ) {
                lastIdx = g;
            }
        }

        //indexMapping.put(1,meta.getColumnName());
        indexMapping.put(lastIdx+1,meta.getIdField());

        return builder.toString();
    }
 
开发者ID:wmira,项目名称:nosql-jdbc,代码行数:26,代码来源:SQLDMLObject.java

示例3: SQLObjectQuery

import org.boon.core.reflection.BeanUtils; //导入依赖的package包/类
/**
 *
 *
 * @param documentClass
 */
public SQLObjectQuery(final Class<T> documentClass,final SQLAlias thealias,boolean traverse) {

    this.documentClass = documentClass;
    this.meta = DocumentMeta.fromAnnotation(this.documentClass);
    this.alias = thealias == null ? new SQLAlias() : thealias;


    //create some needed stuf
    //TODO: opportunity for caching here
    this.fields = BeanUtils.getFieldsFromObject(this.documentClass);
    this.fieldRefs = DocumentRefMeta.lookupDocumentMetaRefs(fields);


    this.alias.addAliasFor(this.meta.getTableName());
    this.columnQuery = new SQLColumnQuery(this,null,null);

    if ( traverse && this.fieldRefs != null && this.fieldRefs.size() > 0 ) {

        for ( String documentRefKey : this.fieldRefs.keySet() ) {
            DocumentRefMeta refMeta = this.fieldRefs.get(documentRefKey);
            //DocumentRef ref = refMeta.getDocumentRef();
            Class<T> cls = refMeta.document();
            SQLObjectQuery cobjectQuery = new SQLObjectQuery(cls,alias,false);
            referenceObjectQuery.put(documentRefKey,cobjectQuery);
            refsColumnQuery.put(documentRefKey,new SQLColumnQuery(cobjectQuery,refMeta,this));
        }
    }
}
 
开发者ID:wmira,项目名称:nosql-jdbc,代码行数:34,代码来源:SQLObjectQuery.java

示例4: setObjectRef

import org.boon.core.reflection.BeanUtils; //导入依赖的package包/类
public static <T> void setObjectRef(final T instance,final SQLObjectQuery parentObjectQuery, final DocumentRefMeta refMeta,
    final SQLObjectQuery refObjectQuery,final ResultSet rs) throws Exception {

    Object ref = createDocumentFromRs(refMeta.document(),refObjectQuery,rs);
    if ( ref == null ) {
        return;
    }

    Map<String,FieldAccess> faccessMap = parentObjectQuery.getObjectFields();

    FieldAccess fieldAccess = faccessMap.get(refMeta.getFieldName());

    if ( fieldAccess != null ) {
        fieldAccess.setObject(instance,ref);
    }

    FieldAccess fieldIdAccess = faccessMap.get(refMeta.getRefIdFieldName());

    //set the ID
    DocumentMeta thisMeta = refMeta.getMeta();
    FieldAccess refFieldAccess = BeanUtils.getField(ref,thisMeta.getIdField());

    if ( refFieldAccess != null ) {
        Object id = refFieldAccess.getObject(ref);
        fieldIdAccess.setObject(instance,id);
    }


}
 
开发者ID:wmira,项目名称:nosql-jdbc,代码行数:30,代码来源:PgsqlJsonRepository.java

示例5: mergeNotNullToFirstUnSafe

import org.boon.core.reflection.BeanUtils; //导入依赖的package包/类
private static <T> T mergeNotNullToFirstUnSafe(T dest, Object... srcs) {
	for (Object src : srcs) {
		Set<String> ignores = Sets.set();
		Map<String, FieldAccess> fieldMap = BeanUtils.getFieldsFromObject(src);
		for (Entry<String, FieldAccess> entry : fieldMap.entrySet()) {
			System.out.println(entry);
			if (entry.getValue().getObject(src) == null) {
				ignores.add(entry.getKey());
			}
		}
		BeanUtils.copyProperties(src, dest, ignores);
	}
	return dest;
}
 
开发者ID:East196,项目名称:maker,代码行数:15,代码来源:Merger.java

示例6: mergeToFirst

import org.boon.core.reflection.BeanUtils; //导入依赖的package包/类
public static <T> T mergeToFirst(T template, Object... srcs) {
	T dest = BeanUtils.copy(template);
	for (Object src : srcs) {
		BeanUtils.copyProperties(src, dest);
	}
	return dest;
}
 
开发者ID:East196,项目名称:maker,代码行数:8,代码来源:Merger.java

示例7: testDocumentRefMeta

import org.boon.core.reflection.BeanUtils; //导入依赖的package包/类
@Test
public void testDocumentRefMeta() {

    Class cls = Parent.class;

    Map<String,FieldAccess> fields = BeanUtils.getFieldsFromObject(cls);

    Map<String,DocumentRefMeta> metas = DocumentRefMeta.lookupDocumentMetaRefs(fields);

    assertNotNull("should not be null",metas);
    assertEquals("Should be equal to 1", 1, metas.size());


    DocumentRefMeta refMeta = metas.get("singleChild");
    assertNotNull("key should be singleChild",refMeta);
    assertTrue(refMeta.document().equals(SingleChild.class));
    assertEquals("singleChild",refMeta.getFieldName());
    assertEquals("singleChildId", refMeta.getRefIdFieldName());

}
 
开发者ID:wmira,项目名称:nosql-jdbc,代码行数:21,代码来源:DocumentRefTest.java

示例8: mergeNotNullToFirst

import org.boon.core.reflection.BeanUtils; //导入依赖的package包/类
public static <T> T mergeNotNullToFirst(T template, Object... srcs) {
	T dest = BeanUtils.copy(template);
	return mergeNotNullToFirstUnSafe(dest, srcs);
}
 
开发者ID:East196,项目名称:maker,代码行数:5,代码来源:Merger.java

示例9: testCriteriaSQLStrings

import org.boon.core.reflection.BeanUtils; //导入依赖的package包/类
@Test
public void testCriteriaSQLStrings() {

    ColumnCriterion cr = new ColumnCriterion("column","test");

    assertEquals("column",cr.getColumn());
    assertEquals("test",cr.getValue());
    assertEquals("column=?",cr.toSQLString(null));

    FieldCriterion fieldCriterion = new FieldCriterion("id","abc"); //new PsqlJsonFieldCriterion("column","id","abc");

    Criteria criteria = new Criteria();
    criteria.add(cr);
    criteria.add(fieldCriterion);


    Samp document = new Samp();
    Map<String,FieldAccess> fields = BeanUtils.getFieldsFromObject(document);
    assertEquals("column=?" + SQLObjectQuery.SQL_AND_DELIMITER + "data->>'id'=?", SQLObjectQuery.toSQLCriteriaFilter(null,DocumentMeta.fromAnnotation(document.getClass()),criteria,
            PgsqlJsonRepository.CRITERION_TRANSFORMER));

    ColumnExtra extra = new ColumnExtra("col");
    ColumnExtra extraAuto = new ColumnExtra("auto:record_id");

    assertEquals("col",extra.getColumn());
    assertFalse(extra.isAuto());


    assertEquals("record_id", extraAuto.getColumn());
    assertTrue(extraAuto.isAuto());
}
 
开发者ID:wmira,项目名称:nosql-jdbc,代码行数:32,代码来源:CriteriaTest.java


注:本文中的org.boon.core.reflection.BeanUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。