Skip to content
Snippets Groups Projects
Commit 6faf8608 authored by Simon Spinner's avatar Simon Spinner
Browse files

Add ID retrieval methods to ModelRepository interface.

parent a3352811
No related branches found
No related tags found
No related merge requests found
package tools.descartes.prisma.core;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -127,19 +126,13 @@ public class TestModelRepository implements ModelRepository {
}
@Override
public Map<String, String> loadPropertiesFile(String path) throws IOException {
Node curNode = findNode(path, null);
if (curNode != null) {
return curNode.properties;
}
return null;
public Object getInstance(Object id) {
return id;
}
@Override
public void storePropertiesFile(Transaction transaction, String path, Map<String, String> properties)
throws IOException {
Node curNode = findNode(path, (TestTransaction) transaction);
curNode.properties = properties;
public Object getInstanceID(Object object) {
return object;
}
@Override
......
package tools.descartes.prisma.core;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.ecore.resource.Resource;
......@@ -31,13 +29,11 @@ public interface ModelRepository {
public Transaction createTransaction();
public Map<String, String> loadPropertiesFile(String path) throws IOException;
public void storePropertiesFile(Transaction transaction, String path, Map<String, String> properties)
throws IOException;
public void waitForUpdate();
public <T> List<T> query(String query, Object context, Class<T> resultType);
public Object getInstanceID(Object object);
public Object getInstance(Object id);
}
......@@ -5,12 +5,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.eclipse.emf.cdo.common.lob.CDOClobWriter;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.eresource.CDOTextResource;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOAdapterPolicy;
import org.eclipse.emf.cdo.view.CDOQuery;
......@@ -175,32 +174,13 @@ public class CDOModelRepository implements ModelRepository {
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<String, String> loadPropertiesFile(String path) throws IOException {
Properties containerProperties = new Properties();
CDOTextResource textFile = readOnlyView.getTextResource(path);
containerProperties.load(textFile.getContents().getContents());
// Awkward cast required here due to problems in Java API
return (Map) containerProperties;
public Object getInstanceID(Object object) {
return ((CDOObject) object).cdoID();
}
@Override
public void storePropertiesFile(Transaction transaction, String path, Map<String, String> properties)
throws IOException {
CDOTransaction cdoTransaction = checkTransaction(transaction);
// Save the properties in a text file for later retrieval
CDOTextResource propRes = cdoTransaction.getOrCreateTextResource(path);
transaction.lock(propRes, LockType.WRITE);
Properties prop = new Properties();
prop.putAll(properties);
CDOClobWriter writer = new CDOClobWriter();
try {
prop.store(writer, "");
} finally {
writer.close();
}
propRes.setContents(writer.getClob());
public Object getInstance(Object id) {
return readOnlyView.getObject((CDOID) id);
}
public Transaction createTransaction() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment