@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; } }
/** * 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; }
/** * Saves the object, but only if not already {@link #isPersistent() * persistent}. * * @see #isPersistent() * @see #persist(Object) */ @Hidden protected void persistIfNotAlready(final Object domainObject) { getContainer().persistIfNotAlready(domainObject); }
/** * 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; }
@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; }