use of org.eclipse.persistence.dynamic.DynamicType in project aai-aai-common by onap.
the class FromOxmVertexSchema method fromOxm.
public void fromOxm(String vertexType, DynamicJAXBContext jaxbContext, HashMap<String, DynamicType> xmlElementLookup) throws SchemaProviderException {
name = vertexType;
properties = new HashMap<String, PropertySchema>();
annotations = new HashMap<String, String>();
String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, vertexType);
DynamicType modelObjectType = jaxbContext.getDynamicType(javaTypeName);
if (modelObjectType == null) {
// Try to lookup by xml root element by exact match
modelObjectType = xmlElementLookup.get(vertexType);
}
if (modelObjectType == null) {
// Try to lookup by xml root element by lowercase
modelObjectType = xmlElementLookup.get(vertexType.toLowerCase());
}
if (modelObjectType == null) {
// Direct lookup as java-type name
modelObjectType = jaxbContext.getDynamicType(vertexType);
}
if (modelObjectType == null) {
// Vertex isn't found in the OXM
throw new SchemaProviderException("Vertex " + vertexType + " not found in OXM");
}
// Check annotations
Map<String, Object> oxmProps = modelObjectType.getDescriptor().getProperties();
for (Map.Entry<String, Object> entry : oxmProps.entrySet()) {
if (entry.getValue() instanceof String) {
annotations.put(entry.getKey().toLowerCase(), (String) entry.getValue());
}
}
// Regular props
for (DatabaseMapping mapping : modelObjectType.getDescriptor().getMappings()) {
if (mapping instanceof XMLAnyObjectMapping)
continue;
if (mapping instanceof XMLAnyCollectionMapping)
continue;
FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
propSchema.fromOxm(mapping, modelObjectType, false);
properties.put(propSchema.getName().toLowerCase(), propSchema);
}
// Reserved Props
final DynamicType reservedType = jaxbContext.getDynamicType("ReservedPropNames");
for (DatabaseMapping mapping : reservedType.getDescriptor().getMappings()) {
if (mapping.isAbstractDirectMapping()) {
FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
propSchema.fromOxm(mapping, reservedType, true);
properties.put(propSchema.getName().toLowerCase(), propSchema);
}
}
}
use of org.eclipse.persistence.dynamic.DynamicType in project aai-aai-common by onap.
the class OxmSchemaLoader method loadXmlLookupMap.
private static void loadXmlLookupMap(String version, DynamicJAXBContext jaxbContext) {
@SuppressWarnings("rawtypes") List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
HashMap<String, DynamicType> types = new HashMap<String, DynamicType>();
for (@SuppressWarnings("rawtypes") Descriptor desc : descriptorsList) {
DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
String entityName = desc.getDefaultRootElement();
types.put(entityName, entity);
}
xmlElementLookup.put(version, types);
}
use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.
the class PersistenceContext method newEntity.
/**
* A convenience method to create a new dynamic entity of the given type
*/
public DynamicEntity newEntity(Map<String, String> tenantId, String type) {
JPADynamicHelper helper = new JPADynamicHelper(getEmf());
DynamicEntity entity;
try {
entity = helper.newDynamicEntity(type);
} catch (IllegalArgumentException e) {
ClassDescriptor descriptor = getDescriptor(type);
if (descriptor != null) {
DynamicType jaxbType = (DynamicType) descriptor.getProperty(DynamicType.DESCRIPTOR_PROPERTY);
if (jaxbType != null) {
return jaxbType.newDynamicEntity();
}
}
JPARSLogger.exception(getSessionLog(), "exception_thrown_while_creating_dynamic_entity", new Object[] { type }, e);
throw e;
}
return entity;
}
use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.
the class JPADynamicHelper method addTypes.
/**
* Add one or more EntityType instances to a session and optionally generate
* needed tables with or without FK constraints.
*/
@Override
public void addTypes(boolean createMissingTables, boolean generateFKConstraints, DynamicType... types) {
super.addTypes(createMissingTables, generateFKConstraints, types);
for (DynamicType type : types) {
ClassDescriptor descriptor = type.getDescriptor();
descriptor.getQueryManager().checkDatabaseForDoesExist();
}
}
use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.
the class SimpleTypes_MultiTable method persistSimpleA.
@Test
public void persistSimpleA() {
DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
Assert.assertNotNull(simpleTypeA);
DynamicEntity simpleInstance = simpleTypeA.newDynamicEntity();
simpleInstance.set("id", 1);
simpleInstance.set("value1", "A1");
UnitOfWork uow = session.acquireUnitOfWork();
uow.registerNewObject(simpleInstance);
uow.commit();
ReportQuery countQuery = dynamicHelper.newReportQuery("SimpleA", new ExpressionBuilder());
countQuery.addCount();
countQuery.setShouldReturnSingleValue(true);
int simpleCount = ((Number) session.executeQuery(countQuery)).intValue();
Assert.assertEquals(1, simpleCount);
session.release();
}
Aggregations