Skip to content

Commit

Permalink
Merge branch 'WINDUP-651' of https://github.com/bradsdavis/windup int…
Browse files Browse the repository at this point in the history
…o bradsdavis-WINDUP-651
  • Loading branch information
jsight committed Jun 17, 2015
2 parents e1f604d + 3019ae7 commit 22671b3
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 80 deletions.
Expand Up @@ -27,6 +27,18 @@ public interface HibernateSessionFactoryModel extends WindupVertexFrame
@Adjacency(label = HibernateConfigurationFileModel.HIBERNATE_SESSION_FACTORY, direction = Direction.IN)
HibernateConfigurationFileModel getHibernateConfigurationFileModel();

/**
* Contains a link back to the {@link DataSourceModel}
*/
@Adjacency(label = DataSourceModel.DATA_SOURCE, direction = Direction.OUT)
public Iterable<DataSourceModel> getDataSources();

/**
* Contains a link back to the {@link DataSourceModel}
*/
@Adjacency(label = DataSourceModel.DATA_SOURCE, direction = Direction.OUT)
void addDataSource(DataSourceModel dataSource);

/**
* Contains the hibernate session factories properties
*/
Expand Down
Expand Up @@ -17,13 +17,29 @@
@TypeValue(JPAEntityModel.TYPE)
public interface JPAEntityModel extends WindupVertexFrame
{
public static final String ENTITY_NAME = "entityName";
public static final String CATALOG_NAME = "catalogName";
public static final String SCHEMA_NAME = "schemaName";
public static final String TABLE_NAME = "tableName";
public static final String NAMED_QUERY = "namedQuery";
public static final String JPA_ENTITY_CLASS = "jpaEntityClass";
public static final String SPECIFICATION_VERSION = "specificationVersion";
public static final String TYPE = "JPAEntityModel";


/**
* Contains the entity name
*/
@Property(ENTITY_NAME)
public String getEntityName();

/**
* Contains the entity name
*/
@Property(ENTITY_NAME)
public void setEntityName(String entityName);


/**
* Contains the specification version
*/
Expand Down Expand Up @@ -83,4 +99,20 @@ public interface JPAEntityModel extends WindupVertexFrame
*/
@Adjacency(label = JPA_ENTITY_CLASS, direction = Direction.OUT)
public JavaClassModel getJavaClass();


/**
* Contains the jpa named query
*/
@Adjacency(label = NAMED_QUERY, direction = Direction.OUT)
public void addNamedQuery(JPANamedQueryModel model);


/**
* Contains the jpa named query
*/
@Adjacency(label = NAMED_QUERY, direction = Direction.OUT)
Iterable<JPANamedQueryModel> getNamedQueries();


}
@@ -0,0 +1,62 @@
package org.jboss.windup.rules.apps.javaee.model;

import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.rules.apps.java.model.JavaClassModel;

import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.frames.Adjacency;
import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;

/**
* Contains metadata associated with a JPA Named Query.
*
* @author <a href="mailto:bradsdavis@gmail.com">Brad Davis</a>
*
*/
@TypeValue(JPANamedQueryModel.TYPE)
public interface JPANamedQueryModel extends WindupVertexFrame
{
public static final String JPA_ENTITY = "jpaEntity";
public static final String QUERY_NAME = "queryName";
public static final String QUERY = "query";
public static final String TYPE = "JPANamedQuery";


/**
* Contains the query name
*/
@Property(QUERY_NAME)
public String getQueryName();

/**
* Contains the query name
*/
@Property(QUERY_NAME)
public void setQueryName(String queryName);


/**
* Contains the query
*/
@Property(QUERY)
public String getQuery();

/**
* Contains the query
*/
@Property(QUERY)
public void setQuery(String query);

/**
* Contains the jpa entity model
*/
@Adjacency(label = JPAEntityModel.NAMED_QUERY, direction = Direction.IN)
public void setJpaEntity(JPAEntityModel jpaEntity);

/**
* Contains the jpa entity model
*/
@Adjacency(label = JPAEntityModel.NAMED_QUERY, direction = Direction.IN)
public JPAEntityModel getJpaEntity();
}
Expand Up @@ -22,6 +22,7 @@
import org.jboss.windup.reporting.service.ReportService;
import org.jboss.windup.rules.apps.javaee.model.JPAConfigurationFileModel;
import org.jboss.windup.rules.apps.javaee.model.JPAEntityModel;
import org.jboss.windup.rules.apps.javaee.model.JPANamedQueryModel;
import org.jboss.windup.rules.apps.javaee.service.JPAConfigurationFileService;
import org.jboss.windup.rules.apps.javaee.service.JPAEntityService;
import org.jboss.windup.util.exception.WindupException;
Expand All @@ -47,8 +48,9 @@ public CreateJPAReportRuleProvider()
@Override
public Configuration getConfiguration(GraphContext context)
{
ConditionBuilder applicationProjectModelsFound = Query.fromType(JPAConfigurationFileModel.class).or(
Query.fromType(JPAEntityModel.class));
ConditionBuilder applicationProjectModelsFound = Query.fromType(JPAConfigurationFileModel.class)
.or(Query.fromType(JPAEntityModel.class))
.or(Query.fromType(JPANamedQueryModel.class));

GraphOperation addReport = new GraphOperation()
{
Expand Down Expand Up @@ -92,6 +94,8 @@ private void createJPAReport(GraphContext context, ProjectModel projectModel)

JPAConfigurationFileService jpaConfigurationFileService = new JPAConfigurationFileService(context);
JPAEntityService jpaEntityService = new JPAEntityService(context);
GraphService<JPANamedQueryModel> jpaNamedQueryService = new GraphService<>(context, JPANamedQueryModel.class);

GraphService<WindupVertexListModel> listService = new GraphService<WindupVertexListModel>(context, WindupVertexListModel.class);

WindupVertexListModel jpaConfigList = listService.create();
Expand All @@ -105,10 +109,19 @@ private void createJPAReport(GraphContext context, ProjectModel projectModel)
{
entityList.addItem(entityModel);
}

WindupVertexListModel namedQueryList = listService.create();
for (JPANamedQueryModel model : jpaNamedQueryService.findAll())
{
namedQueryList.addItem(model);
}


Map<String, WindupVertexFrame> additionalData = new HashMap<>(2);
additionalData.put("jpaConfiguration", jpaConfigList);
additionalData.put("jpaEntities", entityList);
additionalData.put("jpaNamedQueries", namedQueryList);

applicationReportModel.setRelatedResource(additionalData);

// Set the filename for the report
Expand Down
Expand Up @@ -28,9 +28,10 @@
import org.jboss.windup.rules.apps.java.scan.ast.annotations.JavaAnnotationTypeReferenceModel;
import org.jboss.windup.rules.apps.java.scan.ast.annotations.JavaAnnotationTypeValueModel;
import org.jboss.windup.rules.apps.java.scan.provider.AnalyzeJavaFilesRuleProvider;
import org.jboss.windup.rules.apps.javaee.model.EjbEntityBeanModel;
import org.jboss.windup.rules.apps.javaee.model.EjbMessageDrivenModel;
import org.jboss.windup.rules.apps.javaee.model.EjbSessionBeanModel;
import org.jboss.windup.rules.apps.javaee.model.JPAEntityModel;
import org.jboss.windup.rules.apps.javaee.service.JPAEntityService;
import org.jboss.windup.rules.apps.javaee.service.JmsDestinationService;
import org.jboss.windup.util.Logging;
import org.ocpsoft.rewrite.config.Configuration;
Expand Down Expand Up @@ -80,20 +81,7 @@ public void perform(GraphRewrite event, EvaluationContext context, JavaTypeRefer
extractMessageDrivenMetadata(event, payload);
}
})
.withId(ruleIDPrefix + "_MessageDrivenRule")
.addRule()
.when(JavaClass.references("javax.persistence.Entity").at(TypeReferenceLocation.ANNOTATION).as(ENTITY_ANNOTATIONS)
.or(JavaClass.references("javax.persistence.Table").at(TypeReferenceLocation.ANNOTATION).as(TABLE_ANNOTATIONS_LIST)))
.perform(Iteration.over(ENTITY_ANNOTATIONS).perform(new AbstractIterationOperation<JavaTypeReferenceModel>()
{
@Override
public void perform(GraphRewrite event, EvaluationContext context, JavaTypeReferenceModel payload)
{
extractEntityBeanMetadata(event, payload);
}
}).endIteration())
.withId(ruleIDPrefix + "_EntityBeanRule");

.withId(ruleIDPrefix + "_MessageDrivenRule");
}

private String getAnnotationLiteralValue(JavaAnnotationTypeReferenceModel model, String name)
Expand Down Expand Up @@ -134,43 +122,6 @@ private void extractEJBMetadata(GraphRewrite event, JavaTypeReferenceModel javaT
sessionBean.setSessionType(sessionType);
}

private void extractEntityBeanMetadata(GraphRewrite event, JavaTypeReferenceModel entityTypeReference)
{
((SourceFileModel) entityTypeReference.getFile()).setGenerateSourceReport(true);
JavaAnnotationTypeReferenceModel entityAnnotationTypeReference = (JavaAnnotationTypeReferenceModel) entityTypeReference;
JavaAnnotationTypeReferenceModel tableAnnotationTypeReference = null;
for (WindupVertexFrame annotationTypeReferenceBase : Variables.instance(event).findVariable(TABLE_ANNOTATIONS_LIST))
{
JavaAnnotationTypeReferenceModel annotationTypeReference = (JavaAnnotationTypeReferenceModel) annotationTypeReferenceBase;
if (annotationTypeReference.getFile().equals(entityTypeReference.getFile()))
{
tableAnnotationTypeReference = (JavaAnnotationTypeReferenceModel) annotationTypeReference;
break;
}
}

JavaClassModel ejbClass = getJavaClass(entityTypeReference);

String ejbName = getAnnotationLiteralValue(entityAnnotationTypeReference, "name");
if (ejbName == null)
{
ejbName = ejbClass.getClassName();
}
String tableName = tableAnnotationTypeReference == null ? ejbName : getAnnotationLiteralValue(tableAnnotationTypeReference, "name");
if (tableName == null)
{
tableName = ejbName;
}
String persistenceType = "Container"; // It is always container in the case of Annotations

Service<EjbEntityBeanModel> entityBeanService = new GraphService<>(event.getGraphContext(), EjbEntityBeanModel.class);
EjbEntityBeanModel entityBean = entityBeanService.create();
entityBean.setBeanName(ejbName);
entityBean.setEjbClass(ejbClass);
entityBean.setTableName(tableName);
entityBean.setPersistenceType(persistenceType);
}

private void extractMessageDrivenMetadata(GraphRewrite event, JavaTypeReferenceModel javaTypeReference)
{
((SourceFileModel) javaTypeReference.getFile()).setGenerateSourceReport(true);
Expand Down

0 comments on commit 22671b3

Please sign in to comment.