use of org.datanucleus.store.rdbms.mapping.java.EmbeddedElementPCMapping in project datanucleus-rdbms by datanucleus.
the class AbstractCollectionStore method updateEmbeddedElement.
/**
* Method to update a field of an embedded element.
* @param op ObjectProvider of the owner
* @param element The element to update
* @param fieldNumber The number of the field to update
* @param value The value
* @return true if the datastore was updated
*/
public boolean updateEmbeddedElement(ObjectProvider op, E element, int fieldNumber, Object value) {
boolean modified = false;
if (elementMapping != null && elementMapping instanceof EmbeddedElementPCMapping) {
String fieldName = elementCmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber).getName();
if (fieldName == null) {
// We have no mapping for this field so presumably is the owner field or a PK field
return false;
}
JavaTypeMapping fieldMapping = ((EmbeddedElementPCMapping) elementMapping).getJavaTypeMapping(fieldName);
if (fieldMapping == null) {
// We have no mapping for this field so presumably is the owner field or a PK field
return false;
}
modified = updateEmbeddedElement(op, element, fieldNumber, value, fieldMapping);
}
return modified;
}
use of org.datanucleus.store.rdbms.mapping.java.EmbeddedElementPCMapping in project datanucleus-rdbms by datanucleus.
the class AbstractCollectionStore method getUpdateEmbeddedElementStmt.
/**
* Generate statement for update the field of an embedded element.
* <PRE>
* UPDATE SETTABLE
* SET EMBEDDEDFIELD1 = ?
* WHERE OWNERCOL=?
* AND ELEMENTCOL = ?
* </PRE>
*
* @param fieldMapping The mapping for the field within the embedded object to be updated
* @return Statement for updating an embedded element in the Set
*/
protected String getUpdateEmbeddedElementStmt(JavaTypeMapping fieldMapping) {
JavaTypeMapping ownerMapping = getOwnerMapping();
StringBuilder stmt = new StringBuilder("UPDATE ").append(containerTable.toString()).append(" SET ");
for (int i = 0; i < fieldMapping.getNumberOfDatastoreMappings(); i++) {
if (i > 0) {
stmt.append(",");
}
stmt.append(fieldMapping.getDatastoreMapping(i).getColumn().getIdentifier().toString());
stmt.append(" = ");
stmt.append(fieldMapping.getDatastoreMapping(i).getUpdateInputParameter());
}
stmt.append(" WHERE ");
BackingStoreHelper.appendWhereClauseForMapping(stmt, ownerMapping, null, true);
EmbeddedElementPCMapping embeddedMapping = (EmbeddedElementPCMapping) elementMapping;
for (int i = 0; i < embeddedMapping.getNumberOfJavaTypeMappings(); i++) {
JavaTypeMapping m = embeddedMapping.getJavaTypeMapping(i);
if (m != null) {
for (int j = 0; j < m.getNumberOfDatastoreMappings(); j++) {
stmt.append(" AND ");
stmt.append(m.getDatastoreMapping(j).getColumn().getIdentifier().toString());
stmt.append(" = ");
stmt.append(m.getDatastoreMapping(j).getUpdateInputParameter());
}
}
}
return stmt.toString();
}
Aggregations