|
Lines 12-17
Link Here
|
| 12 |
import org.eclipse.core.runtime.CoreException; |
12 |
import org.eclipse.core.runtime.CoreException; |
| 13 |
import org.eclipse.core.runtime.IProgressMonitor; |
13 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 14 |
import org.eclipse.jpt.core.internal.JpaModelManager; |
14 |
import org.eclipse.jpt.core.internal.JpaModelManager; |
|
|
15 |
import org.eclipse.jpt.core.internal.JptCorePlugin; |
| 15 |
import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal; |
16 |
import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal; |
| 16 |
import org.eclipse.jpt.core.internal.content.orm.OrmFactory; |
17 |
import org.eclipse.jpt.core.internal.content.orm.OrmFactory; |
| 17 |
import org.eclipse.jpt.core.internal.content.orm.OrmResource; |
18 |
import org.eclipse.jpt.core.internal.content.orm.OrmResource; |
|
Lines 21-33
Link Here
|
| 21 |
import org.eclipse.jpt.core.internal.content.persistence.PersistenceUnit; |
22 |
import org.eclipse.jpt.core.internal.content.persistence.PersistenceUnit; |
| 22 |
import org.eclipse.jpt.core.internal.content.persistence.resource.PersistenceArtifactEdit; |
23 |
import org.eclipse.jpt.core.internal.content.persistence.resource.PersistenceArtifactEdit; |
| 23 |
import org.eclipse.jpt.core.internal.content.persistence.resource.PersistenceResource; |
24 |
import org.eclipse.jpt.core.internal.content.persistence.resource.PersistenceResource; |
|
|
25 |
import org.eclipse.jst.j2ee.internal.J2EEConstants; |
| 26 |
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; |
| 24 |
import org.eclipse.wst.common.frameworks.datamodel.IDataModel; |
27 |
import org.eclipse.wst.common.frameworks.datamodel.IDataModel; |
|
|
28 |
import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; |
| 25 |
import org.eclipse.wst.common.project.facet.core.IDelegate; |
29 |
import org.eclipse.wst.common.project.facet.core.IDelegate; |
| 26 |
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
30 |
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
| 27 |
|
31 |
|
| 28 |
public class JpaFacetPostInstallDelegate |
32 |
public class JpaFacetPostInstallDelegate |
| 29 |
implements IDelegate, IJpaFacetDataModelProperties |
33 |
implements IDelegate, IJpaFacetDataModelProperties |
| 30 |
{ |
34 |
{ |
|
|
35 |
private final static String WEB_PROJECT_DEPLOY_PREFIX = J2EEConstants.WEB_INF_CLASSES; |
| 36 |
|
| 31 |
private final static String PERSISTENCE_XML_FILE_PATH = "META-INF/persistence.xml"; |
37 |
private final static String PERSISTENCE_XML_FILE_PATH = "META-INF/persistence.xml"; |
| 32 |
|
38 |
|
| 33 |
private final static String ORM_XML_FILE_PATH = "META-INF/orm.xml"; |
39 |
private final static String ORM_XML_FILE_PATH = "META-INF/orm.xml"; |
|
Lines 64-71
Link Here
|
| 64 |
} |
70 |
} |
| 65 |
|
71 |
|
| 66 |
private void createPersistenceXml(IProject project, IDataModel dataModel) { |
72 |
private void createPersistenceXml(IProject project, IDataModel dataModel) { |
|
|
73 |
String deployPath = PERSISTENCE_XML_FILE_PATH; |
| 74 |
try { |
| 75 |
if (FacetedProjectFramework.hasProjectFacet(project, IModuleConstants.JST_WEB_MODULE)) { |
| 76 |
deployPath = WEB_PROJECT_DEPLOY_PREFIX + "/" + deployPath; |
| 77 |
} |
| 78 |
} |
| 79 |
catch (CoreException ce) { |
| 80 |
// could not determine project facets. assume it doesn't have the facet. |
| 81 |
JptCorePlugin.log(ce); |
| 82 |
} |
| 83 |
|
| 67 |
PersistenceArtifactEdit pae = |
84 |
PersistenceArtifactEdit pae = |
| 68 |
PersistenceArtifactEdit.getArtifactEditForWrite(project, PERSISTENCE_XML_FILE_PATH); |
85 |
PersistenceArtifactEdit.getArtifactEditForWrite(project, deployPath); |
| 69 |
PersistenceResource resource = pae.getPersistenceResource(); |
86 |
PersistenceResource resource = pae.getPersistenceResource(); |
| 70 |
Persistence persistence = PersistenceFactory.eINSTANCE.createPersistence(); |
87 |
Persistence persistence = PersistenceFactory.eINSTANCE.createPersistence(); |
| 71 |
persistence.setVersion("1.0"); |
88 |
persistence.setVersion("1.0"); |
|
Lines 78-85
Link Here
|
| 78 |
} |
95 |
} |
| 79 |
|
96 |
|
| 80 |
private void createOrmXml(IProject project, IDataModel dataModel) { |
97 |
private void createOrmXml(IProject project, IDataModel dataModel) { |
|
|
98 |
String deployPath = ORM_XML_FILE_PATH; |
| 99 |
try { |
| 100 |
if (FacetedProjectFramework.hasProjectFacet(project, IModuleConstants.JST_WEB_MODULE)) { |
| 101 |
deployPath = WEB_PROJECT_DEPLOY_PREFIX + "/" + deployPath; |
| 102 |
} |
| 103 |
} |
| 104 |
catch (CoreException ce) { |
| 105 |
// could not determine project facets. assume it doesn't have the facet. |
| 106 |
JptCorePlugin.log(ce); |
| 107 |
} |
| 108 |
|
| 81 |
OrmArtifactEdit oae = |
109 |
OrmArtifactEdit oae = |
| 82 |
OrmArtifactEdit.getArtifactEditForWrite(project, ORM_XML_FILE_PATH); |
110 |
OrmArtifactEdit.getArtifactEditForWrite(project, deployPath); |
| 83 |
OrmResource resource = oae.getOrmResource(); |
111 |
OrmResource resource = oae.getOrmResource(); |
| 84 |
EntityMappingsInternal entityMappings = OrmFactory.eINSTANCE.createEntityMappingsInternal(); |
112 |
EntityMappingsInternal entityMappings = OrmFactory.eINSTANCE.createEntityMappingsInternal(); |
| 85 |
entityMappings.setVersion("1.0"); |
113 |
entityMappings.setVersion("1.0"); |