0 votes
asked in MicroStream for Java by (590 points)
edited by

I created a microstream table and a dao-class.
I used by copy&paste the same code, like I did several times before.
On all other locations where i use the code it works fine.
Suddenly, when I try to add some lines I got the error: "java.lang.UnsupportedOperationException"

1) Part of my dao-class:

 

public class MsToolsDAO
{
	
	public static List<MsTools> findALL()
	{
		return DbHandler.getRoot().getAllMsTools();
	}

	public static void insert(final MsTools myMsTools)
	{
		List<MsTools> myAllMsTools = new ArrayList<>();
		myAllMsTools = MsToolsDAO.findALL();
--->		myAllMsTools.add(myMsTools);
                DbHandler.getStoragemanager().store(myAllMsTools);

		// MsToolsDAO.findALL().add(myMsTools);
		// DbHandler.getStoragemanager().store(MsToolsDAO.findALL());
	}
}

The line with the arrow marks the position where the error occours
The line with the comments // are the lines which I use regulary.
I changed it to figure out where the error occours.

My Entity class:

public class MsTools implements java.io.Serializable
{
	
	private Integer id;
	private Integer PlattformId;
	private String  Toolname;
	private Integer ToolOwnerId;

	public MsTools()
	{
		super();

	}

	public static MsTools New(
		final Integer id,
		final Integer plattformId,
		final String toolname,
		final Integer toolOwnerId)
	{
		
		final MsTools mst = new MsTools();
		mst.setId(id);
		mst.setPlattformId(plattformId);
		mst.setToolname(toolname);
		mst.setToolOwnerId(toolOwnerId);
		
		return mst;
	}
	
	public Integer getId()
	{
		return this.id;
	}
	
	public void setId(final Integer id)
	{
		this.id = id;
	}
	
	public Integer getPlattformId()
	{
		return this.PlattformId;
	}
	
	public void setPlattformId(final Integer plattformId)
	{
		this.PlattformId = plattformId;
	}
	
	public String getToolname()
	{
		return this.Toolname;
	}
	
	public void setToolname(final String toolname)
	{
		this.Toolname = toolname;
	}
	
	public Integer getToolOwnerId()
	{
		return this.ToolOwnerId;
	}
	
	public void setToolOwnerId(final Integer toolOwnerId)
	{
		this.ToolOwnerId = toolOwnerId;
	}
	
}

 

My Code which I use to trigger insert:
 

private void btnSave_onClick(final ClickEvent<Button> event)
	{
		try
		{
			final MsTools msTid = new MsTools();

			msTid.setPlattformId(this.nrPlattformId.getValue().intValue());
			msTid.setToolOwnerId(this.nrToolOwnerId.getValue().intValue());
			msTid.setToolname(this.txtToolname.getValue());

			if(!this.nrId.isEmpty())
			{
				this.logger
					.info("Der Datensatz mit der ID soll gespeichert/aktualisiert werden: " + this.nrId.getValue());
				msTid.setId(this.nrId.getValue().intValue());
				MsToolsDAO.update(msTid);

			}
			else
			{
				final Integer newId = MsToolsDAO.getNextMsToolsId() + 1;
				msTid.setId(newId); // generiere eine neue id
				MsToolsDAO.findALL().stream()
					.forEach(c -> System.out.println(c + " id: " + c.getId() + " Name: " + c.getToolname()));

--->				MsToolsDAO.insert(msTid);

			}
			MsToolsDAO.save(msTid);

			this.binderTools.readBean(null);
			this.frmTools.setVisible(false);
			this.btnSave.setVisible(false);
			this.btnDelete.setVisible(false);

		}
		catch(final Exception e)
		{
			e.printStackTrace();

			final DialogErrorOccured MyErrorHandling = new DialogErrorOccured();
			this.binderTools.readBean(null);
			MyErrorHandling.errorDialog(e, this.getClass());

		}

		this.grdTools.setDataProvider(DataProvider.ofCollection(MsToolsDAO.findALL()));
		this.grdTools.getDataProvider().refreshAll();

	}

The line with the arrow marks the line where I call my dao.insert

I use microstream version 4:
 

</dependency>
		    <dependency>
        <groupId>one.microstream</groupId>
        <artifactId>storage.embedded</artifactId>
        <version>04.00.00-MS-GA</version>
</dependency>
<dependency>
        <groupId>one.microstream</groupId>
        <artifactId>storage.embedded.configuration</artifactId>
        <version>04.00.00-MS-GA</version>
 </dependency>

I deleted the whole database several times and created it new - without success.
The table contains 8 datarows, which I created by a mockup.
My MockUp Class:
 

public class MockupTools
{

	public static void init()
	{
		MockupTools.mockItUp();
	}

	private static void mockItUp()
	{
		// id, PlattformId, ToolName, ToolOwnerID
		final MsTools myTools = MsTools.New(1, 1, "NGK", 1); // PUR-PL
		final MsTools myTools1 = MsTools.New(2, 2, "PNFC", 41); // PUR-MCR
		final MsTools myTools2 = MsTools.New(3, 3, "APN", 25); // PILUM
		final MsTools myTools3 = MsTools.New(4, 3, "TLMS", 27); // PUR-PDM
		final MsTools myTools4 = MsTools.New(5, 5, "MDM", 41); // OneControlling
		final MsTools myTools5 = MsTools.New(6, 5, "OneCon BI Selfservice ", 43); // Bi-Factory
		final MsTools myTools6 = MsTools.New(7, 1, "Capri", 42); // PUR-PL
		final MsTools myTools7 = MsTools.New(8, 2, "YTD", 45); // PUR-MCR

		DbHandler.getRoot().setAllMsTools(Arrays.asList(
			myTools,
			myTools1,
			myTools2,
			myTools3,
			myTools4,
			myTools5,
			myTools6,
			myTools7));

		DbHandler.getStoragemanager().store(DbHandler.getRoot().getAllMsTools());
		DbHandler.getStoragemanager().storeRoot();

	}

}

 

Perhaps I did somewhere a typo, but I could not find.
Any help is appreciated

The stacktrace:
 

java.lang.UnsupportedOperationException
	at java.base/java.util.AbstractList.add(AbstractList.java:153)
	at java.base/java.util.AbstractList.add(AbstractList.java:111)
	at com.rieder.powerkiss.msDal.MsToolsDAO.insert(MsToolsDAO.java:86)
	at com.rieder.powerkiss.ui.ManageTools.btnSave_onClick(ManageTools.java:254)
	at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205)
	at com.vaadin.flow.component.ComponentEventBus.handleDomEvent(ComponentEventBus.java:373)
	at com.vaadin.flow.component.ComponentEventBus.lambda$addDomTrigger$dd1b7957$1(ComponentEventBus.java:264)
	at com.vaadin.flow.internal.nodefeature.ElementListenerMap.lambda$fireEvent$2(ElementListenerMap.java:441)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at com.vaadin.flow.internal.nodefeature.ElementListenerMap.fireEvent(ElementListenerMap.java:441)
	at com.vaadin.flow.server.communication.rpc.EventRpcHandler.handleNode(EventRpcHandler.java:59)
	at com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler.handle(AbstractRpcInvocationHandler.java:64)
	at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocationData(ServerRpcHandler.java:409)
	at com.vaadin.flow.server.communication.ServerRpcHandler.lambda$handleInvocations$1(ServerRpcHandler.java:390)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:390)
	at com.vaadin.flow.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:317)
	at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:89)
	at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
	at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1540)
	at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:247)
	at com.rapidclipse.framework.server.RapServlet.service(RapServlet.java:159)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:834)

 

1 Answer

+1 vote
answered by (800 points)
selected by
 
Best answer
Arrays.asList(...) creates an unmodifiable list. So add(...) throws an UnsupportedOperationException.

Just use ArrayList then the problem will be gone.
Notes: Every question must be a separate forum post. Headline: Formulate your question shortly and precisely. Thank you!
Powered by Question2Answer
...