@Override
	public void generateSpecializedPart(SQLiteModelMethod method, TypeSpec.Builder classBuilder, MethodSpec.Builder methodBuilder, Set<JQLProjection> fieldList, boolean mapFields) {
		SQLiteEntity entity = method.getEntity();

		// get return type (in this case is always a list)
		ClassName returnRawListClazzName = ClassName.get(List.class);

		TypeName entityClass = typeName(entity.getElement());

		methodBuilder.addCode("\n");
		methodBuilder.addStatement("$T<$T> resultList=new $T<$T>(_cursor.getCount())", List.class, entityClass, ArrayList.class, entityClass);

		methodBuilder.addStatement("$T resultBean=null", entityClass);
		// immutable management
		if (entity.isImmutablePojo()) {
			methodBuilder.addCode("\n");
			methodBuilder.addComment("initialize temporary variable for immutable POJO");
			ImmutableUtility.generateImmutableVariableInit(entity, methodBuilder);
		}

		methodBuilder.addCode("\n");
		methodBuilder.beginControlFlow("if (_cursor.moveToFirst())");

		// generate index from columns
		methodBuilder.addCode("\n");
		{
			int i = 0;
			for (JQLProjection a : fieldList) {
				SQLProperty item = a.property;

				methodBuilder.addStatement("int index$L=_cursor.getColumnIndex($S)", (i++), item.columnName);
				if (item.hasTypeAdapter()) {
					methodBuilder.addStatement("$T $LAdapter=$T.getAdapter($T.class)", item.typeAdapter.getAdapterTypeName(), item.getName(), SQLTypeAdapterUtils.class,
							item.typeAdapter.getAdapterTypeName());
				}
			}
		}
		methodBuilder.addCode("\n");

		methodBuilder.beginControlFlow("do\n");

		// immutable management
		if (entity.isImmutablePojo()) {
			methodBuilder.addComment("reset temporary variable for immutable POJO");
			ImmutableUtility.generateImmutableVariableReset(entity, methodBuilder);
		} else {
			methodBuilder.addCode("resultBean=new $T();\n\n", entityClass);
		}

		// generate mapping
		int i = 0;
		for (JQLProjection a : fieldList) {
			SQLProperty item = a.property;

			if (item.isNullable()) {
				methodBuilder.addCode("if (!_cursor.isNull(index$L)) { ", i);
			}
			SQLTransformer.cursor2Java(methodBuilder, typeName(entity.getElement()), item, "resultBean", "_cursor", "index" + i + "");
			methodBuilder.addCode(";");
			if (item.isNullable()) {
				methodBuilder.addCode(" }");
			}
			methodBuilder.addCode("\n");

			i++;
		}
		methodBuilder.addCode("\n");

		// immutable management
		if (entity.isImmutablePojo()) {
			methodBuilder.addComment("define immutable POJO");
			ImmutableUtility.generateImmutableEntityCreation(entity, methodBuilder, "resultBean", false);
		}

		methodBuilder.addCode("resultList.add(resultBean);\n");
		methodBuilder.endControlFlow("while (_cursor.moveToNext())");

		methodBuilder.endControlFlow();

		methodBuilder.addCode("\n");

		// return list or immutable list
		if (entity.isImmutablePojo()) {
			methodBuilder.addCode("return ");
			ImmutableUtility.generateImmutableCollectionIfPossible(entity, methodBuilder, "resultList", ParameterizedTypeName.get(returnRawListClazzName, entityClass));
			methodBuilder.addCode(";\n");
		} else {
			methodBuilder.addCode("return resultList;\n");
		}

		methodBuilder.endControlFlow();
	}
@ Override public void generateSpecializedPart ( SQLiteModelMethod method , TypeSpec . Builder classBuilder , MethodSpec . Builder methodBuilder , Set < JQLProjection > fieldList , boolean mapFields ) { SQLiteEntity entity = method . getEntity ( ) ; ClassName returnRawListClazzName = ClassName . get ( List . class ) ; TypeName entityClass = typeName ( entity . getElement ( ) ) ; methodBuilder . addCode ( "\n" ) ; methodBuilder . addStatement ( "$T<$T> resultList=new $T<$T>(_cursor.getCount())" , List . class , entityClass , ArrayList . class , entityClass ) ; methodBuilder . addStatement ( "$T resultBean=null" , entityClass ) ; if ( entity . isImmutablePojo ( ) ) { methodBuilder . addCode ( "\n" ) ; methodBuilder . addComment ( "initialize temporary variable for immutable POJO" ) ; ImmutableUtility . generateImmutableVariableInit ( entity , methodBuilder ) ; } methodBuilder . addCode ( "\n" ) ; methodBuilder . beginControlFlow ( "if (_cursor.moveToFirst())" ) ; methodBuilder . addCode ( "\n" ) ; { int i = 0 ; for ( JQLProjection a : fieldList ) { SQLProperty item = a . property ; methodBuilder . addStatement ( "int index$L=_cursor.getColumnIndex($S)" , ( i ++ ) , item . columnName ) ; if ( item . hasTypeAdapter ( ) ) { methodBuilder . addStatement ( "$T $LAdapter=$T.getAdapter($T.class)" , item . typeAdapter . getAdapterTypeName ( ) , item . getName ( ) , SQLTypeAdapterUtils . class , item . typeAdapter . getAdapterTypeName ( ) ) ; } } } methodBuilder . addCode ( "\n" ) ; methodBuilder . beginControlFlow ( "do\n" ) ; if ( entity . isImmutablePojo ( ) ) { methodBuilder . addComment ( "reset temporary variable for immutable POJO" ) ; ImmutableUtility . generateImmutableVariableReset ( entity , methodBuilder ) ; } else { methodBuilder . addCode ( "resultBean=new $T();\n\n" , entityClass ) ; } int i = 0 ; for ( JQLProjection a : fieldList ) { SQLProperty item = a . property ; if ( item . isNullable ( ) ) { methodBuilder . addCode ( "if (!_cursor.isNull(index$L)) { " , i ) ; } SQLTransformer . cursor2Java ( methodBuilder , typeName ( entity . getElement ( ) ) , item , "resultBean" , "_cursor" , "index" + i + "" ) ; methodBuilder . addCode ( ";" ) ; if ( item . isNullable ( ) ) { methodBuilder . addCode ( " }" ) ; } methodBuilder . addCode ( "\n" ) ; i ++ ; } methodBuilder . addCode ( "\n" ) ; if ( entity . isImmutablePojo ( ) ) { methodBuilder . addComment ( "define immutable POJO" ) ; ImmutableUtility . generateImmutableEntityCreation ( entity , methodBuilder , "resultBean" , false ) ; } methodBuilder . addCode ( "resultList.add(resultBean);\n" ) ; methodBuilder . endControlFlow ( "while (_cursor.moveToNext())" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . addCode ( "\n" ) ; if ( entity . isImmutablePojo ( ) ) { methodBuilder . addCode ( "return " ) ; ImmutableUtility . generateImmutableCollectionIfPossible ( entity , methodBuilder , "resultList" , ParameterizedTypeName . get ( returnRawListClazzName , entityClass ) ) ; methodBuilder . addCode ( ";\n" ) ; } else { methodBuilder . addCode ( "return resultList;\n" ) ; } methodBuilder . endControlFlow ( ) ; }
/*
(non-Javadoc)

@see com.abubusoft.kripton.processor.sqlite.AbstractSelectCodeGenerator#
generateSpecializedPart(com.abubusoft.kripton.processor.sqlite.model.
SQLiteModelMethod, com.squareup.javapoet.TypeSpec.Builder,
com.squareup.javapoet.MethodSpec.Builder, java.util.Set, boolean)