use of com.abubusoft.kripton.processor.bind.model.many2many.M2MEntity in project kripton by xcesco.
the class BindDataSourceSubProcessor method generateEntityName.
/**
* dao or entity can be null
*
* @param dao
* @param entity
* @return
*/
public static String generateEntityName(SQLiteDaoDefinition dao, SQLiteEntity entity) {
String entityName;
if (entity == null) {
M2MEntity m2mEntity = M2MEntity.extractEntityManagedByDAO(dao.getElement());
entityName = m2mEntity.getSimpleName();
} else {
entityName = entity.getSimpleName();
}
return entityName;
}
use of com.abubusoft.kripton.processor.bind.model.many2many.M2MEntity in project kripton by xcesco.
the class BindDataSourceSubProcessor method createSQLDaoDefinition.
/**
* Create DAO definition
*
* @param globalBeanElements
* @param globalDaoElements
* @param generatedDaoParts
* @param daoItem
*/
protected void createSQLDaoDefinition(SQLiteDatabaseSchema schema, final Map<String, TypeElement> globalBeanElements, final Map<String, TypeElement> globalDaoElements, String daoItem) {
Element daoElement = globalDaoElements.get(daoItem);
if (daoElement.getKind() != ElementKind.INTERFACE) {
String msg = String.format("Class %s: only interfaces can be annotated with @%s annotation", daoElement.getSimpleName().toString(), BindDao.class.getSimpleName());
throw (new InvalidKindForAnnotationException(msg));
}
M2MEntity entity = M2MEntity.extractEntityManagedByDAO((TypeElement) daoElement);
// add to current schema generated entities too
for (GeneratedTypeElement genItem : this.generatedEntities) {
if (genItem.getQualifiedName().equals(entity.getQualifiedName())) {
schema.generatedEntities.add(genItem);
}
}
boolean generated = daoElement.getAnnotation(BindGeneratedDao.class) != null;
final SQLiteDaoDefinition currentDaoDefinition = new SQLiteDaoDefinition(schema, daoItem, (TypeElement) daoElement, entity.getClassName().toString(), generated);
// content provider management
BindContentProviderPath daoContentProviderPath = daoElement.getAnnotation(BindContentProviderPath.class);
if (daoContentProviderPath != null) {
currentDaoDefinition.contentProviderEnabled = true;
currentDaoDefinition.contentProviderPath = daoContentProviderPath.path();
currentDaoDefinition.contentProviderTypeName = daoContentProviderPath.typeName();
if (StringUtils.isEmpty(currentDaoDefinition.contentProviderTypeName)) {
Converter<String, String> convert = CaseFormat.UPPER_CAMEL.converterTo(CaseFormat.LOWER_UNDERSCORE);
AssertKripton.assertTrue(currentDaoDefinition.getParent().contentProvider != null, "DAO '%s' has an inconsistent content provider definition, perhaps you forget to use @%s in data source interface?", currentDaoDefinition.getElement().getQualifiedName(), BindContentProvider.class.getSimpleName());
currentDaoDefinition.contentProviderTypeName = currentDaoDefinition.getParent().contentProvider.authority + "." + convert.convert(currentDaoDefinition.getSimpleEntityClassName());
}
}
// set.
if (!globalBeanElements.containsKey(currentDaoDefinition.getEntityClassName()) && !isGeneratedEntity(currentDaoDefinition.getEntityClassName())) {
throw (new InvalidBeanTypeException(currentDaoDefinition));
}
schema.add(currentDaoDefinition);
fillMethods(currentDaoDefinition, daoElement);
/*
* if (generatedDaoPart != null) {
* currentDaoDefinition.addImplementedInterface(TypeUtility.typeName(
* generatedDaoPart)); fillMethods(currentDaoDefinition,
* generatedDaoPart); }
*/
// get @annotation associated to many 2 many relationship
BindDaoMany2Many daoMany2Many = daoElement.getAnnotation(BindDaoMany2Many.class);
// dao definition must have >0 method associated to query
if (currentDaoDefinition.getCollection().size() == 0 && daoMany2Many == null) {
throw (new DaoDefinitionWithoutAnnotatedMethodException(currentDaoDefinition));
}
}
use of com.abubusoft.kripton.processor.bind.model.many2many.M2MEntity in project kripton by xcesco.
the class BindM2MBuilder method generate.
public static Pair<Set<GeneratedTypeElement>, Set<GeneratedTypeElement>> generate(Filer filer, M2MModel model) throws Exception {
entityResult.clear();
daoResult.clear();
BindM2MBuilder visitor = new BindM2MBuilder(filer);
for (M2MEntity item : model.getEntities()) {
visitor.generate(item);
}
Pair<Set<GeneratedTypeElement>, Set<GeneratedTypeElement>> result = new Pair<>();
result.value0 = entityResult;
result.value1 = daoResult;
return result;
}
use of com.abubusoft.kripton.processor.bind.model.many2many.M2MEntity in project kripton by xcesco.
the class BindDataSourceSubProcessor method generateEntityQualifiedName.
public static String generateEntityQualifiedName(SQLiteDaoDefinition dao, SQLiteEntity entity) {
String entityName;
if (entity == null) {
M2MEntity m2mEntity = M2MEntity.extractEntityManagedByDAO(dao.getElement());
entityName = m2mEntity.getQualifiedName();
} else {
entityName = entity.getName().toString();
}
return entityName;
}
use of com.abubusoft.kripton.processor.bind.model.many2many.M2MEntity in project kripton by xcesco.
the class BindMany2ManySubProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
try {
model = new M2MModel();
for (Element daoItem : roundEnv.getElementsAnnotatedWith(BindDaoMany2Many.class)) {
if (daoItem.getKind() != ElementKind.INTERFACE) {
String msg = String.format("%s %s, only interface can be annotated with @%s annotation", daoItem.getKind(), daoItem, BindDaoMany2Many.class.getSimpleName());
throw (new InvalidKindForAnnotationException(msg));
}
M2MEntity entity = M2MEntity.extractEntityManagedByDAO((TypeElement) daoItem);
model.entityAdd(entity);
}
result = BindM2MBuilder.generate(filer, model);
} catch (Exception e) {
String msg = e.getMessage();
error(null, msg);
if (DEBUG_MODE) {
logger.log(Level.SEVERE, msg);
e.printStackTrace();
}
}
return true;
}
Aggregations