use of org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence in project jbosstools-hibernate by jbosstools.
the class AddGeneratedClassesJob method runInWorkspace.
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
final SubMonitor sm = SubMonitor.convert(monitor, UIMessages.SYNC_CLASSES_TASK, 20);
final JptXmlResource resource = jpaProject.getPersistenceXmlResource();
if (resource == null) {
// the resource would only be null if the persistence.xml file had an invalid content type
return Status.OK_STATUS;
}
if (sm.isCanceled()) {
return Status.CANCEL_STATUS;
}
sm.worked(1);
XmlPersistence persistence = (XmlPersistence) resource.getRootObject();
XmlPersistenceUnit persistenceUnit;
if (persistence.getPersistenceUnits().size() > 0) {
persistenceUnit = persistence.getPersistenceUnits().get(0);
} else {
persistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit();
persistenceUnit.setName(jpaProject.getName());
persistence.getPersistenceUnits().add(persistenceUnit);
}
sm.worked(1);
IStatus status = addNewClassRefs(sm.newChild(17), jpaProject, persistenceUnit);
resource.save();
sm.done();
return status;
}
use of org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence in project jbosstools-hibernate by jbosstools.
the class JPAPostInstallFasetListener method exportConnectionProfilePropertiesToPersistenceXml.
private void exportConnectionProfilePropertiesToPersistenceXml(IProject project) {
PersistenceXmlResourceProvider defaultXmlResourceProvider = PersistenceXmlResourceProvider.getDefaultXmlResourceProvider(project);
final JptXmlResource resource = defaultXmlResourceProvider.getXmlResource();
Properties propsToAdd = getConnectionProperties(project);
if (propsToAdd.isEmpty() || resource == null)
return;
XmlPersistence persistence = (XmlPersistence) resource.getRootObject();
if (persistence.getPersistenceUnits().size() > 0) {
XmlPersistenceUnit persistenceUnit = persistence.getPersistenceUnits().get(0);
if (persistenceUnit.getProperties() == null) {
persistenceUnit.setProperties(PersistenceFactory.eINSTANCE.createXmlProperties());
for (Entry<Object, Object> entry : propsToAdd.entrySet()) {
XmlProperty prop = PersistenceFactory.eINSTANCE.createXmlProperty();
prop.setName((String) entry.getKey());
prop.setValue((String) entry.getValue());
persistenceUnit.getProperties().getProperties().add(prop);
}
}
}
resource.save();
}
use of org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence in project jbosstools-hibernate by jbosstools.
the class JPAPostInstallFasetListener method getPersistenceUnitName.
private String getPersistenceUnitName(IProject project) {
String result = null;
PersistenceXmlResourceProvider defaultXmlResourceProvider = PersistenceXmlResourceProvider.getDefaultXmlResourceProvider(project);
final JptXmlResource resource = defaultXmlResourceProvider.getXmlResource();
XmlPersistence persistence = (XmlPersistence) resource.getRootObject();
if (persistence.getPersistenceUnits().size() > 0) {
XmlPersistenceUnit persistenceUnit = persistence.getPersistenceUnits().get(0);
result = persistenceUnit.getName();
}
return result;
}
Aggregations