Java Code Examples for org.apache.commons.lang3.reflect.FieldUtils#writeDeclaredField()

The following examples show how to use org.apache.commons.lang3.reflect.FieldUtils#writeDeclaredField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommentsWavePlugin.java    From dolphin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {
  try {
    // use reflect to fix the root comment
    Document document = (Document) FieldUtils.readDeclaredField(sqlMap, "document", true);
    ExtendedDocument extendedDocument = new ExtendedDocument(document);
    FieldUtils.writeDeclaredField(sqlMap, "document", extendedDocument, true);
    if (context.getCommentGenerator() instanceof CommentGenerator) {
      CommentGenerator cg = (CommentGenerator) context.getCommentGenerator();
      cg.addSqlMapFileComment(extendedDocument);
    }
  } catch (IllegalAccessException e) {
    e.printStackTrace();
  }
  return true;
}
 
Example 2
Source File: PostgisGeoPlugin.java    From dolphin with Apache License 2.0 6 votes vote down vote up
protected void checkAndReplaceInput(List<IntrospectedColumn> columns, TextElement te) {
  String sql = te.getContent();
  for(IntrospectedColumn column : columns){
  	if(column.getFullyQualifiedJavaType().getShortName().equals("Geometry")){
  		String paramStr = MyBatis3FormattingUtilities.getParameterClause(column);
  		sql = StringUtils.replace(sql, paramStr, "ST_GeomFromText(" + paramStr + ","+srid+")"); //replace no prefix geo relate column
  		paramStr = MyBatis3FormattingUtilities.getParameterClause(column, "record.");
  		sql = StringUtils.replace(sql, paramStr, "ST_GeomFromText(" + paramStr + ","+srid+")"); //replace mbg generate prefix geo relate column
  		paramStr = MyBatis3FormattingUtilities.getParameterClause(column, "item.");
  		sql = StringUtils.replace(sql, paramStr, "ST_GeomFromText(" + paramStr + ","+srid+")"); //replace mbg batch plugin generate prefix geo relate column				
//				System.out.println();
//				System.out.println(sql);
  	}
  }
  try {
    FieldUtils.writeDeclaredField(te, "content", sql, true);
  } catch (IllegalAccessException e) {
    e.printStackTrace();
  }
}
 
Example 3
Source File: PostgisGeoPlugin.java    From dolphin with Apache License 2.0 6 votes vote down vote up
protected void checkAndReplaceOutput(List<IntrospectedColumn> columns, TextElement te) {
    String sql = te.getContent();
		for(IntrospectedColumn column : columns){
			if(column.getFullyQualifiedJavaType().getShortName().equals("Geometry")){
				String columnStr = null;
				if(column.isColumnNameDelimited()){
					columnStr = "\""+column.getActualColumnName()+"\"";
				}else{
					columnStr = column.getActualColumnName();
				}
				sql = StringUtils.replaceOnce(sql, columnStr, "ST_AsText("+columnStr+") as " + columnStr);
				//sql = sql.replace(column.getActualColumnName(), "ST_AsText("+column.getActualColumnName()+")");
//				System.out.println();
//				System.out.println(sql);
			}
		}
    try {
      FieldUtils.writeDeclaredField(te, "content", sql, true);
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }		
  }
 
Example 4
Source File: FieldUtilsUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void givenFieldUtilsClass_whenCalledwriteDeclaredField_thenCorrect() throws IllegalAccessException {
    FieldUtils.writeDeclaredField(user, "name", "Julie", true);
    assertThat(FieldUtils.readField(user, "name", true)).isEqualTo("Julie");    
}
 
Example 5
Source File: EntityTest.java    From usergrid with Apache License 2.0 2 votes vote down vote up
@Test
public void testPutAndGet() throws IllegalAccessException {


    final UUID uuid = UUIDGenerator.newTimeUUID();
    final UUID version = UUIDGenerator.newTimeUUID();
    final String type = "test";
    final Id simpleId = new SimpleId( uuid, type );


    Entity entity = new Entity(simpleId );

    FieldUtils.writeDeclaredField( entity, "version", version, true );
    assertEquals( uuid, entity.getId().getUuid() );
    assertEquals( type, entity.getId().getType() );
    assertEquals( version, entity.getVersion());


    BooleanField boolField = new BooleanField( "boolean", false );
    DoubleField doubleField = new DoubleField( "double", 1d );
    IntegerField intField = new IntegerField( "long", 1 );
    LongField longField = new LongField( "int", 1l );
    StringField stringField = new StringField( "name", "test" );
    UUIDField uuidField = new UUIDField( "uuid", UUIDGenerator.newTimeUUID() );
    NullField nullField = new NullField("null");

    entity.setField( boolField );
    entity.setField( doubleField );
    entity.setField( intField );
    entity.setField( longField );
    entity.setField( stringField );
    entity.setField( uuidField );
    entity.setField( nullField );

    Field<Boolean> boolFieldReturned = entity.getField( boolField.getName() );

    assertSame( boolField, boolFieldReturned );

    Field<Double> doubleFieldReturned = entity.getField( doubleField.getName() );

    assertSame( doubleField, doubleFieldReturned );

    Field<Integer> intFieldReturned = entity.getField( intField.getName() );

    assertSame( intField, intFieldReturned );

    Field<Long> longFieldReturned = entity.getField( longField.getName() );

    assertSame( longField, longFieldReturned );

    Field<String> stringFieldReturned = entity.getField( stringField.getName() );

    assertSame( stringField, stringFieldReturned );

    Field<UUID> uuidFieldReturned = entity.getField( uuidField.getName() );

    assertSame( uuidField, uuidFieldReturned );

    Field<Object> nullFieldReturned = entity.getField( nullField.getName());

    assertSame( nullField, nullFieldReturned);


    Set<Field> results = new HashSet<Field>();
    results.addAll( entity.getFields() );


    assertTrue( results.contains( boolField ) );
    assertTrue( results.contains( doubleField ) );
    assertTrue( results.contains( intField ) );
    assertTrue( results.contains( longField ) );
    assertTrue( results.contains( stringField ) );
    assertTrue( results.contains( uuidField ) );
    assertTrue( results.contains( nullField ) );

    assertEquals( 7, results.size() );


    assertEquals( simpleId, entity.getId() );
    assertEquals( version, entity.getVersion() );
}