@SuppressWarnings("unchecked") public static List<JpaProperty> findProperties(BeanId id) { Optional<EntityManager> optional = getEm(); if (!optional.isPresent()) { return new ArrayList<>(); } EntityManager em = optional.get(); Query query = em.createNamedQuery(FIND_PROPERTIES_FOR_BEAN_NAME); query.setParameter(1, id.getInstanceId()); query.setParameter(2, id.getSchemaName()); List<JpaProperty> properties = (List<JpaProperty>) query.getResultList(); return properties; }
public static void deleteProperty(BeanId id, String propName) { Query query = getEmOrFail().createNamedQuery(DELETE_PROPERTY_FOR_BEANID_NAME); query.setParameter(1, id.getInstanceId()); query.setParameter(2, id.getSchemaName()); query.setParameter(3, propName); query.executeUpdate(); }
public static void deleteReference(BeanId id, String propName) { Query query = getEm().createNamedQuery(DELETE_REF_USING_PROPNAME_NAME); query.setParameter(1, id.getInstanceId()); query.setParameter(2, id.getSchemaName()); query.setParameter(3, propName); query.executeUpdate(); }
public static Bean deleteJpaBean(BeanId id) { Bean bean = findEager(id); deletePropertiesAndMarker(id); deleteReferences(id); Query query = getEmOrFail().createNamedQuery(DELETE_BEAN_USING_BEANID_NAME); query.setParameter(1, id.getInstanceId()); query.setParameter(2, id.getSchemaName()); query.executeUpdate(); return bean; }
public static boolean exists(BeanId id) { Query query = getEmOrFail().createNamedQuery(FIND_BEAN_FROM_BEANID_NAME); query.setParameter(1, id.getInstanceId()); query.setParameter(2, id.getSchemaName()); try { query.getSingleResult(); } catch (NoResultException e) { return false; } return true; }
@Test public void test_set_get_list() { createDefault(); Grandfather empty_g1 = new Grandfather("g1"); Grandfather empty_g2 = new Grandfather("g2"); Collection<Bean> empty_expect = toBeans(empty_g1, empty_g2); admin.set(empty_expect); Collection<Bean> empty_result = admin.list(empty_g1.getId().getSchemaName()); assertReflectionEquals(empty_expect, empty_result, LENIENT_ORDER); runtimeAllAndAssert(empty_g1.getClass(), empty_g1, empty_g2); }
@Test public void test_set_get_list() { createDefault(); Grandfather empty_g1 = new Grandfather("g1"); Grandfather empty_g2 = new Grandfather("g2"); Collection<Bean> empty_expect = toBeans(empty_g1, empty_g2); admin.set(empty_expect); Collection<Bean> empty_result = admin.list(empty_g1.getId().getSchemaName()); assertReflectionEquals(empty_expect, empty_result, LENIENT_ORDER); runtimeAllAndAssert(empty_g1.getClass(), empty_g1, empty_g2); }
private static void checkCreateSingleton(Bean bean, Map<BeanId, Bean> storage) { for (Bean b : storage.values()) { if (bean.getId().getSchemaName().equals(b.getId().getSchemaName())) { if (b.getId().isSingleton()) { throw CFG308_SINGELTON_CREATION(bean.getId()); } } } }
@Override public Map<BeanId, Bean> list(String name) { Map<BeanId, Bean> all = readValuesAsMap(); Map<BeanId, Bean> result = new HashMap<BeanId, Bean>(); for (Bean b : all.values()) { if (b.getId().getSchemaName().equals(name)) { Bean bean = getEagerly(b.getId(), all); result.put(bean.getId(), bean); } } return result; }
public static void deleteReferences(BeanId id) { Query query = getEm().createNamedQuery(DELETE_REF_USING_BEANID_NAME); query.setParameter(1, id.getInstanceId()); query.setParameter(2, id.getSchemaName()); query.executeUpdate(); }
JpaProperty(BeanId owner, String name, String value) { this.uuid = UUID.randomUUID().toString(); this.id = owner.getInstanceId(); this.schemaName = owner.getSchemaName(); this.propName = name; this.value = value; }
/** * Delete list properties EXCEPT the marker. This is useful for 'set' operations * that need to clear existing properties. */ public static void deleteProperties(BeanId id) { Query query = getEmOrFail().createNamedQuery(DELETE_ALL_PROPERTIES_FOR_BEANID_NAME); query.setParameter(1, id.getInstanceId()); query.setParameter(2, id.getSchemaName()); query.setParameter(3, BEAN_MARKER_PROPERTY_NAME); query.executeUpdate(); }
@Test public void test_delete_beans() { createDefault(); admin.delete(g1.getId().getSchemaName(), Arrays.asList("g1", "g2")); List<Bean> result = admin.list(g1.getId().getSchemaName()); assertThat(result.size(), is(0)); }
public void cache(Bean bean) { if(!configQueryFeatureEnabled) { return; } if(!cacheManager.isPresent()) { throw new IllegalArgumentException("A cache manager is needed to to queries."); } ConfigIndexedCollection col = indexCollections.get(bean.getId().getSchemaName()); col.add(bean); cacheManager.get().put(bean); }
public void cacheRemove(BeanId beanId) { if(!configQueryFeatureEnabled) { return; } if(!cacheManager.isPresent()) { return; } cacheManager.get().remove(beanId); ConfigIndexedCollection col = indexCollections.get(beanId.getSchemaName()); col.remove(beanId); }
public JpaRef(BeanId source, BeanId target, String propName) { this.sourceId = source.getInstanceId(); this.sourceSchemaName = source.getSchemaName(); this.targetId = target.getInstanceId(); this.targetSchemaName = target.getSchemaName(); this.propertyName = propName; this.id = UUID.randomUUID().toString(); }
public JpaPropertyPk(BeanId id, String propName) { this.propName = propName; this.id = id.getInstanceId(); this.schemaName = id.getSchemaName(); }
@Test public void test_delete_beans() { createDefault(); admin.delete(g1.getId().getSchemaName(), Arrays.asList("g1", "g2")); List<Bean> result = admin.list(g1.getId().getSchemaName()); assertThat(result.size(), is(0)); }
public JpaRef(JpaBean source, JpaBean target, String propName) { this.sourceId = source.getId().getInstanceId(); this.sourceSchemaName = source.getId().getSchemaName(); this.targetId = target.getId().getInstanceId(); this.targetSchemaName = target.getId().getSchemaName(); this.propertyName = propName; this.id = UUID.randomUUID().toString(); }
@Override public Map<BeanId, Bean> list(String name) { Map<BeanId, Bean> result = new HashMap<>(); for (Bean b : storage.all()) { if (b.getId().getSchemaName().equals(name)) { Optional<Bean> bean = getEagerly(b.getId()); result.put(bean.get().getId(), bean.get()); } } return result; }