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;
}
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()));
}
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());
}
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()));
}
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());
}
Aggregations