/** * Create an instance of {@link Entity } * */ public Entity createEntity() { return new Entity(); }
public void addField(final Field field) { if (field == null) throw new NullPointerException("field is null"); if (field instanceof Id) { if (attributes == null) attributes = new Attributes(); attributes.getId().add((Id) field); } else if (field instanceof Basic) { if (attributes == null) attributes = new Attributes(); attributes.getBasic().add((Basic) field); } else if (field instanceof Transient) { if (attributes == null) attributes = new Attributes(); attributes.getTransient().add((Transient) field); } else if (field instanceof AttributeOverride) { getAttributeOverride().add((AttributeOverride) field); } else { throw new IllegalArgumentException("Unknown field type " + field.getClass()); } }
public class Controller { private EntityManagerFactory emf; public void doSomeUnitOfWork(int id) { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); CrudDao dao = new CrudDao(em); Entity entity = dao.get(id); entity.setName("James"); dao.save(entity); em.getTransaction.commit(); em.close(); } }
entity.setXmlMetadataComplete(true); entity = new Entity(jpaEntityClassName); if (entity.getAttributes() == null) { entity.setAttributes(new Attributes()); entity.setDescription(ejbModule.getModuleId() + "#" + bean.getEjbName()); entity.setName(entityName); entity.setEjbName(bean.getEjbName()); entity.getNamedQuery().add(namedQuery); entity.getNamedQuery().add(namedQuery);
for (final Entity entity : entityMappings.getEntity()) { try { entities.put(entity.getDescription(), new EntityData(entity)); } catch (final IllegalArgumentException e) { LoggerFactory.getLogger(this.getClass()).error(e.getMessage(), e); entityData.entity.setTable(table); final Attributes attributes = entityData.entity.getAttributes(); if (attributes != null && attributes.getId().size() == 1) { final Id id = attributes.getId().get(0); name.append(entityData.entity.getName()).append(".").append(queryMethod.getMethodName()); if (queryMethod.getMethodParams() != null && !queryMethod.getMethodParams().getMethodParam().isEmpty()) { name.append('('); entityData.entity.getNamedQuery().add(namedQuery);
final Attributes attributes = this.entity.getAttributes(); for (final AttributeOverride attributeOverride : this.entity.getAttributeOverride()) { this.fields.put(attributeOverride.getName(), attributeOverride);
entitiesByEjbName.put(entity.getEjbName(), entity); logger.warning("openejb-cmp-orm.xml mapping ignored: module=" + ejbModule.getModuleId() + ": <entity class=\"" + mapping.getClazz() + "\">"); persistenceUnit.getClazz().add(entity.getClazz()); if (entity.getAttributes() != null && entity.getAttributes().isEmpty()) { entity.setAttributes(null);
final List<List<String>> params = parseQueryParamters(finder.getQueryParams()); final String queryFilter = finder.getQueryFilter(); final String ejbQl = convertToEjbQl(entityData.entity.getName(), cmpFields, finder.getQueryParams(), queryFilter); name.append(entityData.entity.getName()).append(".").append(finder.getMethodName()); if (!params.isEmpty()) { name.append('('); entityData.entity.getNamedQuery().add(namedQuery);
final Attributes rightAttributes = rightEntity.getAttributes(); Map<String, RelationField> rightRelationships = rightAttributes.getRelationshipFieldMap(); final Attributes leftAttributes = leftEntity.getAttributes(); Map<String, RelationField> leftRelationships = leftAttributes.getRelationshipFieldMap(); leftFieldName = leftRole.getCmrField().getCmrFieldName(); } else { leftFieldName = rightEntity.getName() + "_" + rightRole.getCmrField().getCmrFieldName(); leftSynthetic = true; rightFieldName = rightRole.getCmrField().getCmrFieldName(); } else { rightFieldName = leftEntity.getName() + "_" + leftRole.getCmrField().getCmrFieldName(); rightSynthetic = true;
private Entity removeEntity(final EntityMappings userMappings, final String className) { final Entity entity; entity = userMappings.getEntityMap().get(className); if (entity != null) { userMappings.getEntityMap().remove(entity.getKey()); } return entity; }
public void convertModule(EjbModule ejbModule, EntityMappings entityMappings) { Map<String, EntityData> entities = new TreeMap<String, EntityData>(); if (entityMappings != null ) for (Entity entity : entityMappings.getEntity()) { entities.put(entity.getDescription(), new SunConversion.EntityData(entity)); } // merge data from sun-ejb-jar.xml file SunEjbJar sunEjbJar = getSunEjbJar(ejbModule); mergeEjbConfig(ejbModule, sunEjbJar); mergeEntityMappings(entities, ejbModule.getModuleId(), ejbModule.getEjbJar(), ejbModule.getOpenejbJar(), sunEjbJar); // merge data from sun-cmp-mappings.xml file SunCmpMappings sunCmpMappings = getSunCmpMappings(ejbModule); if (sunCmpMappings != null) { for (SunCmpMapping sunCmpMapping : sunCmpMappings.getSunCmpMapping()) { mergeEntityMappings(entities, ejbModule.getModuleId(), ejbModule, entityMappings, sunCmpMapping); } } }
entity.setXmlMetadataComplete(true); entity = new Entity(jpaEntityClassName); if (entity.getAttributes() == null){ entity.setAttributes(new Attributes()); entity.setDescription(ejbModule.getModuleId() + "#" + bean.getEjbName()); entity.setName(entityName); entity.setEjbName(bean.getEjbName()); entity.getNamedQuery().add(namedQuery); entity.getNamedQuery().add(namedQuery);
for (final Entity entity : entityMappings.getEntity()) { try { entities.put(entity.getDescription(), new EntityData(entity)); } catch (final IllegalArgumentException e) { LoggerFactory.getLogger(this.getClass()).error(e.getMessage(), e); entityData.entity.setTable(table); final Attributes attributes = entityData.entity.getAttributes(); if (attributes != null && attributes.getId().size() == 1) { final Id id = attributes.getId().get(0); name.append(entityData.entity.getName()).append(".").append(queryMethod.getMethodName()); if (queryMethod.getMethodParams() != null && !queryMethod.getMethodParams().getMethodParam().isEmpty()) { name.append('('); entityData.entity.getNamedQuery().add(namedQuery);
final Attributes attributes = this.entity.getAttributes(); for (final AttributeOverride attributeOverride : this.entity.getAttributeOverride()) { this.fields.put(attributeOverride.getName(), attributeOverride);
entitiesByEjbName.put(entity.getEjbName(), entity); logger.warning("openejb-cmp-orm.xml mapping ignored: module=" + ejbModule.getModuleId() + ": <entity class=\"" + mapping.getClazz() + "\">"); persistenceUnit.getClazz().add(entity.getClazz()); if (entity.getAttributes() != null && entity.getAttributes().isEmpty()) { entity.setAttributes(null);
List<List<String>> params = parseQueryParamters(finder.getQueryParams()); String queryFilter = finder.getQueryFilter(); String ejbQl = convertToEjbQl(entityData.entity.getName(), cmpFields, finder.getQueryParams(), queryFilter); name.append(entityData.entity.getName()).append(".").append(finder.getMethodName()); if (!params.isEmpty()) { name.append('('); entityData.entity.getNamedQuery().add(namedQuery);
final Attributes rightAttributes = rightEntity.getAttributes(); final Map<String, RelationField> rightRelationships = rightAttributes.getRelationshipFieldMap(); final Attributes leftAttributes = leftEntity.getAttributes(); final Map<String, RelationField> leftRelationships = leftAttributes.getRelationshipFieldMap(); leftFieldName = leftRole.getCmrField().getCmrFieldName(); } else { leftFieldName = rightEntity.getName() + "_" + rightRole.getCmrField().getCmrFieldName(); leftSynthetic = true; rightFieldName = rightRole.getCmrField().getCmrFieldName(); } else { rightFieldName = leftEntity.getName() + "_" + leftRole.getCmrField().getCmrFieldName(); rightSynthetic = true;
private Entity removeEntity(final EntityMappings userMappings, final String className) { final Entity entity; entity = userMappings.getEntityMap().get(className); if (entity != null) { userMappings.getEntityMap().remove(entity.getKey()); } return entity; }
public void convertModule(final EjbModule ejbModule, final EntityMappings entityMappings) { final Map<String, EntityData> entities = new TreeMap<String, EntityData>(); if (entityMappings != null) { for (final Entity entity : entityMappings.getEntity()) { entities.put(entity.getDescription(), new EntityData(entity)); } } // merge data from sun-ejb-jar.xml file final SunEjbJar sunEjbJar = getSunEjbJar(ejbModule); mergeEjbConfig(ejbModule, sunEjbJar); mergeEntityMappings(entities, ejbModule.getModuleId(), ejbModule.getEjbJar(), ejbModule.getOpenejbJar(), sunEjbJar); // merge data from sun-cmp-mappings.xml file final SunCmpMappings sunCmpMappings = getSunCmpMappings(ejbModule); if (sunCmpMappings != null) { for (final SunCmpMapping sunCmpMapping : sunCmpMappings.getSunCmpMapping()) { mergeEntityMappings(entities, ejbModule.getModuleId(), ejbModule, entityMappings, sunCmpMapping); } } }
entity.setXmlMetadataComplete(true); entity = new Entity(jpaEntityClassName); if (entity.getAttributes() == null) { entity.setAttributes(new Attributes()); entity.setDescription(ejbModule.getModuleId() + "#" + bean.getEjbName()); entity.setName(entityName); entity.setEjbName(bean.getEjbName()); entity.getNamedQuery().add(namedQuery); entity.getNamedQuery().add(namedQuery);