Search in sources :

Example 1 with XmlProperty

use of org.eclipse.jpt.jpa.core.resource.persistence.XmlProperty 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();
}
Also used : XmlPersistence(org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence) JptXmlResource(org.eclipse.jpt.common.core.resource.xml.JptXmlResource) XmlProperty(org.eclipse.jpt.jpa.core.resource.persistence.XmlProperty) PersistenceXmlResourceProvider(org.eclipse.jpt.jpa.core.internal.resource.persistence.PersistenceXmlResourceProvider) Properties(java.util.Properties) XmlPersistenceUnit(org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistenceUnit)

Aggregations

Properties (java.util.Properties)1 JptXmlResource (org.eclipse.jpt.common.core.resource.xml.JptXmlResource)1 PersistenceXmlResourceProvider (org.eclipse.jpt.jpa.core.internal.resource.persistence.PersistenceXmlResourceProvider)1 XmlPersistence (org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence)1 XmlPersistenceUnit (org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistenceUnit)1 XmlProperty (org.eclipse.jpt.jpa.core.resource.persistence.XmlProperty)1