Search in sources :

Example 6 with PersistenceDescriptorModel

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

the class PersistenceDescriptorServiceImpl method createModuleDefaultDescriptor.

@Override
public PersistenceDescriptorModel createModuleDefaultDescriptor(final Path path) {
    KieModule module = moduleService.resolveModule(path);
    if (module == null) {
        return null;
    }
    // TODO read default descriptor parameters from a configuration/template.
    // We can basically copy the configuration from WEB-INF/classes/META-INF/persistence.xml file
    // since this file will always exist for a kie-wb installation.
    // This default values are taken from "org.jbpm.domain" persistence unit shipped by default with kie-wb-distributions
    PersistenceDescriptorModel descriptorModel = new PersistenceDescriptorModel();
    descriptorModel.setVersion("2.0");
    PersistenceUnitModel unitModel = new PersistenceUnitModel();
    descriptorModel.setPersistenceUnit(unitModel);
    unitModel.setName(module.getPom().getGav().toString());
    unitModel.setTransactionType(TransactionType.JTA);
    unitModel.setProvider("org.hibernate.jpa.HibernatePersistenceProvider");
    unitModel.setJtaDataSource("java:jboss/datasources/ExampleDS");
    unitModel.addProperty(new Property("hibernate.dialect", "org.hibernate.dialect.H2Dialect"));
    unitModel.addProperty(new Property("hibernate.max_fetch_depth", "3"));
    unitModel.addProperty(new Property("hibernate.hbm2ddl.auto", "update"));
    unitModel.addProperty(new Property("hibernate.show_sql", "false"));
    // <!-- BZ 841786: AS7/EAP 6/Hib 4 uses new (sequence) generators which seem to cause problems -->
    unitModel.addProperty(new Property("hibernate.id.new_generator_mappings", "false"));
    unitModel.addProperty(new Property("hibernate.transaction.jta.platform", "org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"));
    // use only entities configured by the user, avoiding in this way that classes in the project classpath (e.g, from dependencies)
    // to be included in the EntityManager
    unitModel.setExcludeUnlistedClasses(true);
    return descriptorModel;
}
Also used : PersistenceUnitModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceUnitModel) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel) Property(org.kie.workbench.common.screens.datamodeller.model.persistence.Property) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 7 with PersistenceDescriptorModel

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

the class DataModelerEventObserverTest method onPersistableDataObjectDeletedTest.

@Test
public void onPersistableDataObjectDeletedTest() {
    DataModelerEventObserver eventObserver = createObserver();
    PersistenceDescriptorModel descriptorModel = createModel();
    descriptorModel.getPersistenceUnit().getClasses().add("package1.PersistableObject");
    DataObject dataObject = new DataObjectImpl("package1", "PersistableObject");
    dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Entity.class)));
    when(descriptorPath.toURI()).thenReturn(DESCRIPTOR_PATH);
    when(descriptorService.calculatePersistenceDescriptorPath(any(Module.class))).thenReturn(descriptorPath);
    when(descriptorService.load(descriptorPath)).thenReturn(descriptorModel);
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true);
    DataObjectDeletedEvent deletedEvent = new DataObjectDeletedEvent(module, dataObject);
    eventObserver.onDataObjectDeleted(deletedEvent);
    verify(descriptorService, times(1)).save(eq(descriptorPath), eq(descriptorModel), any(Metadata.class), anyString());
    assertFalse(descriptorModel.getPersistenceUnit().getClasses().contains(dataObject.getClassName()));
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) Path(org.uberfire.backend.vfs.Path) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel) DataObjectDeletedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectDeletedEvent) Module(org.guvnor.common.services.project.model.Module) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Test(org.junit.Test)

Example 8 with PersistenceDescriptorModel

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

the class DataModelerEventObserverTest method onNonPersistableDataObjectDeletedTest.

@Test
public void onNonPersistableDataObjectDeletedTest() {
    DataModelerEventObserver eventObserver = createObserver();
    PersistenceDescriptorModel descriptorModel = createModel();
    DataObject dataObject = new DataObjectImpl("package1", "NonPersistableObject");
    when(descriptorPath.toURI()).thenReturn(DESCRIPTOR_PATH);
    when(descriptorService.calculatePersistenceDescriptorPath(any(Module.class))).thenReturn(descriptorPath);
    when(descriptorService.load(descriptorPath)).thenReturn(descriptorModel);
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true);
    DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject);
    eventObserver.onDataObjectCreated(createdEvent);
    verify(descriptorService, times(0)).save(eq(descriptorPath), eq(descriptorModel), any(Metadata.class), anyString());
    assertEquals(0, descriptorModel.getPersistenceUnit().getClasses().size());
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) Path(org.uberfire.backend.vfs.Path) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataObjectCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

Example 9 with PersistenceDescriptorModel

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

the class DataModelerEventObserverTest method onPersistableDataObjectCreatedTest.

@Test
public void onPersistableDataObjectCreatedTest() {
    DataModelerEventObserver eventObserver = createObserver();
    PersistenceDescriptorModel descriptorModel = createModel();
    DataObject dataObject = new DataObjectImpl("package1", "PersistableObject");
    dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Entity.class)));
    when(descriptorPath.toURI()).thenReturn(DESCRIPTOR_PATH);
    when(descriptorService.calculatePersistenceDescriptorPath(any(Module.class))).thenReturn(descriptorPath);
    when(descriptorService.load(descriptorPath)).thenReturn(descriptorModel);
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true);
    DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject);
    eventObserver.onDataObjectCreated(createdEvent);
    verify(descriptorService, times(1)).save(eq(descriptorPath), eq(descriptorModel), any(Metadata.class), anyString());
    assertTrue(descriptorModel.getPersistenceUnit().getClasses().contains(dataObject.getClassName()));
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) Path(org.uberfire.backend.vfs.Path) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataObjectCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel) Module(org.guvnor.common.services.project.model.Module) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Test(org.junit.Test)

Example 10 with PersistenceDescriptorModel

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

the class DataModelerEventObserverTest method onNonPersistableDataObjectCreatedTest.

@Test
public void onNonPersistableDataObjectCreatedTest() {
    DataModelerEventObserver eventObserver = createObserver();
    PersistenceDescriptorModel descriptorModel = createModel();
    descriptorModel.getPersistenceUnit().getClasses().add("package1.PersistableObject");
    DataObject dataObject = new DataObjectImpl("package1", "NonPersistableObject");
    when(descriptorPath.toURI()).thenReturn(DESCRIPTOR_PATH);
    when(descriptorService.calculatePersistenceDescriptorPath(any(Module.class))).thenReturn(descriptorPath);
    when(descriptorService.load(descriptorPath)).thenReturn(descriptorModel);
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true);
    DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject);
    eventObserver.onDataObjectCreated(createdEvent);
    verify(descriptorService, times(0)).save(eq(descriptorPath), eq(descriptorModel), any(Metadata.class), anyString());
    assertEquals(1, descriptorModel.getPersistenceUnit().getClasses().size());
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) Path(org.uberfire.backend.vfs.Path) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataObjectCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

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