Skip to content
Snippets Groups Projects
Commit 38bb6fd0 authored by Chrissi's avatar Chrissi
Browse files

modeljoin dateien im code erzeugt

parent f8280c3b
Branches
No related tags found
No related merge requests found
natural join lib.Library with lib.Library as lib.Library {
keep attributes lib.Library.name
keep outgoing lib.Library.employees as type lib.Employee {
keep attributes lib.Employee.salary
keep outgoing lib.Employee.manager as type lib.Employee {
}
keep supertype lib.Person as type lib.Person {
keep attributes lib.Person.name
}
}
}
\ No newline at end of file
natural join lib.Library with lib.Library as lib.Library {
keep attributes lib.Library.name
keep outgoing lib.Library.employees as type lib.Employee {
keep attributes lib.Employee.salary
keep supertype lib.Person as type lib.Person {
keep attributes lib.Person.name
}
}
}
\ No newline at end of file
natural join lib.Employee with lib.Employee as lib.Employee {
keep attributes lib.Employee.salary
keep outgoing lib.Employee.manager as type lib.Employee {
}
keep supertype lib.Person as type lib.Person {
keep attributes lib.Person.name
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="Library" nsURI="http://www.example.org/library" nsPrefix="org.rosi_project.example.mm.lib">
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="Library" nsURI="http://www.example.org/library" nsPrefix="lib">
<eClassifiers xsi:type="ecore:EClass" name="Library">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="employees" upperBound="-1"
......
......@@ -12,7 +12,7 @@ import org.rosi_project.model_sync.model_join.representation.grammar.KeepReferen
import org.rosi_project.model_sync.model_join.representation.grammar.KeepSuperTypeExpression;
import org.rosi_project.model_sync.model_join.representation.grammar.KeepSuperTypeExpression.KeepSuperTypeBuilder;
import org.rosi_project.model_sync.model_join.representation.grammar.ModelJoinExpression;
import org.rosi_project.model_sync.model_join.representation.grammar.ThetaJoinExpression;
import org.rosi_project.model_sync.model_join.representation.util.JoinFactory.NaturalJoinBuilder;
import org.rosi_project.model_sync.model_join.representation.util.JoinFactory.ThetaJoinBuilder;
/**
......@@ -26,6 +26,10 @@ public class ModelJoinBuilder {
public static ThetaJoinBuilder thetaJoin() {
return JoinFactory.createNew().theta();
}
public static NaturalJoinBuilder naturalJoin() {
return JoinFactory.createNew().natural();
}
public static KeepAttributesExpression attributes(AttributePath firstAttribute, AttributePath... moreAttributes) {
return KeepAttributesExpression.keepAttributes(firstAttribute, moreAttributes);
......
......@@ -14,7 +14,7 @@ import org.rosi_project.model_sync.model_join.representation.grammar.ModelJoinEx
*
* @author Rico Bergmann
*/
class FileBasedModelJoinWriter implements ModelJoinWritingService<Boolean> {
public class FileBasedModelJoinWriter implements ModelJoinWritingService<Boolean> {
private final File outputFile;
private final StringBasedModelJoinWriter toStringWriter;
......@@ -24,7 +24,7 @@ class FileBasedModelJoinWriter implements ModelJoinWritingService<Boolean> {
*
* @param outputFile the file to write to
*/
FileBasedModelJoinWriter(@Nonnull File outputFile) {
public FileBasedModelJoinWriter(@Nonnull File outputFile) {
this.outputFile = outputFile;
this.toStringWriter = StringBasedModelJoinWriter.withNewlines();
}
......
package org.rosi_project.model_sync.modelrepresentation;
import static org.rosi_project.model_sync.model_join.representation.util.ModelJoinBuilder.attributes;
import static org.rosi_project.model_sync.model_join.representation.util.ModelJoinBuilder.outgoing;
import static org.rosi_project.model_sync.model_join.representation.util.ModelJoinBuilder.supertype;
import static org.rosi_project.model_sync.model_join.representation.util.ModelJoinBuilder.thetaJoin;
import static org.rosi_project.model_sync.model_join.representation.util.ModelJoinBuilder.naturalJoin;
import java.io.File;
import org.rosi_project.model_sync.model_join.representation.core.AttributePath;
import org.rosi_project.model_sync.model_join.representation.core.ClassResource;
import org.rosi_project.model_sync.model_join.representation.grammar.JoinExpression;
import org.rosi_project.model_sync.model_join.representation.grammar.KeepAttributesExpression;
import org.rosi_project.model_sync.model_join.representation.grammar.KeepExpression;
import org.rosi_project.model_sync.model_join.representation.grammar.ModelJoinExpression;
import org.rosi_project.model_sync.model_join.representation.util.JoinFactory;
import org.rosi_project.model_sync.model_join.representation.util.ModelJoinBuilder;
import org.rosi_project.model_sync.model_join.representation.writer.*;
public class ModelJoinCreation {
public static void main(String[] args) {
// TODO Auto-generated method stub
ClassResource person = ClassResource.fromQualifiedName("contact.Person");
/*ClassResource person = ClassResource.fromQualifiedName("contact.Person");
ClassResource employee = ClassResource.fromQualifiedName("company.Employee");
AttributePath dateOfBirth = AttributePath.from(person, "dateOfBirth");
......@@ -33,8 +37,95 @@ public class ModelJoinCreation {
for (KeepExpression k: j.getKeeps()) {
System.out.println(k);
}
}
}*/
ClassResource library = ClassResource.from("lib", "Library");
ClassResource employee = ClassResource.from("lib", "Employee");
ClassResource person = ClassResource.from("lib", "Person");
//ClassResource jointargetMovie = ClassResource.from("jointarget", "Movie");
//ClassResource jointargetVote = ClassResource.from("jointarget", "Vote");
//ClassResource jointargetMediaItem = ClassResource.from("jointarget", "MediaItem");
AttributePath libraryName = AttributePath.from(library, "name");
AttributePath libraryEmployees = AttributePath.from(library, "employees");
AttributePath employeeSalary = AttributePath.from(employee, "salary");
AttributePath employeeManager = AttributePath.from(employee, "manager");
AttributePath personName = AttributePath.from(person, "name");
ModelJoinExpression mjManager = ModelJoinBuilder.createNewModelJoin()
.add(naturalJoin()
.join(employee)
.with(employee)
.as(employee)
.keep(attributes(employeeSalary))
.keep(outgoing(employeeManager)
.as(employee)
.buildExpression()
)
.keep(supertype(person)
.as(person)
.keep(attributes(personName))
.buildExpression()
)
.done())
.build();
ModelJoinExpression mjComplete = ModelJoinBuilder.createNewModelJoin()
.add(naturalJoin()
.join(library)
.with(library)
.as(library)
.keep(attributes(libraryName))
.keep(outgoing(libraryEmployees)
.as(employee)
.keep(attributes(employeeSalary))
.keep(outgoing(employeeManager)
.as(employee)
.buildExpression()
)
.keep(supertype(person)
.as(person)
.keep(attributes(personName))
.buildExpression()
)
.buildExpression()
)
.done())
.build();
ModelJoinExpression mjSimple = ModelJoinBuilder.createNewModelJoin()
.add(naturalJoin()
.join(library)
.with(library)
.as(library)
.keep(attributes(libraryName))
.keep(outgoing(libraryEmployees)
.as(employee)
.keep(attributes(employeeSalary))
.keep(supertype(person)
.as(person)
.keep(attributes(personName))
.buildExpression()
)
.buildExpression()
)
.done())
.build();
File fileComplete = new File("libraryComplete.modeljoin");
File fileSimple = new File("librarySimple.modeljoin");
File fileManager = new File("manager.modeljoin");
//registerCreatedFile(outputFile);
FileBasedModelJoinWriter writerComplete = new FileBasedModelJoinWriter(fileComplete);
writerComplete.write(mjComplete);
FileBasedModelJoinWriter writerSimple = new FileBasedModelJoinWriter(fileSimple);
writerSimple.write(mjSimple);
FileBasedModelJoinWriter writerManager = new FileBasedModelJoinWriter(fileManager);
writerManager.write(mjManager);
}
}
......@@ -31,7 +31,9 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
val joinType = STypeRegistry.query(j.getTarget.getResourceName, j.getTarget.getResourcePath)
if (!joinType.isEmpty) {
viewCompartment.addJoinObject(joinType.get.asInstanceOf[SJoinClass])
if (joinType.get.isInstanceOf[SJoinClass]) {
viewCompartment.addJoinObject(joinType.get.asInstanceOf[SJoinClass])
}
createClasses(asScalaBuffer(j.getKeepsList).toSet, joinType.get.asInstanceOf[SClass], sModel)
}
......
......@@ -7,7 +7,8 @@ import org.rosi_project.model_sync.generator.Creation
object ApplicationTest extends App {
runCombinedTest(Creation.rolesum)
runTestLibrary(Creation.rolesum)
//runCombinedTest(Creation.rolesum)
//runShrinkingModel(Creation.rolesum)
//runTestAML(Creation.rolesum)
......@@ -85,7 +86,7 @@ object ApplicationTest extends App {
}
def runTestLibrary(cre: Creation.Value): Unit = {
var config: GeneratorConfig = GeneratorConfig(Seq("assets/models/Library.ecore"), false, new File("assets/models"));
var config: GeneratorConfig = GeneratorConfig(Seq("assets/models/Library.ecore"), false, new File("assets/models"), modelJoin = "assets/model_join/manager.modeljoin");
config.setCreate(cre)
new Generator(config).run()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment