use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.
the class AbstractEntityResource method checkIdempotenceOnRelationships.
/**
* This method maintains idempotence on PUT by disallowing sequencing in relationships.
*
* @param descriptor descriptor of the entity passed in 'entity' parameter.
* @param entity entity to process.
* @return true if check is passed (no sequencing)
*/
private boolean checkIdempotenceOnRelationships(ClassDescriptor descriptor, Object entity) {
final List<DatabaseMapping> mappings = descriptor.getMappings();
if ((mappings != null) && (!mappings.isEmpty())) {
for (DatabaseMapping mapping : mappings) {
if (mapping instanceof ForeignReferenceMapping) {
final ForeignReferenceMapping fkMapping = (ForeignReferenceMapping) mapping;
if ((fkMapping.isCascadePersist()) || (fkMapping.isCascadeMerge())) {
final ClassDescriptor referenceDescriptor = fkMapping.getReferenceDescriptor();
if (referenceDescriptor != null) {
if (referenceDescriptor instanceof RelationalDescriptor) {
final RelationalDescriptor relDesc = (RelationalDescriptor) referenceDescriptor;
final AbstractDirectMapping relSequenceMapping = relDesc.getObjectBuilder().getSequenceMapping();
if (relSequenceMapping != null) {
final Object value = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
if (value != null) {
if (value instanceof ValueHolder) {
final ValueHolder<?> holder = (ValueHolder<?>) value;
if (holder.getValue() != null) {
return false;
}
} else if (value instanceof Collection) {
if (!(((Collection<?>) value).isEmpty())) {
return false;
}
}
}
}
}
}
}
}
}
}
return true;
}
use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method addToOROXProjectsForBuildSql.
protected void addToOROXProjectsForBuildSql(ModelWithBuildSql modelWithBuildSql, Project orProject, Project oxProject, NamingConventionTransformer nct) {
List<DbColumn> columns = buildDbColumns(dbwsBuilder.getConnection(), modelWithBuildSql.getBuildSql());
String schemaAlias = modelWithBuildSql.getReturnType();
String tableName = schemaAlias;
NamingConventionTransformer customNct = setUpCustomTransformer(tableName, nct);
RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), null, customNct);
createdORDescriptors.put(desc.getJavaClassName(), desc);
desc.descriptorIsAggregate();
orProject.addDescriptor(desc);
XMLDescriptor xdesc = buildOXDescriptor(desc.getAlias(), schemaAlias, desc.getJavaClassName(), dbwsBuilder.getTargetNamespace());
oxProject.addDescriptor(xdesc);
List<String> columnsAlreadyProcessed = new ArrayList<String>();
for (DbColumn dbColumn : columns) {
String columnName = dbColumn.getFieldName();
if (!columnsAlreadyProcessed.contains(columnName)) {
columnsAlreadyProcessed.add(columnName);
ElementStyle style = nct.styleForElement(columnName);
if (style == NONE) {
continue;
}
dbwsBuilder.logMessage(FINE, "Building mappings for " + columnName);
DirectToFieldMapping orFieldMapping = buildORFieldMappingFromColumn(dbColumn, desc, dbwsBuilder.getDatabasePlatform(), nct);
desc.addMapping(orFieldMapping);
XMLDirectMapping oxFieldMapping = buildOXFieldMappingFromColumn(dbColumn, dbwsBuilder.getDatabasePlatform(), nct);
if (oxFieldMapping instanceof XMLBinaryDataMapping) {
xdesc.getNamespaceResolver().put(XML_MIME_PREFIX, XML_MIME_URL);
}
xdesc.addMapping(oxFieldMapping);
} else {
dbwsBuilder.logMessage(SEVERE, "Duplicate ResultSet columns not supported '" + columnName + "'");
throw new RuntimeException("Duplicate ResultSet columns not supported");
}
}
}
use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method buildOROXProjects.
/**
* Builds OR/OX projects, descriptors {@literal &} mappings, based on a given list
* of types, as well as table(s) and secondary SQL.
*/
public void buildOROXProjects(NamingConventionTransformer nct, List<CompositeDatabaseType> types) {
// save for later
this.nct = nct;
String projectName = dbwsBuilder.getProjectName();
Project orProject = new Project();
orProject.setName(projectName + UNDERSCORE + DBWS_OR_LABEL);
Project oxProject = null;
if (dbTables.isEmpty() && !dbwsBuilder.hasBuildSqlOperations()) {
dbwsBuilder.logMessage(FINEST, "No tables specified");
oxProject = new SimpleXMLFormatProject();
} else {
oxProject = new Project();
}
oxProject.setName(projectName + UNDERSCORE + DBWS_OX_LABEL);
for (TableType dbTable : dbTables) {
String tableName = dbTable.getTableName();
RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.requireCRUDOperations, nct);
orProject.addDescriptor(desc);
XMLDescriptor xdesc = buildOXDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.getTargetNamespace(), nct);
oxProject.addDescriptor(xdesc);
for (FieldType dbColumn : dbTable.getColumns()) {
String columnName = dbColumn.getFieldName();
ElementStyle style = nct.styleForElement(columnName);
if (style == NONE) {
continue;
}
dbwsBuilder.logMessage(FINE, "Building mappings for " + tableName + DOT + columnName);
DirectToFieldMapping orFieldMapping = buildORFieldMappingFromColumn(dbColumn, desc, dbwsBuilder.getDatabasePlatform(), nct);
desc.addMapping(orFieldMapping);
XMLDirectMapping oxFieldMapping = buildOXFieldMappingFromColumn(dbColumn, dbwsBuilder.getDatabasePlatform(), nct);
if (oxFieldMapping instanceof XMLBinaryDataMapping) {
xdesc.getNamespaceResolver().put(XML_MIME_PREFIX, XML_MIME_URL);
}
xdesc.addMapping(oxFieldMapping);
// check for switch from Byte[] to byte[]
if (oxFieldMapping.getAttributeClassificationName() == APBYTE.getName()) {
orFieldMapping.setAttributeClassificationName(APBYTE.getName());
}
}
setUpFindQueries(nct, tableName, desc);
}
finishUpProjects(orProject, oxProject, types);
}
use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.
the class Util method buildORDescriptor.
/**
* Build a RelationalDescriptor for a given table.
*/
public static RelationalDescriptor buildORDescriptor(String tableName, String projectName, List<String> requireCRUDOperations, NamingConventionTransformer nct) {
RelationalDescriptor desc = new RelationalDescriptor();
desc.addTableName(tableName);
String tableAlias = getGeneratedAlias(tableName);
desc.setAlias(tableAlias);
desc.setJavaClassName(getGeneratedJavaClassName(tableName, projectName));
desc.useWeakIdentityMap();
// keep track of which tables require CRUD operations
if (requireCRUDOperations != null) {
requireCRUDOperations.add(tableAlias);
}
return desc;
}
use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.
the class MappingProject method buildCubicleDescriptor.
protected void buildCubicleDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
// SECTION: DESCRIPTOR
descriptor.setJavaClass(Cubicle.class);
Vector vector = new Vector();
vector.addElement("MAP_CUB");
descriptor.setTableNames(vector);
descriptor.addPrimaryKeyFieldName("MAP_CUB.C_ID");
// SECTION: PROPERTIES
descriptor.setSequenceNumberName("SEQ_ID");
descriptor.setSequenceNumberFieldName("C_ID");
// SECTION: COPY POLICY
descriptor.createCopyPolicy("constructor");
// SECTION: INSTANTIATION POLICY
descriptor.createInstantiationPolicy("constructor");
// SECTION: DIRECTTOFIELDMAPPING
DirectToFieldMapping typeConversionMapping = new DirectToFieldMapping();
TypeConversionConverter typeConversionConverter = new TypeConversionConverter();
typeConversionMapping.setAttributeName("id");
typeConversionMapping.setIsReadOnly(false);
typeConversionMapping.setFieldName("MAP_CUB.C_ID");
typeConversionConverter.setObjectClass(java.math.BigDecimal.class);
typeConversionConverter.setDataClass(String.class);
typeConversionMapping.setConverter(typeConversionConverter);
descriptor.addMapping(typeConversionMapping);
// SECTION: DIRECTTOFIELDMAPPING
DirectToFieldMapping directtofieldmapping1 = new DirectToFieldMapping();
directtofieldmapping1.setAttributeName("location");
directtofieldmapping1.setIsReadOnly(false);
directtofieldmapping1.setFieldName("MAP_CUB.LOCATION");
descriptor.addMapping(directtofieldmapping1);
// SECTION: MANYTOMANYMAPPING
ManyToManyMapping manytomanymapping = new ManyToManyMapping();
manytomanymapping.setAttributeName("emergencyExits");
manytomanymapping.setIsReadOnly(false);
manytomanymapping.setUsesIndirection(false);
manytomanymapping.setReferenceClass(EmergencyExit.class);
manytomanymapping.setIsPrivateOwned(false);
manytomanymapping.setRelationTableName("CUBICLE_EMERGENCYEXIT");
manytomanymapping.addSourceRelationKeyFieldName("CUBICLE_EMERGENCYEXIT.CUBICLE_LOCATION", "MAP_CUB.LOCATION");
manytomanymapping.addTargetRelationKeyFieldName("CUBICLE_EMERGENCYEXIT.EXIT_ID", "MAP_EMERGENCYEXIT.EXIT_ID");
descriptor.addMapping(manytomanymapping);
addDescriptor(descriptor);
}
Aggregations