Cmobilecom JPA 2.0.RC1 Developer Guide

4. Enhancer

Managed classes must be enhanced after compilation to be managed by EntityManager. The syntax of invoking Enhancer is:
	java -classpath classpath com.cmobilecom.jpa.processor.Enhancer
		-d outputDir -persistenceXmlClasspath persistence_xml_classpath
		class_root_directory1 class_root_directory2 ...
Enhance managed classes after they are compiled.

Java

Example: enhance managed classes in the source set "test".
configurations {
	processor
}
	
dependencies {
	// annotation processor: generate static metamodel
	processor 'com.cmobilecom:cmobilecom-jpa-processor:2.0.RC1'
}

// StaticMetamodelGenerator/Enhancer: classpath for loading META-INF/persistence.xml and 
// referenced orm mapping xml files.
def persistenceXmlClasspath = files('src/test/resources').asPath;
	
compileTestJava {
	// annotation processor: generate static metamodel source code which will be
	// added into sourceSet.java.srcDirs
	options.annotationProcessorPath = configurations.processor
	options.compilerArgs << '-ApersistenceXmlClasspath=' + persistenceXmlClasspath
	
	
	doLast {
		javaexec {
			classpath = configurations.processor
			main 'com.cmobilecom.jpa.processor.Enhancer'
			args "-persistenceXmlClasspath", persistenceXmlClasspath
			args sourceSets.test.output.classesDirs.singleFile.absolutePath
		}
	}
	
}

Android

Example: enhance managed classes in the source set "androidTest".
configurations {
	processor
}
	
dependencies {
	// annotation processor: generate static metamodel
	processor 'com.cmobilecom:cmobilecom-jpa-processor:2.0.RC1'
}
	
dependencies {
	// Android does not have javax.annotation that is requried to compile generated sources,
	// but it is not needed at runtime.
	compileOnly group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
	annotationProcessor configurations.processor
}
	
afterEvaluate {
	// StaticMetamodelGenerator/Enhancer: classpath for loading META-INF/persistence.xml and 
	// referenced orm mapping xml files.
	def persistenceXmlClasspath = files('src/androidTest/resources').asPath;

	compileDebugAndroidTestJavaWithJavac {
		options.compilerArgs << '-ApersistenceXmlClasspath=' + persistenceXmlClasspath

		
		doLast {
			javaexec {
				classpath = configurations.processor
				main 'com.cmobilecom.jpa.processor.Enhancer'
				args "-persistenceXmlClasspath", persistenceXmlClasspath
				args compileDebugAndroidTestJavaWithJavac.destinationDir
			}
		}
		
	}
}
The enhancer transforms classes (not jar) at build time. Do not add cmobilecom-jpa-processor.jar in runtime classpath. Added member (field or method) names have prefix "_jpa_". Keep those names if code is obfuscated (e.g., proguard).
Static Metamodel GenerationSchema GenerationFrames / No Frames