use of com.abubusoft.kripton.processor.sqlite.model.SQLiteDatabaseSchema in project kripton by xcesco.
the class BindDataSourceSubProcessor method processSecondRound.
public boolean processSecondRound(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (SQLiteDatabaseSchema schema : schemas) {
// definition
for (String daoName : schema.getDaoNameSet()) {
// check dao into bean definition
if (globalDaoGenerated.contains(daoName)) {
createSQLEntityFromDao(schema, schema.getElement(), daoName);
createSQLDaoDefinition(schema, globalBeanElements, globalDaoElements, daoName);
}
}
// end foreach bean
}
return true;
}
use of com.abubusoft.kripton.processor.sqlite.model.SQLiteDatabaseSchema in project kripton by xcesco.
the class BindDataSourceSubProcessor method createDataSource.
/**
* @param databaseSchema
* @return databaseSchema
*/
protected SQLiteDatabaseSchema createDataSource(Element databaseSchema) {
if (databaseSchema.getKind() != ElementKind.INTERFACE) {
String msg = String.format("Class %s: only interfaces can be annotated with @%s annotation", databaseSchema.getSimpleName().toString(), BindDataSource.class.getSimpleName());
throw (new InvalidKindForAnnotationException(msg));
}
if (!databaseSchema.getSimpleName().toString().endsWith(BindDataSourceBuilder.SUFFIX)) {
String msg = String.format("Interface %s marked with @%s annotation must have a typeName with suffix \"" + BindDataSourceBuilder.SUFFIX + "\" to be used with @BindDataSource", databaseSchema.getSimpleName().toString(), BindDataSource.class.getSimpleName());
throw (new InvalidNameException(msg));
}
// go ahead to dataSource analysis
// ASSERT: daoElement and beanElement is element for dao and bean
// associated
String schemaFileName = AnnotationUtility.extractAsString(databaseSchema, BindDataSource.class, AnnotationAttributeType.FILENAME);
int schemaVersion = AnnotationUtility.extractAsInt(databaseSchema, BindDataSource.class, AnnotationAttributeType.VERSION);
boolean generateLog = AnnotationUtility.extractAsBoolean(databaseSchema, BindDataSource.class, AnnotationAttributeType.GENERATE_LOG);
boolean generateSchema = AnnotationUtility.extractAsBoolean(databaseSchema, BindDataSource.class, AnnotationAttributeType.GENERATE_SCHEMA);
boolean generateAsyncTask = AnnotationUtility.extractAsBoolean(databaseSchema, BindDataSource.class, AnnotationAttributeType.GENERATE_ASYNC_TASK);
boolean generateCursorWrapper = AnnotationUtility.extractAsBoolean(databaseSchema, BindDataSource.class, AnnotationAttributeType.GENERATE_CURSOR_WRAPPER);
boolean generateRx = AnnotationUtility.extractAsBoolean(databaseSchema, BindDataSource.class, AnnotationAttributeType.GENERATE_RX);
// get all dao used within SQLDatabaseSchema annotation
List<String> daoIntoDataSource = AnnotationUtility.extractAsClassNameArray(elementUtils, databaseSchema, BindDataSource.class, AnnotationAttributeType.DAO_SET);
String configCursorFactory = NoCursorFactory.class.getName();
String configDatabaseErrorHandler = NoDatabaseErrorHandler.class.getName();
String configDatabaseLifecycleHandler = NoDatabaseLifecycleHandler.class.getName();
boolean configInMemory = false;
boolean configLogEnabled = true;
String configPopulatorClass = NoPopulator.class.getName();
// manage for annotated data-source options
BindDataSourceOptions dataSourceOptionsAnnotation = databaseSchema.getAnnotation(BindDataSourceOptions.class);
if (dataSourceOptionsAnnotation != null) {
configInMemory = AnnotationUtility.extractAsBoolean(databaseSchema, BindDataSourceOptions.class, AnnotationAttributeType.IN_MEMORY);
configLogEnabled = AnnotationUtility.extractAsBoolean(databaseSchema, BindDataSourceOptions.class, AnnotationAttributeType.LOG_ENABLED);
configPopulatorClass = AnnotationUtility.extractAsClassName(databaseSchema, BindDataSourceOptions.class, AnnotationAttributeType.POPULATOR);
configCursorFactory = AnnotationUtility.extractAsClassName(databaseSchema, BindDataSourceOptions.class, AnnotationAttributeType.CURSOR_FACTORY);
configDatabaseLifecycleHandler = AnnotationUtility.extractAsClassName(databaseSchema, BindDataSourceOptions.class, AnnotationAttributeType.DATABASE_LIFECYCLE_HANDLER);
}
SQLiteDatabaseSchema schema = new SQLiteDatabaseSchema((TypeElement) databaseSchema, schemaFileName, schemaVersion, generateSchema, generateLog, generateAsyncTask, generateCursorWrapper, generateRx, daoIntoDataSource, configCursorFactory, configDatabaseErrorHandler, configDatabaseLifecycleHandler, configInMemory, configLogEnabled, configPopulatorClass);
// manage for content provider generation
BindContentProvider contentProviderAnnotation = databaseSchema.getAnnotation(BindContentProvider.class);
if (contentProviderAnnotation != null) {
schema.generateContentProvider = true;
schema.contentProvider = new SQLiteModelContentProvider();
schema.contentProvider.authority = contentProviderAnnotation.authority();
} else {
schema.generateContentProvider = false;
}
return schema;
}
use of com.abubusoft.kripton.processor.sqlite.model.SQLiteDatabaseSchema in project kripton by xcesco.
the class BindDataSourceSubProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element dataSource : dataSets) {
SQLiteDatabaseSchema currentSchema = createDataSource(dataSource);
// definition
for (String daoName : currentSchema.getDaoNameSet()) {
// check dao into bean definition
createSQLEntityFromDao(currentSchema, dataSource, daoName);
}
// Get all generated dao definitions
for (String generatedDaoItem : currentSchema.getDaoNameSet()) {
createSQLDaoDefinition(currentSchema, globalBeanElements, globalDaoElements, generatedDaoItem);
}
analyzeForeignKey(currentSchema);
String msg;
if (currentSchema.getCollection().size() == 0) {
msg = String.format("No DAO definition with @%s annotation was found for class %s with @%s annotation", BindDao.class.getSimpleName(), currentSchema.getElement().getSimpleName().toString(), BindDataSource.class.getSimpleName());
// info(msg);
error(null, msg);
return true;
}
// for each dao definition, we define its uid
int uid = 0;
for (SQLiteDaoDefinition daoDefinition : currentSchema.getCollection()) {
String daoFieldName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, daoDefinition.getName()) + "_UID";
daoDefinition.daoUidName = daoFieldName;
daoDefinition.daoUidValue = uid;
uid++;
}
schemas.add(currentSchema);
}
return true;
}
use of com.abubusoft.kripton.processor.sqlite.model.SQLiteDatabaseSchema in project kripton by xcesco.
the class BindDataSourceSubProcessor method generatedClasses.
/**
* Build classes
*
* @param roundEnv
*
* @throws Exception
*/
protected void generatedClasses(RoundEnvironment roundEnv) throws Exception {
for (SQLiteDatabaseSchema currentSchema : schemas) {
BindTableGenerator.generate(elementUtils, filer, currentSchema, currentSchema.generatedEntities);
BindDaoBuilder.generate(elementUtils, filer, currentSchema);
if (currentSchema.generateCursor)
BindCursorBuilder.generate(elementUtils, filer, currentSchema);
if (currentSchema.generateAsyncTask)
BindAsyncTaskBuilder.generate(elementUtils, filer, currentSchema);
BindDataSourceBuilder.generate(elementUtils, filer, currentSchema);
if (currentSchema.generateContentProvider) {
BindContentProviderBuilder.generate(elementUtils, filer, currentSchema);
}
}
}
Aggregations