public void testConstructorNull() throws Exception { try { new PrimaryKey("key", null, null); fail("Expected NullPointerException"); } catch (NullPointerException e) { } }
public void testGetPrimaryKeysCldSource3() throws Exception { ClassDescriptor cld = model.getClassDescriptorByName("org.intermine.model.testmodel.Company"); Source source = new Source("testsource2"); assertEquals(new HashSet(Arrays.asList(new PrimaryKey("key1", "name, address", cld), new PrimaryKey("local_key", "name, vatNumber", cld))), DataLoaderHelper.getPrimaryKeys(cld, source, null)); }
/** * Retrieve a map from key name to PrimaryKey object. The Map contains all the primary keys * that exist on a particular class, without performing any recursion. * * @param cld the ClassDescriptor to fetch primary keys for * @return the Map from key names to PrimaryKeys */ public static Map<String, PrimaryKey> getPrimaryKeys(ClassDescriptor cld) { Map<String, PrimaryKey> keyMap = primaryKeyCache.get(cld); if (keyMap == null) { keyMap = new LinkedHashMap<String, PrimaryKey>(); Properties keys = getKeyProperties(cld.getModel().getName()); String cldName = Util.unqualifiedName(cld.getName()); Properties cldKeys = Util.getPropertiesStartingWith(cldName, keys); cldKeys = Util.stripStart(cldName, cldKeys); List<String> keyNames = new ArrayList<String>(); for (Object key : cldKeys.keySet()) { if (key instanceof String) { keyNames.add((String) key); } } Collections.sort(keyNames); for (String keyName : keyNames) { PrimaryKey key = new PrimaryKey(keyName, (String) cldKeys.get(keyName), cld); keyMap.put(keyName, key); } primaryKeyCache.put(cld, keyMap); } return keyMap; }
public void testGetPrimaryKeysCld() { ClassDescriptor cld = model.getClassDescriptorByName("org.intermine.model.basicmodel.Employee"); expected.put("key1", new PrimaryKey("key1", "name, age", cld)); expected.put("key2", new PrimaryKey("key2", "name, fullTime", cld)); assertEquals(expected, PrimaryKeyUtil.getPrimaryKeys(cld)); }
/** * Retrieve a map from key name to PrimaryKey object. The Map contains all the primary keys * that exist on a particular class, without performing any recursion. * * @param cld the ClassDescriptor to fetch primary keys for * @return the Map from key names to PrimaryKeys */ public static Map<String, PrimaryKey> getPrimaryKeys(ClassDescriptor cld) { Map<String, PrimaryKey> keyMap = primaryKeyCache.get(cld); if (keyMap == null) { keyMap = new LinkedHashMap<String, PrimaryKey>(); Properties keys = getKeyProperties(cld.getModel().getName()); String cldName = Util.unqualifiedName(cld.getName()); Properties cldKeys = Util.getPropertiesStartingWith(cldName, keys); cldKeys = Util.stripStart(cldName, cldKeys); List<String> keyNames = new ArrayList<String>(); for (Object key : cldKeys.keySet()) { if (key instanceof String) { keyNames.add((String) key); } } Collections.sort(keyNames); for (String keyName : keyNames) { PrimaryKey key = new PrimaryKey(keyName, (String) cldKeys.get(keyName), cld); keyMap.put(keyName, key); } primaryKeyCache.put(cld, keyMap); } return keyMap; }
+ propName + " for source: " + source.getName()); } else { PrimaryKey pk = new PrimaryKey(keyName, fieldList, cld); if (!keySet.contains(pk)) { keySet.add(pk);
+ propName + " for source: " + source.getName()); } else { PrimaryKey pk = new PrimaryKey(keyName, fieldList, cld); if (!keySet.contains(pk)) { keySet.add(pk);
public void testGetPrimaryKeysCldSource2() throws Exception { ClassDescriptor cld = model.getClassDescriptorByName("org.intermine.model.testmodel.Company"); Source source = new Source("testsource4"); Set expected = new HashSet(); expected.add(new PrimaryKey("key1", "name,address", cld)); expected.add(new PrimaryKey("key2", "vatNumber", cld)); assertEquals(expected, DataLoaderHelper.getPrimaryKeys(cld, source, 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) { } } }
if (cldName.equals(propCldName)) { String keyName = propKey.substring(posOfDot + 1); PrimaryKey pk = new PrimaryKey(keyName, fieldList, cld); if (!keySet.contains(pk)) { keySet.add(pk);
if (cldName.equals(propCldName)) { String keyName = propKey.substring(posOfDot + 1); PrimaryKey pk = new PrimaryKey(keyName, fieldList, cld); if (!keySet.contains(pk)) { keySet.add(pk);
public void testGetPrimaryKeysCldSource() throws Exception { ClassDescriptor cld = model.getClassDescriptorByName("org.intermine.model.testmodel.Company"); Source source = new Source("testsource"); assertEquals(Collections.singleton(new PrimaryKey("key1", "name, address", cld)), DataLoaderHelper.getPrimaryKeys(cld, source, null)); source = new Source("testsource5"); try { DataLoaderHelper.getPrimaryKeys(cld, source, null); fail("Was expecting an exception"); } catch (IllegalArgumentException e) { } }