Search in sources :

Example 1 with PersistenceUnitModel

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

the class PersistencePresenterTest method newPersistenceDescriptorEditorContent.

private PersistenceDescriptorEditorContent newPersistenceDescriptorEditorContent() {
    final PersistenceDescriptorEditorContent content = new PersistenceDescriptorEditorContent();
    final PersistenceDescriptorModel model = new PersistenceDescriptorModel();
    model.setVersion("2.0");
    final PersistenceUnitModel unitModel = new PersistenceUnitModel();
    model.setPersistenceUnit(unitModel);
    unitModel.setName("UnitName");
    unitModel.setTransactionType(TransactionType.JTA);
    unitModel.setProvider("ProviderClass");
    unitModel.setJtaDataSource("JTADataSource");
    unitModel.setClasses(Arrays.asList("Class1", "Class2"));
    content.setDescriptorModel(model);
    content.setOverview(new Overview());
    return content;
}
Also used : PersistenceUnitModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceUnitModel) PersistenceDescriptorEditorContent(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorEditorContent) Overview(org.guvnor.common.services.shared.metadata.model.Overview) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel)

Example 2 with PersistenceUnitModel

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

the class PersistenceDescriptorXMLMarshallerTest method expectedDescriptor.

private PersistenceDescriptorModel expectedDescriptor() {
    PersistenceDescriptorModel descriptor = new PersistenceDescriptorModel();
    descriptor.setVersion("2.1");
    PersistenceUnitModel persistenceUnit = new PersistenceUnitModel();
    descriptor.setPersistenceUnit(persistenceUnit);
    persistenceUnit.setName("org.test.persistence-unit");
    persistenceUnit.setDescription("org.test.description");
    persistenceUnit.setProvider("org.test.Provider");
    persistenceUnit.setJtaDataSource("java:jboss/datasources/ExampleDS");
    persistenceUnit.getMappingFile().add("META-INF/Mapping1.xml");
    persistenceUnit.getMappingFile().add("META-INF/Mapping2.xml");
    persistenceUnit.getJarFile().add("file1.jar");
    persistenceUnit.getJarFile().add("file2.jar");
    persistenceUnit.getClasses().add("org.test.Entity1");
    persistenceUnit.getClasses().add("org.test.Entity2");
    persistenceUnit.setExcludeUnlistedClasses(true);
    persistenceUnit.setSharedCacheMode(CachingType.ALL);
    persistenceUnit.setValidationMode(ValidationMode.AUTO);
    persistenceUnit.setTransactionType(TransactionType.JTA);
    persistenceUnit.addProperty(new Property("property1", "property1_value"));
    persistenceUnit.addProperty(new Property("property2", "property2_value"));
    return descriptor;
}
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)

Example 3 with PersistenceUnitModel

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceUnitModel 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 4 with PersistenceUnitModel

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

the class PersistenceDescriptorValidatorImpl method validate.

@Override
public List<ValidationMessage> validate(Path path, PersistenceDescriptorModel model) {
    final List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    final KieModule module = moduleService.resolveModule(path);
    if (module == null) {
        // uncommon scenario, since by construction, the same as with other wb assets, a persistence descriptor
        // belongs to a module
        messages.add(newErrorMessage(PersistenceDescriptorValidationMessages.DESCRIPTOR_NOT_BELONG_TO_PROJECT_ID, PersistenceDescriptorValidationMessages.DESCRIPTOR_NOT_BELONG_TO_PROJECT));
        return messages;
    }
    if (model.getPersistenceUnit() == null) {
        messages.add(newErrorMessage(PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_NOT_FOUND_ID, PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_NOT_FOUND));
        return messages;
    }
    final PersistenceUnitModel unitModel = model.getPersistenceUnit();
    if (unitModel.getName() == null || unitModel.getName().trim().isEmpty()) {
        messages.add(newErrorMessage(PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_NAME_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_NAME_EMPTY));
    }
    if (unitModel.getProvider() == null || unitModel.getProvider().trim().isEmpty()) {
        messages.add(newErrorMessage(PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_PROVIDER_ID, PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_PROVIDER_EMPTY));
    }
    if (unitModel.getTransactionType() == null) {
        messages.add(newErrorMessage(PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_TRANSACTION_TYPE_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_TRANSACTION_TYPE_EMPTY));
    } else if (unitModel.getTransactionType() == TransactionType.JTA && (unitModel.getJtaDataSource() == null || unitModel.getJtaDataSource().trim().isEmpty())) {
        messages.add(newErrorMessage(PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_JTA_DATASOURCE_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_JTA_DATASOURCE_EMPTY));
    } else if (unitModel.getTransactionType() == TransactionType.RESOURCE_LOCAL && (unitModel.getNonJtaDataSource() == null || unitModel.getNonJtaDataSource().trim().isEmpty())) {
        messages.add(newErrorMessage(PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_NON_JTA_DATASOURCE_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTENCE_UNIT_NON_JTA_DATASOURCE_EMPTY));
    }
    if (unitModel.getClasses() != null && !unitModel.getClasses().isEmpty()) {
        ClassLoader moduleClassLoader = moduleClassLoaderHelper.getModuleClassLoader(module);
        unitModel.getClasses().forEach(clazz -> Optional.ofNullable(classValidator.validate(clazz, moduleClassLoader)).ifPresent(messages::addAll));
    }
    if (unitModel.getProperties() != null) {
        int[] index = { 1 };
        unitModel.getProperties().forEach(property -> messages.addAll(Optional.ofNullable(propertyValidator.validate(property.getName(), property.getValue(), index[0]++)).orElse(Collections.emptyList())));
    }
    return messages;
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) PersistenceUnitModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceUnitModel) ArrayList(java.util.ArrayList) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 5 with PersistenceUnitModel

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceUnitModel 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)

Aggregations

PersistenceUnitModel (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceUnitModel)7 PersistenceDescriptorModel (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel)5 Property (org.kie.workbench.common.screens.datamodeller.model.persistence.Property)3 ArrayList (java.util.ArrayList)2 KieModule (org.kie.workbench.common.services.shared.project.KieModule)2 Overview (org.guvnor.common.services.shared.metadata.model.Overview)1 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 PersistenceDescriptorEditorContent (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorEditorContent)1