@SuppressWarnings("unchecked") @Override public Object newInstance(final Class cls, final Map attributes) throws InstantiationException, IllegalAccessException { return container.newTransientInstance(cls); } };
public List<Role> allRoles() { return container.allInstances(Role.class); }
protected UserMemento getUser() { return getContainer().getUser(); }
@Programmatic // for use by fixtures private ToDoItem newToDo( final String description, final Category category, final Subcategory subcategory, final String username, final LocalDate dueBy, final BigDecimal cost) { final ToDoItem toDoItem = container.newTransientInstance(ToDoItem.class); toDoItem.setDescription(description); toDoItem.setCategory(category); toDoItem.setSubcategory(subcategory); final ApplicationUser applicationUser = applicationUserRepository.findByUsername(username); final ApplicationTenancy applicationTenancy = applicationUser.getTenancy(); if(applicationTenancy == null) { throw new IllegalStateException(String.format("No application tenancy defined for user '%s'", username)); } toDoItem.setAtPath(applicationTenancy.getPath()); toDoItem.setDueBy(dueBy); toDoItem.setCost(cost); container.persist(toDoItem); container.flush(); return toDoItem; }
/** * Create simple object */ @Action(domainEvent = CreateDomainEvent.class) @MemberOrder(sequence = "3") public SimpleObject create(@ParameterLayout(named = "Name") final String name) { final SimpleObject obj = container.newTransientInstance(SimpleObject.class); obj.setName(name); container.persistIfNotAlready(obj); return obj; }
/** * @deprecated - use {@link org.apache.isis.applib.services.repository.RepositoryService#allMatches(Class, Predicate, long...)}. */ @Deprecated protected <T> List<T> allMatches(final Class<T> ofType, final Filter<? super T> filter, long... range) { return getContainer().allMatches(ofType, filter, range); }
/** * Display the specified message to the user, in a non-intrusive fashion. */ protected void informUser(final String message) { getContainer().informUser(message); }
protected void injectServices() { if(container != null) { for (final ExceptionRecognizer ers : exceptionRecognizers) { container.injectServicesInto(ers); } } }
@Programmatic FixtureResult newFixtureResult(final FixtureScript script, final String subkey, final Object object, final boolean firstTime) { if(object == null) { return null; } if (object instanceof ViewModel || getContainer().isPersistent(object)) { // continue } else { switch(getNonPersistedObjectsStrategy()) { case PERSIST: getContainer().flush(); break; case IGNORE: return null; } } final FixtureResult fixtureResult = new FixtureResult(); fixtureResult.setFixtureScriptClassName(firstTime ? script.getClass().getName() : null); fixtureResult.setFixtureScriptQualifiedName(script.getQualifiedName()); fixtureResult.setKey(script.pathWith(subkey)); fixtureResult.setObject(object); return fixtureResult; }
@SuppressWarnings("unchecked") @Override protected Object createNode(final Object arg0, final Map arg1, final Object arg2) { final Object domainObject = super.createNode(arg0, arg1, arg2); container.persistIfNotAlready(domainObject); return domainObject; } }
@Override public Object route(final Object original) { if(original != null) { return original; } // ensure that any persisted objects have been deleted. container.flush(); final BreadcrumbModelProvider wicketSession = (BreadcrumbModelProvider) AuthenticatedWebSession.get(); final BreadcrumbModel breadcrumbModel = wicketSession.getBreadcrumbModel(); final List<EntityModel> breadcrumbs = breadcrumbModel.getList(); final Optional<Object> firstViewModelOrNonDeletedPojoIfAny = breadcrumbs.stream() .filter(entityModel -> entityModel != null).map(EntityModel::getObject) .filter(objectAdapter -> objectAdapter != null).map(ObjectAdapter::getObject) .filter(pojo -> !(pojo instanceof Persistable) || !((Persistable)pojo).dnIsDeleted()) .findFirst(); return firstViewModelOrNonDeletedPojoIfAny.orElse(homePage()); }
public void update(final Object object) { getContainer().objectChanged(object); }
@Override public boolean accept(final Object t) { return getContainer().isPersistent(t); } };
@Override public DomainObjectContainer getContainer() { if(mockContainer == null) { mockContainer = getService(DomainObjectContainer.class); context.checking(new Expectations() { { allowing(mockContainer).newTransientInstance(with(Expectations.<Class<?>>anything())); will(new Action() { @SuppressWarnings("rawtypes") public Object invoke(Invocation invocation) throws Throwable { Class cls = (Class) invocation.getParameter(0); return scenarioExecution.injectServices(cls.newInstance()); } public void describeTo(Description description) { description.appendText("newTransientInstance"); } }); allowing(mockContainer).persistIfNotAlready(with(anything())); } }); } return mockContainer; }
/** * Convenience method that delegates to {@link DomainObjectContainer}. * * @see DomainObjectContainer#allMatches(Class, Filter) */ protected <T> List<T> allMatches(final Class<T> ofType, final Filter<? super T> filter) { return getContainer().allMatches(ofType, filter); }
/** * Display the specified i18n message to the user, in a non-intrusive fashion. * * <p> * The method simply delegates to the {@link DomainObjectContainer}. * </p> * * @see DomainObjectContainer#informUser(TranslatableString, Class, String) * * @deprecated - use {@link org.apache.isis.applib.services.message.MessageService#informUser(TranslatableString, Class, String)} */ @Deprecated protected void informUser(TranslatableString message, final Class<?> contextClass, final String contextMethod) { getContainer().informUser(message, contextClass, contextMethod); }
@Programmatic public F build( final FixtureScript parentFixtureScript, ExecutionContext executionContext) { final F onFixture = (F) BuilderScriptAbstract.this; parentFixtureScript.container.injectServicesInto(onFixture); execPrereqs(executionContext); // returns the fixture script that is run // (either this one, or possibly one previously executed). return (F)executionContext.executeChildT(parentFixtureScript, this); }
/** * Queues up a request to persist this object to the object store (as per {@link #persist(Object)}) (or do * nothing if the object is already {@link #isPersistent(Object) persistent}). * * <p> * It is recommended that the object be initially instantiated using * {@link #newTransientInstance(Class)}. However, the framework will also * handle the case when the object is simply <i>new()</i>ed up. See * {@link #newTransientInstance(Class)} for more information. * </p> * * <p> * The method simply delegates to the {@link DomainObjectContainer}. * </p> * * @see #newTransientInstance(Class) * @see #isPersistent(Object) * @see #persist(Object) * @see {@link DomainObjectContainer#persistIfNotAlready(Object)} * * @deprecated - use {@link org.apache.isis.applib.services.repository.RepositoryService#persist(Object)} or {@link org.apache.isis.applib.services.repository.RepositoryService#persistAndFlush(Object)} */ @Deprecated protected <T> T persistIfNotAlready(final T domainObject) { getContainer().persistIfNotAlready(domainObject); return domainObject; }
try { final IsisSystem isft = IsisSystem.get(); isft.getContainer().flush(); // don't care if npe isft.getService(IsisJdoSupport.class).getJdoPersistenceManager().flush(); } catch (Exception ignore) {
/** * This method does nothing (is a no-op). * * <p> * Previous this method was provided for manual control of object dirtyng; with the JDO/DataNucleus objectstore * that original functionality is performed automatically by the framework. * </p> * * @deprecated */ @Programmatic @Deprecated protected void objectChanged() { getContainer().objectChanged(this); }