/** * {@inheritDoc} */ @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("<fields=\""); boolean needComma = false; for (String fieldName : getFieldNames()) { if (needComma) { sb.append(","); } sb.append(fieldName); } sb.append("\">"); return sb.toString(); } }
/** * {@inheritDoc} */ @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("<fields=\""); boolean needComma = false; for (String fieldName : getFieldNames()) { if (needComma) { sb.append(","); } sb.append(fieldName); } sb.append("\">"); return sb.toString(); } }
/** * Returns true if the given field is a member of any primary key on the given class, for the * given source. * * @param model the Model in which to find ClassDescriptors * @param clazz the Class in which to look * @param fieldName the name of the field to check * @param source the Source that the keys belong to * @return true if the field is a primary key */ public static boolean fieldIsPrimaryKey(Model model, Class<?> clazz, String fieldName, Source source) { Map<PrimaryKeyCacheKey, Set<String>> cache = primaryKeyCache.get(); PrimaryKeyCacheKey key = new PrimaryKeyCacheKey(model, clazz, source); Set<String> fields = cache.get(key); if (fields == null) { fields = new HashSet<String>(); for (ClassDescriptor cld : model.getClassDescriptorsForClass(clazz)) { for (PrimaryKey pk : getPrimaryKeys(cld, source, null)) { fields.addAll(pk.getFieldNames()); } } cache.put(key, fields); } return fields.contains(fieldName); }
/** * Returns true if the given field is a member of any primary key on the given class, for the * given source. * * @param model the Model in which to find ClassDescriptors * @param clazz the Class in which to look * @param fieldName the name of the field to check * @param source the Source that the keys belong to * @return true if the field is a primary key */ public static boolean fieldIsPrimaryKey(Model model, Class<?> clazz, String fieldName, Source source) { Map<PrimaryKeyCacheKey, Set<String>> cache = primaryKeyCache.get(); PrimaryKeyCacheKey key = new PrimaryKeyCacheKey(model, clazz, source); Set<String> fields = cache.get(key); if (fields == null) { fields = new HashSet<String>(); for (ClassDescriptor cld : model.getClassDescriptorsForClass(clazz)) { for (PrimaryKey pk : getPrimaryKeys(cld, source, null)) { fields.addAll(pk.getFieldNames()); } } cache.put(key, fields); } return fields.contains(fieldName); }
/** * Returns whether this primary key can be fetched now. * * @param pk the PrimaryKey * @param cld the ClassDescriptor that the PrimaryKey is in * @param pksNotDone a Map of pks not yet fetched * @return a boolean */ protected boolean canDoPkNow(PrimaryKey pk, ClassDescriptor cld, Map<PrimaryKey, ClassDescriptor> pksNotDone) { boolean canDoPkNow = true; Iterator<String> fieldNameIter = pk.getFieldNames().iterator(); while (fieldNameIter.hasNext() && canDoPkNow) { String fieldName = fieldNameIter.next(); FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd.isReference()) { Iterator<ClassDescriptor> otherCldIter = pksNotDone.values().iterator(); while (otherCldIter.hasNext() && canDoPkNow) { ClassDescriptor otherCld = otherCldIter.next(); Class<? extends FastPathObject> fieldClass = ((ReferenceDescriptor) fd) .getReferencedClassDescriptor().getType(); if (otherCld.getType().isAssignableFrom(fieldClass) || fieldClass.isAssignableFrom(otherCld.getType())) { canDoPkNow = false; } } } } return canDoPkNow; }
/** * Returns whether this primary key can be fetched now. * * @param pk the PrimaryKey * @param cld the ClassDescriptor that the PrimaryKey is in * @param pksNotDone a Map of pks not yet fetched * @return a boolean */ protected boolean canDoPkNow(PrimaryKey pk, ClassDescriptor cld, Map<PrimaryKey, ClassDescriptor> pksNotDone) { boolean canDoPkNow = true; Iterator<String> fieldNameIter = pk.getFieldNames().iterator(); while (fieldNameIter.hasNext() && canDoPkNow) { String fieldName = fieldNameIter.next(); FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd.isReference()) { Iterator<ClassDescriptor> otherCldIter = pksNotDone.values().iterator(); while (otherCldIter.hasNext() && canDoPkNow) { ClassDescriptor otherCld = otherCldIter.next(); Class<? extends FastPathObject> fieldClass = ((ReferenceDescriptor) fd) .getReferencedClassDescriptor().getType(); if (otherCld.getType().isAssignableFrom(fieldClass) || fieldClass.isAssignableFrom(otherCld.getType())) { canDoPkNow = false; } } } } return canDoPkNow; }
getIntegrationWriter().getModel()); for (PrimaryKey pk :keysForSource) { for (String fieldName: pk.getFieldNames()) { ClassDescriptor cld = pk.getClassDescriptor(); FieldDescriptor fld = cld.getFieldDescriptorByName(fieldName);
public void createPKQueryForPK(InterMineObject obj, boolean queryNulls, ClassDescriptor cld, PrimaryKey pk, Source source, Set<Query> returnSet) throws MetaDataException { for (String fieldName : pk.getFieldNames()) { FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd instanceof AttributeDescriptor) {
getIntegrationWriter().getModel()); for (PrimaryKey pk :keysForSource) { for (String fieldName: pk.getFieldNames()) { ClassDescriptor cld = pk.getClassDescriptor(); FieldDescriptor fld = cld.getFieldDescriptorByName(fieldName);
public void createPKQueryForPK(InterMineObject obj, boolean queryNulls, ClassDescriptor cld, PrimaryKey pk, Source source, Set<Query> returnSet) throws MetaDataException { for (String fieldName : pk.getFieldNames()) { FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd instanceof AttributeDescriptor) {
String firstKeyField = key.getFieldNames().iterator().next();
String firstKeyField = key.getFieldNames().iterator().next();
List<String> fields = new ArrayList<String>(); for (String field : pk.getFieldNames()) { String colName = DatabaseUtil.generateSqlCompatibleName(field);
PrimaryKey key = entry.getValue(); List<String> fieldNames = new ArrayList<String>(); for (String fieldName : key.getFieldNames()) { FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd == null) {
PrimaryKey key = entry.getValue(); List<String> fieldNames = new ArrayList<String>(); for (String fieldName : key.getFieldNames()) { FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd == null) {
public void testConstructor() throws Exception { Model model = Model.getInstanceByName("basicmodel"); ClassDescriptor cld = model.getClassDescriptorByName("org.intermine.model.basicmodel.Employee"); Set<String> expected = new HashSet<String>(); expected.add("name"); expected.add("age"); assertEquals(expected, new PrimaryKey("key1", "name, age", cld).getFieldNames()); try { new PrimaryKey("key1", "name, age", null); fail("Expected NullPointerException"); } catch (NullPointerException e) { } try { new PrimaryKey("key1", "name, flibble", cld); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { new PrimaryKey("key1", "name, departments", cld); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } } }
ClassDescriptor cld, PrimaryKey pk, Source source, IntToIntMap idMap) throws MetaDataException { for (String fieldName : pk.getFieldNames()) { FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd instanceof AttributeDescriptor) {
ClassDescriptor cld, PrimaryKey pk, Source source, IntToIntMap idMap) throws MetaDataException { for (String fieldName : pk.getFieldNames()) { FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd instanceof AttributeDescriptor) {
query.addToSelect(qc); ConstraintSet cs = new ConstraintSet(ConstraintOp.AND); for (String fieldName : pk.getFieldNames()) { FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd instanceof AttributeDescriptor) {
query.addToSelect(qc); ConstraintSet cs = new ConstraintSet(ConstraintOp.AND); for (String fieldName : pk.getFieldNames()) { FieldDescriptor fd = cld.getFieldDescriptorByName(fieldName); if (fd instanceof AttributeDescriptor) {