if ((!(isRelation | isEmbedded))) {
if (columns.length == 1) {
// each field is mapped to one column
this.column = columns[0];
this.columnName = column.getName();
Table table = domainTypeHandler.getTable();
if (table == null) {
message = local.message("ERR_No_Mapped_Table", domainTypeHandler.getName());
setUnsupported(message);
return;
}
this.storeColumn = table.getColumn(columnName);
if (storeColumn == null) {
message = local.message("ERR_No_Column", name, table.getName(), columnName);
setUnsupported(message);
return;
}
this.storeColumns = new com.mysql.clusterj.core.store.Column[] {storeColumn};
charsetName = storeColumn.getCharsetName();
// set up the default object operation handler for the column type
// TODO this might better use the "Class type;" field in superclass
this.javaType = column.getJavaType();
this.objectOperationHandlerDelegate = getObjectOperationHandler(javaType);
if (objectOperationHandlerUnsupportedType.equals(objectOperationHandlerDelegate)) {
message = local.message("ERR_Unsupported_Meta_Type", javaType);
setUnsupported(message);
return;
} else {
this.javaTypeName = NdbOpenJPAUtility.getJavaTypeName(javaType);
if (storeColumn.isPrimaryKey()) {
domainTypeHandler.registerPrimaryKeyColumn(this, storeColumn.getName());
}
}
} else if (columns.length > 1) {
// error, no support
StringBuffer buffer = new StringBuffer();
String separator = "";
for (Column errorColumn : columns) {
buffer.append(separator);
buffer.append(errorColumn.getName());
separator = ", ";
}
message = local.message("ERR_More_Than_One_Column_Mapped_To_A_Field",
domainTypeHandler.getName(), name, buffer);
logger.info(message);
setUnsupported(message);
return;
} else if (columns.length == 0) {
message = local.message("ERR_No_Column_Mapped_To_A_Field",
domainTypeHandler.getName(), name, fieldMapping.getTable(), fieldMapping.getStrategy().getClass().getName());
logger.info(message);
setUnsupported(message);
return;
}
if (this.primaryKey) {
// each field is mapped to its own column
// if using a user-defined openJPAId class, set up the value handler
oidField = getFieldForOidClass(this, domainTypeHandler.getOidClass(), name);
indexNames.add("PRIMARY");
switch (javaType) {
case JavaTypes.INT:
this.objectOperationHandlerDelegate = objectOperationHandlerKeyInt;
break;
case JavaTypes.INT_OBJ:
this.objectOperationHandlerDelegate = objectOperationHandlerKeyObjectInteger;
break;
case JavaTypes.LONG:
this.objectOperationHandlerDelegate = objectOperationHandlerKeyLong;
break;
case JavaTypes.LONG_OBJ:
this.objectOperationHandlerDelegate = objectOperationHandlerKeyObjectLong;
break;
case JavaTypes.STRING: this.objectOperationHandlerDelegate =
objectOperationHandlerKeyString;
break;
default:
message = local.message("ERR_Illegal_Primary_Key_Type",
domainTypeHandler.getName(), name, columnName, javaTypeName);
logger.info(message);
setUnsupported(message);
}
}
} else if (isRelation) {
// relationships might have zero, one, or more columns
if (columns.length == 1) {
this.column = columns[0];
this.columnName = column.getName();
this.columnNames = new String[] {columnName};
Table table = domainTypeHandler.getTable();
this.storeColumn = table.getColumn(columnName);
if (storeColumn == null) {
message = local.message("ERR_No_Column", name, table.getName(), columnName);
setUnsupported(message);
return;
}
this.storeColumns = new com.mysql.clusterj.core.store.Column[] {storeColumn};
// set up the default object operation handler for the column type
this.javaType = column.getJavaType();
this.javaTypeName = NdbOpenJPAUtility.getJavaTypeName(javaType);
this.objectOperationHandlerDelegate = getObjectOperationHandlerRelationDelegate(javaType);
if (objectOperationHandlerDelegate == null) {
// unsupported primary key type
return;
}
} else if (columns.length == 0) {
if (isMappedBy) {
// this is the case of a OneToMany field mapped by columns in another table
this.objectOperationHandlerDelegate = objectOperationHandlerVirtualType;
} else {
message = local.message("ERR_No_Columns_And_Not_Mapped_By",
this.domainTypeHandler.getName(), this.name);
logger.info(message);
setUnsupported(message);
}
} else {
// multiple columns for related object
if (isMappedBy) {
// this is the case of OneToOne field mapped by columns in another table
this.objectOperationHandlerDelegate = objectOperationHandlerVirtualType;
} else {
// create an array of NdbOpenJPADomainFieldHandlerImpl
// one for each column in the foreign key
// each one needs to be able to extract the foreign key
// value from the openJPAId instance of the related instance
// using the oidField object
this.relatedTypeMapping = fieldMapping.getDeclaredTypeMapping();
this.relatedType = relatedTypeMapping.getDescribedType();
Class<?> oid = relatedTypeMapping.getObjectIdType();
if (logger.isDetailEnabled()) logger.detail(
"For class: " + domainTypeHandler.getName() +
" field: " + name + " related type is: " + relatedType.getName() +
" objectid type: " + oid.getName());
// create the domain field handlers for each column
this.compositeDomainFieldHandlers = new NdbOpenJPADomainFieldHandlerImpl[columns.length];
this.columnNames = new String[columns.length];
this.storeColumns = new com.mysql.clusterj.core.store.Column[columns.length];
for (int i = 0; i < columns.length; ++i) {
StringBuffer detailMessage = new StringBuffer();
Column localColumn = columns[i];
String localColumnName = localColumn.getName();
Table table = domainTypeHandler.getTable();
com.mysql.clusterj.core.store.Column localStoreColumn = table.getColumn(localColumnName);
if (localStoreColumn == null) {
message = local.message("ERR_No_Column", name, table.getName(), localColumnName);
logger.info(message);
setUnsupported(message);
return;
}
this.storeColumns[i] = localStoreColumn;