if ((FieldDescriptor.N_ONE_RELATION == ref.relationType()) && (ref.getReverseReferenceDescriptor() != null)) {
if (FieldDescriptor.N_ONE_RELATION == ref.relationType()) {
    protected void createStandardIndexes(ClassDescriptor cld)        throws SQLException, MetaDataException {        // Set of fieldnames that already are the first element of an index.        Set doneFieldNames = new HashSet();        String cldTableName = DatabaseUtil.getTableName(cld);        //add an index for each primary key        Map primaryKeys = PrimaryKeyUtil.getPrimaryKeys(cld);        for (Iterator i = primaryKeys.entrySet().iterator(); i.hasNext();) {            Map.Entry entry = (Map.Entry) i.next();            String keyName = (String) entry.getKey();            PrimaryKey key = (PrimaryKey) entry.getValue();            List fieldNames = new ArrayList();            boolean firstOne = true;            boolean doNulls = false;            for (Iterator j = key.getFieldNames().iterator(); j.hasNext();) {                String fieldName = (String) j.next();                FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName);                if (firstOne && (fd instanceof AttributeDescriptor)) {                    doNulls = !((AttributeDescriptor) fd).isPrimitive();                }                if (fd == null) {                    throw new MetaDataException("field (" + fieldName + ") not found for class: "                                                + cld.getName() + ".");                }                fieldNames.add(DatabaseUtil.getColumnName(fd));                firstOne = false;            }            // create indexes on this class and on all subclasses            Set clds = new HashSet(Collections.singleton(cld));            clds.addAll(cld.getModel().getAllSubs(cld));            for (Iterator k = clds.iterator(); k.hasNext();) {                ClassDescriptor nextCld = (ClassDescriptor) k.next();                ClassDescriptor tableMaster = schema.getTableMaster(nextCld);                String tableName = DatabaseUtil.getTableName(tableMaster);                if (!schema.getMissingTables().contains(tableName.toLowerCase())) {                    dropIndex(tableName + "__" + cldTableName + "__" + keyName);                    createIndex(tableName + "__" + cldTableName + "__" + keyName, tableName,                                StringUtil.join(fieldNames, ", ") + ", id");                    if (doNulls) {                        dropIndex(tableName + "__" + cldTableName + "__" + keyName + "__nulls");                        createIndex(tableName + "__" + cldTableName + "__" + keyName + "__nulls",                                tableName, "(" + fieldNames.get(0) + " IS NULL)");                    }                    doneFieldNames.add(fieldNames.get(0));                }            }        }        //and one for each bidirectional N-to-1 relation to increase speed of        //e.g. company.getDepartments        for (Iterator i = cld.getAllReferenceDescriptors().iterator(); i.hasNext();) {            ReferenceDescriptor ref = (ReferenceDescriptor) i.next();            ClassDescriptor refMaster = ref.getClassDescriptor();            ClassDescriptor tableMaster = schema.getTableMaster(cld);            String tableName = DatabaseUtil.getTableName(tableMaster);            if ((FieldDescriptor.N_ONE_RELATION == ref.relationType())                    && (ref.getReverseReferenceDescriptor() != null)) {                if (!schema.getMissingTables().contains(tableName.toLowerCase())) {                    String fieldName = DatabaseUtil.getColumnName(ref);                    if (!doneFieldNames.contains(fieldName)) {                        dropIndex(cldTableName + "__"  + ref.getName());                        createIndex(cldTableName + "__"  + ref.getName(), tableName,                                    fieldName + ", id");                    }                }            }        }        //finally add an index to all M-to-N indirection table columns        //for (Iterator i = cld.getAllCollectionDescriptors().iterator(); i.hasNext();) {        for (Iterator i = cld.getCollectionDescriptors().iterator(); i.hasNext();) {            CollectionDescriptor col = (CollectionDescriptor) i.next();            if (FieldDescriptor.M_N_RELATION == col.relationType()) {                String tableName = DatabaseUtil.getIndirectionTableName(col);                String columnName = DatabaseUtil.getInwardIndirectionColumnName(col);                String columnName2 = DatabaseUtil.getOutwardIndirectionColumnName(col);                if ((columnName.compareTo(columnName2) < 0)                        || (col.getReverseReferenceDescriptor() == null)) {                    dropIndex(tableName + "__"  + columnName);                    dropIndex(tableName + "__"  + columnName2);                    createIndex(tableName + "__"  + columnName, tableName,                            columnName + ", " + columnName2);                    createIndex(tableName + "__"  + columnName2, tableName,                            columnName2 + ", " + columnName);                }            }        }    }