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