private void visit(SQLiteDatabaseSchema schema, GeneratedTypeElement entity) throws Exception {
		int indexCounter = 0;

		// generate the class name that represents the table
		String classTableName = getTableClassName(entity.getSimpleName());

		PackageElement pkg = elementUtils.getPackageElement(entity.packageName);
		String packageName = pkg.isUnnamed() ? null : pkg.getQualifiedName().toString();

		AnnotationProcessorUtilis.infoOnGeneratedClasses(BindDataSource.class, packageName, classTableName);
		classBuilder = TypeSpec.classBuilder(classTableName).addModifiers(Modifier.PUBLIC)
				.addSuperinterface(SQLiteTable.class);

		BindTypeContext context = new BindTypeContext(classBuilder, TypeUtility.typeName(packageName, classTableName),
				Modifier.STATIC, Modifier.PRIVATE);

		// javadoc for class
		classBuilder.addJavadoc("<p>");
		classBuilder.addJavadoc("\nEntity <code>$L</code> is associated to table <code>$L</code>\n",
				entity.getSimpleName(), entity.getTableName());
		classBuilder.addJavadoc("This class represents table associated to entity.\n");
		classBuilder.addJavadoc("</p>\n");
		JavadocUtility.generateJavadocGeneratedBy(classBuilder);
		classBuilder.addJavadoc(" @see $T\n", TypeUtility.className(entity.getName()));

		{
			// @formatter:off
			// table_name
			FieldSpec fieldSpec = FieldSpec
					.builder(String.class, "TABLE_NAME", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
					.initializer("\"$L\"", entity.getTableName())
					.addJavadoc("Costant represents typeName of table $L\n", entity.getTableName()).build();
			classBuilder.addField(fieldSpec);
			// @formatter:on
		}

		StringBuilder bufferTable = new StringBuilder();
		StringBuilder bufferForeignKey = new StringBuilder();
		// shared between create table and drop table
		StringBuilder bufferIndexesCreate = new StringBuilder();
		StringBuilder bufferDropTable = new StringBuilder();
		StringBuilder bufferIndexesDrop = new StringBuilder();

		bufferTable.append("CREATE TABLE " + entity.getTableName());
		// define column typeName set

		String separator = "";
		bufferTable.append(" (");
		
		List<String> uniqueConstraintColumn=new ArrayList<>();

		// for each column, that need to be persisted on table
		for (SQLProperty item : entity.getCollection()) {
			bufferTable.append(separator);
			bufferTable.append(item.columnName);

			// every column is a long
			if (item.getPropertyType() == null) {
				bufferTable.append(" " + SQLTransformer.lookup(TypeName.LONG).getColumnTypeAsString());
			} else {
				bufferTable.append(
						" " + SQLTransformer.lookup(item.getPropertyType().getTypeName()).getColumnTypeAsString());
			}

			switch (item.columnType) {
			case PRIMARY_KEY:
				bufferTable.append(" PRIMARY KEY AUTOINCREMENT NOT NULL");
				break;
			case PRIMARY_KEY_UNMANGED:
				bufferTable.append(" PRIMARY KEY NOT NULL");
				break;
			case UNIQUE:
				bufferTable.append(" UNIQUE");
				break;
			case INDEXED:
				bufferIndexesCreate.append(String.format(" CREATE INDEX idx_%s_%s ON %s(%s);", entity.getTableName(),
						item.columnName, entity.getTableName(), item.columnName));
				bufferIndexesDrop.append(
						String.format(" DROP INDEX IF EXISTS idx_%s_%s;", entity.getTableName(), item.columnName));
				
				uniqueConstraintColumn.add(item.columnName);
				
				break;
			case STANDARD:
				break;
			}

			boolean nullable = item.isNullable();

			// if it is not primary key and it is not nullable, then add not
			// null
			if (!nullable && !(item.columnType == ColumnType.PRIMARY_KEY
					|| item.columnType == ColumnType.PRIMARY_KEY_UNMANGED)) {
				bufferTable.append(" NOT NULL");
			}

			// foreign key
			String foreignClassName = item.foreignParentClassName;
			if (item.isForeignKey()) {
				SQLiteEntity reference = model.getEntity(foreignClassName);

				if (reference == null) {
					// check if we have a DAO associated into DataSource
					// definition
					boolean found = false;
					for (SQLiteDaoDefinition daoDefinition : schema.getCollection()) {
						if (daoDefinition.getEntityClassName().equals(foreignClassName)) {
							found = true;
						}
					}

					if (!found) {
						throw new NoDaoElementFound(schema, TypeUtility.className(foreignClassName));
					} else {
						throw new InvalidBeanTypeException(item, foreignClassName);
					}
				}

				bufferForeignKey.append(", FOREIGN KEY(" + item.columnName + ") REFERENCES " + reference.getTableName()
						+ "(" + reference.getPrimaryKey().columnName + ")");

				if (item.onDeleteAction != ForeignKeyAction.NO_ACTION) {
					bufferForeignKey.append(" ON DELETE " + item.onDeleteAction.toString().replaceAll("_", " "));
				}

				if (item.onUpdateAction != ForeignKeyAction.NO_ACTION) {
					bufferForeignKey.append(" ON UPDATE " + item.onUpdateAction.toString().replaceAll("_", " "));
				}

				// INSERT as dependency only if reference is another entity.
				// Same entity can not be own dependency.
				if (!entity.getClassName().equals(TypeUtility.typeName(reference.getElement()))) {
					entity.referedEntities.add(reference);
				}

			}

			separator = ", ";
		}

		// add foreign key
		bufferTable.append(bufferForeignKey.toString());

		// add contrants unique
		bufferTable.append(String.format(", UNIQUE (%s)", StringUtils.join(uniqueConstraintColumn, ", ")));

		bufferTable.append(");");

		// add indexes creation one table
		if (bufferIndexesCreate.length() > 0) {
			bufferTable.append(bufferIndexesCreate.toString());
		}

		// add single column indexes (NOT UNIQUE)
		{
			Triple<String, String, String> multiIndexes = buildIndexes(entity, false, indexCounter);
			if (!StringUtils.isEmpty(multiIndexes.value0)) {
				bufferTable.append(multiIndexes.value0 + ";");
				bufferIndexesDrop.append(multiIndexes.value1 + ";");
			}
		}

		{
			// create table SQL
			// @formatter:off
			FieldSpec.Builder fieldSpec = FieldSpec.builder(String.class, "CREATE_TABLE_SQL")
					.addModifiers(Modifier.STATIC, Modifier.FINAL, Modifier.PUBLIC);
			// @formatter:on

			// @formatter:off
			fieldSpec.addJavadoc("<p>\nDDL to create table $L\n</p>\n", entity.getTableName());
			fieldSpec.addJavadoc("\n<pre>$L</pre>\n", bufferTable.toString());
			// @formatter:on

			classBuilder.addField(fieldSpec.initializer("$S", bufferTable.toString()).build());
		}

		// drop table SQL
		// index does not need to be dropped, they are automatically detroyed
		// with tables
		if (bufferIndexesDrop.length() > 0) {
			bufferDropTable.append(bufferIndexesDrop.toString());
		}

		bufferDropTable.append("DROP TABLE IF EXISTS " + entity.getTableName() + ";");

		{
			// @formatter:off
			FieldSpec fieldSpec = FieldSpec.builder(String.class, "DROP_TABLE_SQL")
					.addModifiers(Modifier.STATIC, Modifier.FINAL, Modifier.PUBLIC)
					.initializer("$S", bufferDropTable.toString())
					.addJavadoc("<p>\nDDL to drop table $L\n</p>\n", entity.getTableName())
					.addJavadoc("\n<pre>$L</pre>\n", bufferDropTable.toString()).build();
			// @formatter:on
			classBuilder.addField(fieldSpec);
		}

		// define column typeName set
		for (ModelProperty item : entity.getCollection()) {
			item.accept(this);
		}

		ManagedPropertyPersistenceHelper.generateFieldPersistance(context, entity.getCollection(), PersistType.BYTE,
				true, Modifier.STATIC, Modifier.PUBLIC);

		model.sqlForCreate.add(bufferTable.toString());
		model.sqlForDrop.add(bufferDropTable.toString());

		generateColumnsArray(entity);

		TypeSpec typeSpec = classBuilder.build();
		JavaWriterHelper.writeJava2File(filer, packageName, typeSpec);

	}
private void visit ( SQLiteDatabaseSchema schema , GeneratedTypeElement entity ) throws Exception { int indexCounter = 0 ; String classTableName = getTableClassName ( entity . getSimpleName ( ) ) ; PackageElement pkg = elementUtils . getPackageElement ( entity . packageName ) ; String packageName = pkg . isUnnamed ( ) ? null : pkg . getQualifiedName ( ) . toString ( ) ; AnnotationProcessorUtilis . infoOnGeneratedClasses ( BindDataSource . class , packageName , classTableName ) ; classBuilder = TypeSpec . classBuilder ( classTableName ) . addModifiers ( Modifier . PUBLIC ) . addSuperinterface ( SQLiteTable . class ) ; BindTypeContext context = new BindTypeContext ( classBuilder , TypeUtility . typeName ( packageName , classTableName ) , Modifier . STATIC , Modifier . PRIVATE ) ; classBuilder . addJavadoc ( "<p>" ) ; classBuilder . addJavadoc ( "\nEntity <code>$L</code> is associated to table <code>$L</code>\n" , entity . getSimpleName ( ) , entity . getTableName ( ) ) ; classBuilder . addJavadoc ( "This class represents table associated to entity.\n" ) ; classBuilder . addJavadoc ( "</p>\n" ) ; JavadocUtility . generateJavadocGeneratedBy ( classBuilder ) ; classBuilder . addJavadoc ( " @see $T\n" , TypeUtility . className ( entity . getName ( ) ) ) ; { FieldSpec fieldSpec = FieldSpec . builder ( String . class , "TABLE_NAME" , Modifier . PUBLIC , Modifier . STATIC , Modifier . FINAL ) . initializer ( "\"$L\"" , entity . getTableName ( ) ) . addJavadoc ( "Costant represents typeName of table $L\n" , entity . getTableName ( ) ) . build ( ) ; classBuilder . addField ( fieldSpec ) ; } StringBuilder bufferTable = new StringBuilder ( ) ; StringBuilder bufferForeignKey = new StringBuilder ( ) ; StringBuilder bufferIndexesCreate = new StringBuilder ( ) ; StringBuilder bufferDropTable = new StringBuilder ( ) ; StringBuilder bufferIndexesDrop = new StringBuilder ( ) ; bufferTable . append ( "CREATE TABLE " + entity . getTableName ( ) ) ; String separator = "" ; bufferTable . append ( " (" ) ; List < String > uniqueConstraintColumn = new ArrayList < > ( ) ; for ( SQLProperty item : entity . getCollection ( ) ) { bufferTable . append ( separator ) ; bufferTable . append ( item . columnName ) ; if ( item . getPropertyType ( ) == null ) { bufferTable . append ( " " + SQLTransformer . lookup ( TypeName . LONG ) . getColumnTypeAsString ( ) ) ; } else { bufferTable . append ( " " + SQLTransformer . lookup ( item . getPropertyType ( ) . getTypeName ( ) ) . getColumnTypeAsString ( ) ) ; } switch ( item . columnType ) { case PRIMARY_KEY : bufferTable . append ( " PRIMARY KEY AUTOINCREMENT NOT NULL" ) ; break ; case PRIMARY_KEY_UNMANGED : bufferTable . append ( " PRIMARY KEY NOT NULL" ) ; break ; case UNIQUE : bufferTable . append ( " UNIQUE" ) ; break ; case INDEXED : bufferIndexesCreate . append ( String . format ( " CREATE INDEX idx_%s_%s ON %s(%s);" , entity . getTableName ( ) , item . columnName , entity . getTableName ( ) , item . columnName ) ) ; bufferIndexesDrop . append ( String . format ( " DROP INDEX IF EXISTS idx_%s_%s;" , entity . getTableName ( ) , item . columnName ) ) ; uniqueConstraintColumn . add ( item . columnName ) ; break ; case STANDARD : break ; } boolean nullable = item . isNullable ( ) ; if ( ! nullable && ! ( item . columnType == ColumnType . PRIMARY_KEY || item . columnType == ColumnType . PRIMARY_KEY_UNMANGED ) ) { bufferTable . append ( " NOT NULL" ) ; } String foreignClassName = item . foreignParentClassName ; if ( item . isForeignKey ( ) ) { SQLiteEntity reference = model . getEntity ( foreignClassName ) ; if ( reference == null ) { boolean found = false ; for ( SQLiteDaoDefinition daoDefinition : schema . getCollection ( ) ) { if ( daoDefinition . getEntityClassName ( ) . equals ( foreignClassName ) ) { found = true ; } } if ( ! found ) { throw new NoDaoElementFound ( schema , TypeUtility . className ( foreignClassName ) ) ; } else { throw new InvalidBeanTypeException ( item , foreignClassName ) ; } } bufferForeignKey . append ( ", FOREIGN KEY(" + item . columnName + ") REFERENCES " + reference . getTableName ( ) + "(" + reference . getPrimaryKey ( ) . columnName + ")" ) ; if ( item . onDeleteAction != ForeignKeyAction . NO_ACTION ) { bufferForeignKey . append ( " ON DELETE " + item . onDeleteAction . toString ( ) . replaceAll ( "_" , " " ) ) ; } if ( item . onUpdateAction != ForeignKeyAction . NO_ACTION ) { bufferForeignKey . append ( " ON UPDATE " + item . onUpdateAction . toString ( ) . replaceAll ( "_" , " " ) ) ; } if ( ! entity . getClassName ( ) . equals ( TypeUtility . typeName ( reference . getElement ( ) ) ) ) { entity . referedEntities . add ( reference ) ; } } separator = ", " ; } bufferTable . append ( bufferForeignKey . toString ( ) ) ; bufferTable . append ( String . format ( ", UNIQUE (%s)" , StringUtils . join ( uniqueConstraintColumn , ", " ) ) ) ; bufferTable . append ( ");" ) ; if ( bufferIndexesCreate . length ( ) > 0 ) { bufferTable . append ( bufferIndexesCreate . toString ( ) ) ; } { Triple < String , String , String > multiIndexes = buildIndexes ( entity , false , indexCounter ) ; if ( ! StringUtils . isEmpty ( multiIndexes . value0 ) ) { bufferTable . append ( multiIndexes . value0 + ";" ) ; bufferIndexesDrop . append ( multiIndexes . value1 + ";" ) ; } } { FieldSpec . Builder fieldSpec = FieldSpec . builder ( String . class , "CREATE_TABLE_SQL" ) . addModifiers ( Modifier . STATIC , Modifier . FINAL , Modifier . PUBLIC ) ; fieldSpec . addJavadoc ( "<p>\nDDL to create table $L\n</p>\n" , entity . getTableName ( ) ) ; fieldSpec . addJavadoc ( "\n<pre>$L</pre>\n" , bufferTable . toString ( ) ) ; classBuilder . addField ( fieldSpec . initializer ( "$S" , bufferTable . toString ( ) ) . build ( ) ) ; } if ( bufferIndexesDrop . length ( ) > 0 ) { bufferDropTable . append ( bufferIndexesDrop . toString ( ) ) ; } bufferDropTable . append ( "DROP TABLE IF EXISTS " + entity . getTableName ( ) + ";" ) ; { FieldSpec fieldSpec = FieldSpec . builder ( String . class , "DROP_TABLE_SQL" ) . addModifiers ( Modifier . STATIC , Modifier . FINAL , Modifier . PUBLIC ) . initializer ( "$S" , bufferDropTable . toString ( ) ) . addJavadoc ( "<p>\nDDL to drop table $L\n</p>\n" , entity . getTableName ( ) ) . addJavadoc ( "\n<pre>$L</pre>\n" , bufferDropTable . toString ( ) ) . build ( ) ; classBuilder . addField ( fieldSpec ) ; } for ( ModelProperty item : entity . getCollection ( ) ) { item . accept ( this ) ; } ManagedPropertyPersistenceHelper . generateFieldPersistance ( context , entity . getCollection ( ) , PersistType . BYTE , true , Modifier . STATIC , Modifier . PUBLIC ) ; model . sqlForCreate . add ( bufferTable . toString ( ) ) ; model . sqlForDrop . add ( bufferDropTable . toString ( ) ) ; generateColumnsArray ( entity ) ; TypeSpec typeSpec = classBuilder . build ( ) ; JavaWriterHelper . writeJava2File ( filer , packageName , typeSpec ) ; }
Visit.

@param schema
the schema
@param entity
the entity
@throws Exception
the exception