Search in sources :

Example 11 with PersistenceDescriptorModel

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel in project kie-wb-common by kiegroup.

the class PersistenceDescriptorValidatorTest method createValidDescriptor.

private PersistenceDescriptorModel createValidDescriptor() {
    PersistenceDescriptorModel descriptor = new PersistenceDescriptorModel();
    descriptor.setVersion(VERSION);
    PersistenceUnitModel unit = new PersistenceUnitModel();
    descriptor.setPersistenceUnit(unit);
    unit.setJtaDataSource(JTA_DATASOURCE);
    unit.setName(PERSISTENCE_UNIT_NAME);
    unit.setProvider(PERSISTENCE_PROVIDER);
    unit.setTransactionType(TransactionType.JTA);
    List<Property> properties = new ArrayList<>();
    properties.add(new Property("name1", "value1"));
    properties.add(new Property("name2", "value2"));
    unit.setProperties(properties);
    List<String> classes = new ArrayList<>();
    classes.add(PersistableClass1.class.getName());
    classes.add(PersistableClass2.class.getName());
    classes.add(PersistableClass3.class.getName());
    descriptor.getPersistenceUnit().setClasses(classes);
    return descriptor;
}
Also used : PersistenceUnitModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceUnitModel) ArrayList(java.util.ArrayList) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel) Property(org.kie.workbench.common.screens.datamodeller.model.persistence.Property)

Example 12 with PersistenceDescriptorModel

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel in project kie-wb-common by kiegroup.

the class DOM2PersistenceDescriptorVisitor method visitPersistence.

private void visitPersistence(Element element) {
    descriptorModel = new PersistenceDescriptorModel();
    descriptorModel.setVersion(element.getAttribute(PersistenceDescriptorXMLMarshaller.VERSION));
    NodeList children = element.getElementsByTagName(PersistenceDescriptorXMLMarshaller.PERSISTENCE_UNIT);
    if (children != null && children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            visitPersistenceUnit((Element) children.item(i));
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel)

Example 13 with PersistenceDescriptorModel

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel in project kie-wb-common by kiegroup.

the class PersistenceDescriptorXMLMarshallerTest method writeToXMLTest.

@Ignore
public void writeToXMLTest() {
    try {
        PersistenceDescriptorModel descriptor = expectedDescriptor();
        String xml = PersistenceDescriptorXMLMarshaller.toXML(descriptor);
        StringBuilder expectedXml = new StringBuilder();
        InputStream in = getExpectedXML();
        byte[] buffer = new byte[1024];
        int size;
        while ((size = in.read(buffer)) != -1) {
            expectedXml.append(new String(buffer, 0, size, "UTF-8"));
        }
        assertEquals(expectedXml.toString(), xml);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : InputStream(java.io.InputStream) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel) Ignore(org.junit.Ignore)

Example 14 with PersistenceDescriptorModel

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel in project kie-wb-common by kiegroup.

the class DataModelerEventObserver method onDataObjectDeleted.

public void onDataObjectDeleted(@Observes DataObjectDeletedEvent event) {
    Path descriptorPath;
    PersistenceDescriptorModel persistenceDescriptor;
    descriptorPath = descriptorService.calculatePersistenceDescriptorPath(event.getCurrentModule());
    persistenceDescriptor = safeLoad(descriptorPath);
    if (persistenceDescriptor != null && containsClass(persistenceDescriptor.getPersistenceUnit(), event.getCurrentDataObject().getClassName())) {
        persistenceDescriptor.getPersistenceUnit().getClasses().remove(event.getCurrentDataObject().getClassName());
        descriptorService.save(descriptorPath, persistenceDescriptor, null, "Entity removed from persistence descriptor");
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel)

Example 15 with PersistenceDescriptorModel

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel in project kie-wb-common by kiegroup.

the class PersistenceDescriptorEditorServiceImpl method createIfNotExists.

public Pair<Path, Boolean> createIfNotExists(Path path) {
    if (ioService.notExists(Paths.convert(path))) {
        PersistenceDescriptorModel descriptorModel = descriptorService.createModuleDefaultDescriptor(path);
        Path createdPath = descriptorService.save(path, descriptorModel, null, "Default persistence descriptor generated by system");
        return new Pair<Path, Boolean>(createdPath, true);
    } else {
        // When the path was created manually it doesn't have the property.
        return new Pair<Path, Boolean>(Paths.normalizePath(path), false);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel) Pair(org.uberfire.commons.data.Pair)

Aggregations

PersistenceDescriptorModel (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel)16 Path (org.uberfire.backend.vfs.Path)7 Test (org.junit.Test)5 PersistenceUnitModel (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceUnitModel)5 Module (org.guvnor.common.services.project.model.Module)4 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)4 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)4 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)4 DataObjectCreatedEvent (org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent)3 Property (org.kie.workbench.common.screens.datamodeller.model.persistence.Property)3 PersistenceDescriptorEditorContent (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorEditorContent)2 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Overview (org.guvnor.common.services.shared.metadata.model.Overview)1 Ignore (org.junit.Ignore)1 DataObjectDeletedEvent (org.kie.workbench.common.screens.datamodeller.events.DataObjectDeletedEvent)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1 Pair (org.uberfire.commons.data.Pair)1 NodeList (org.w3c.dom.NodeList)1