use of org.datanucleus.metadata.annotations.AnnotationObject in project datanucleus-api-jdo by datanucleus.
the class JDOAnnotationReader method processNamedQueries.
/**
* Convenience method to process @Queries, @Query.
* @param cmd Metadata for the class, to which any queries will be added
* @param cls Class that the named queries are registered against
* @param annotations Annotations specified on the class
*/
protected void processNamedQueries(AbstractClassMetaData cmd, Class cls, AnnotationObject[] annotations) {
for (AnnotationObject annotation : annotations) {
Map<String, Object> annotationValues = annotation.getNameValueMap();
String annName = annotation.getName();
if (annName.equals(JDOAnnotationUtils.QUERIES)) {
Query[] qs = (Query[]) annotationValues.get("value");
for (Query query : qs) {
String lang = JDOAnnotationUtils.getQueryLanguageName(query.language());
if (!StringUtils.isWhitespace(lang)) {
if (// Convert to JDOQL
lang.equals(JDOQuery.JDOQL_QUERY_LANGUAGE)) {
lang = QueryLanguage.JDOQL.toString();
} else if (// Convert to SQL
lang.equals(JDOQuery.SQL_QUERY_LANGUAGE)) {
lang = QueryLanguage.SQL.toString();
} else if (// Convert to JPQL
lang.equals(JDOQuery.JPQL_QUERY_LANGUAGE)) {
lang = QueryLanguage.JPQL.toString();
}
}
String resultClassName = (query.resultClass() != null && query.resultClass() != void.class ? query.resultClass().getName() : null);
if (StringUtils.isWhitespace(query.name())) {
throw new InvalidClassMetaDataException("044154", cmd.getFullClassName());
}
QueryMetaData qmd = new QueryMetaData(query.name());
qmd.setScope(cls.getName());
qmd.setLanguage(lang);
qmd.setUnmodifiable(query.unmodifiable());
qmd.setResultClass(resultClassName);
qmd.setUnique(query.unique());
qmd.setFetchPlanName(query.fetchPlan());
qmd.setQuery(query.value());
JDOAnnotationUtils.addExtensionsToMetaData(qmd, query.extensions());
cmd.addQuery(qmd);
qmd.setParent(cmd);
}
} else if (annName.equals(JDOAnnotationUtils.QUERY)) {
String unmodifiable = "" + annotationValues.get("unmodifiable");
Class resultClassValue = (Class) annotationValues.get("resultClass");
String resultClassName = (resultClassValue != null && resultClassValue != void.class ? resultClassValue.getName() : null);
String lang = JDOAnnotationUtils.getQueryLanguageName((String) annotationValues.get("language"));
if (!StringUtils.isWhitespace(lang)) {
if (// Convert to JDOQL
lang.equals(JDOQuery.JDOQL_QUERY_LANGUAGE)) {
lang = QueryLanguage.JDOQL.toString();
} else if (// Convert to SQL
lang.equals(JDOQuery.SQL_QUERY_LANGUAGE)) {
lang = QueryLanguage.SQL.toString();
} else if (// Convert to JPQL
lang.equals(JDOQuery.JPQL_QUERY_LANGUAGE)) {
lang = QueryLanguage.JPQL.toString();
}
}
if (StringUtils.isWhitespace((String) annotationValues.get("name"))) {
throw new InvalidClassMetaDataException("044154", cmd.getFullClassName());
}
QueryMetaData qmd = new QueryMetaData((String) annotationValues.get("name"));
qmd.setScope(cls.getName());
qmd.setLanguage(lang);
qmd.setUnmodifiable(unmodifiable);
qmd.setResultClass(resultClassName);
qmd.setUnique((String) annotationValues.get("unique"));
qmd.setFetchPlanName((String) annotationValues.get("fetchPlan"));
qmd.setQuery((String) annotationValues.get("value"));
JDOAnnotationUtils.addExtensionsToMetaData(qmd, (Extension[]) annotationValues.get("extensions"));
cmd.addQuery(qmd);
qmd.setParent(cmd);
}
}
}
use of org.datanucleus.metadata.annotations.AnnotationObject in project motech by motech.
the class MdsJdoAnnotationReaderTest method shouldNotRecognizeEntityAnnotationWhenFileMetadataIsEmpty.
@Test
public void shouldNotRecognizeEntityAnnotationWhenFileMetadataIsEmpty() {
AnnotationObject result = mdsJdoAnnotationReader.isClassPersistable(Record.class);
assertNull(result);
}
use of org.datanucleus.metadata.annotations.AnnotationObject in project motech by motech.
the class MdsJdoAnnotationReaderTest method shouldRecognizeRegularPCAnnotation.
@Test
public void shouldRecognizeRegularPCAnnotation() {
AnnotationObject result = mdsJdoAnnotationReader.isClassPersistable(JustPc.class);
assertEquals(PersistenceCapable.class.getName(), result.getName());
assertNotNull(result.getNameValueMap());
assertEquals("false", result.getNameValueMap().get("cacheable"));
assertEquals("true", result.getNameValueMap().get("detachable"));
}
use of org.datanucleus.metadata.annotations.AnnotationObject in project motech by motech.
the class MdsJdoAnnotationReaderTest method shouldPrioritizePersistenceCapableAnnotationValuesOverEntityDefaults.
@Test
public void shouldPrioritizePersistenceCapableAnnotationValuesOverEntityDefaults() {
AnnotationObject result = mdsJdoAnnotationReader.isClassPersistable(PcAndEntity.class);
assertEquals(PersistenceCapable.class.getName(), result.getName());
assertNotNull(result.getNameValueMap());
assertEquals(IdentityType.APPLICATION, result.getNameValueMap().get("identityType"));
assertEquals("false", result.getNameValueMap().get("detachable"));
assertEquals("testCatalog", result.getNameValueMap().get("catalog"));
}
Aggregations