http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/jpa-gen/src/main/java/generators/JPAResourceClassGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/jpa-gen/src/main/java/generators/JPAResourceClassGenerator.java b/modules/registry/jpa-gen/src/main/java/generators/JPAResourceClassGenerator.java deleted file mode 100644 index f3f8978..0000000 --- a/modules/registry/jpa-gen/src/main/java/generators/JPAResourceClassGenerator.java +++ /dev/null @@ -1,513 +0,0 @@ -package generators; -import java.util.ArrayList; -import java.util.List; - -import model.JPAClassField; -import model.JPAClassModel; -import model.JPAResourceClassModel; - - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -public class JPAResourceClassGenerator extends AbstractGenerator { - private String exceptionClassName; - private String jpaUtilsClassName; - private String resourceTypeClassName; - private String queryGeneratorClassName; - - public JPAResourceClassModel createJPAResourceClassModel(JPAClassModel jpaClassModel){ - JPAResourceClassModel jpaResourceClassModel = new JPAResourceClassModel(); - jpaResourceClassModel.jpaClassModel=jpaClassModel; - jpaResourceClassModel.className=jpaClassModel.className+"Resource"; - jpaClassModel.classNameConstant=convertToJavaConstantNameCaseStringConvention(jpaClassModel.className); - for (JPAClassField jpaField : jpaClassModel.fields) { - jpaField.fieldNameConstant=convertToJavaConstantNameCaseStringConvention(jpaField.fieldName); - } - jpaResourceClassModel.jpaClassConstantClassName=jpaClassModel.className+"Constants"; - return jpaResourceClassModel; - } - - public String generateJPAResourceClass(JPAResourceClassModel model){ - String classStr = null; - String className = model.className; - classStr=addLines(classStr,"public class "+className+" extends AbstractResource {"); - classStr=addLines(classStr,tabs(1)+"private final static Logger logger = LoggerFactory.getLogger("+className+".class);"); - - List<String> columnFields=new ArrayList<String>(); - List<String> fieldGetters=new ArrayList<String>(); - List<String> fieldSetters=new ArrayList<String>(); - for (JPAClassField jpaField : model.jpaClassModel.fields) { - String fieldName = jpaField.fieldName; - String dataType = jpaField.fieldDataType; - String fieldTitleString = jpaField.fieldTitle; - - String fieldString=tabs(1)+createFieldVarString(dataType, fieldName); - columnFields.add(fieldString); - - fieldGetters.add(createGetterString(1, fieldName, dataType, fieldTitleString)); - fieldSetters.add(createSetterString(1, fieldName, dataType, fieldTitleString)); - - if (jpaField.foriegnKey){ - fieldName = createVarNameFromClassName(jpaField.foriegnKeyJPAResourceClass); - dataType = jpaField.foriegnKeyJPAResourceClass; - fieldTitleString = jpaField.foriegnKeyJPAResourceClass; - - fieldString=tabs(1)+createFieldVarString(dataType ,fieldName); - columnFields.add(fieldString); - - fieldGetters.add(createGetterString(1, fieldName,dataType, fieldTitleString)); - fieldSetters.add(createSetterString(1, fieldName,dataType, fieldTitleString)); - } - - } - classStr=addLines(classStr,columnFields.toArray(new String[]{})); - - //remove method - classStr=addLines(classStr,tabs(1)); - classStr=addLines(classStr,tabs(1)+"@Override"); - classStr=addLines(classStr,tabs(1)+"public void remove(Object identifier) throws "+getExceptionClassName()+" {"); - if (model.jpaClassModel.generatePKClass){ - classStr=addLines(classStr,tabs(2)+"HashMap<String, String> ids;"); - classStr=addLines(classStr,tabs(2)+"if (identifier instanceof Map) {"); - classStr=addLines(classStr,tabs(3)+"ids = (HashMap<String, String>) identifier;"); - classStr=addLines(classStr,tabs(2)+"} else {"); - classStr=addLines(classStr,tabs(3)+"logger.error(\"Identifier should be a map with the field name and it's value\");"); - classStr=addLines(classStr,tabs(3)+"throw new "+getExceptionClassName()+"(\"Identifier should be a map with the field name and it's value\");"); - classStr=addLines(classStr,tabs(2)+"}"); - } - classStr=addLines(classStr,tabs(2)+"EntityManager em = null;"); - classStr=addLines(classStr,tabs(2)+"try {"); - classStr=addLines(classStr,tabs(3)+"em = "+getJpaUtilsClassName()+".getEntityManager();"); - - classStr=addLines(classStr,tabs(3)+"em.getTransaction().begin();"); - classStr=addLines(classStr,tabs(3)+""+getQueryGeneratorClassName()+" generator = new "+getQueryGeneratorClassName()+"("+model.jpaClassModel.classNameConstant+");"); - if (model.jpaClassModel.generatePKClass){ - for(JPAClassField field:model.jpaClassModel.pkClassModel.pkFields){ - classStr=addLines(classStr,tabs(3)+"generator.setParameter("+model.jpaClassConstantClassName+"."+field.fieldNameConstant+", ids.get("+model.jpaClassConstantClassName+"."+field.fieldNameConstant+"));"); - } - }else{ - for(JPAClassField field:model.jpaClassModel.fields){ - if (field.primaryKey){ - classStr=addLines(classStr,tabs(3)+"generator.setParameter("+model.jpaClassConstantClassName+"."+field.fieldNameConstant+", identifier);"); - } - } - } - classStr=addLines(classStr,tabs(3)+"Query q = generator.deleteQuery(em);"); - classStr=addLines(classStr,tabs(3)+"q.executeUpdate();"); - classStr=addLines(classStr,tabs(3)+"em.getTransaction().commit();"); - classStr=addLines(classStr,tabs(3)+"em.close();"); - classStr=addLines(classStr,tabs(2)+"} catch (ApplicationSettingsException e) {"); - classStr=addLines(classStr,tabs(3)+"logger.error(e.getMessage(), e);"); - classStr=addLines(classStr,tabs(3)+"throw new "+getExceptionClassName()+"(e);"); - classStr=addLines(classStr,tabs(2)+"} finally {"); - classStr=addLines(classStr,tabs(3)+"if (em != null && em.isOpen()) {"); - classStr=addLines(classStr,tabs(4)+"if (em.getTransaction().isActive()) {"); - classStr=addLines(classStr,tabs(5)+"em.getTransaction().rollback();"); - classStr=addLines(classStr,tabs(4)+"}"); - classStr=addLines(classStr,tabs(4)+"em.close();"); - classStr=addLines(classStr,tabs(3)+"}"); - classStr=addLines(classStr,tabs(2)+"}"); - - classStr=addLines(classStr,tabs(1)+"}"); - - //get method for resource class - classStr=addLines(classStr,tabs(1)); - classStr=addLines(classStr,tabs(1)+"@Override"); - classStr=addLines(classStr,tabs(1)+"public Resource get(Object identifier) throws "+getExceptionClassName()+" {"); - - if (model.jpaClassModel.generatePKClass){ - classStr=addLines(classStr,tabs(2)+"HashMap<String, String> ids;"); - classStr=addLines(classStr,tabs(2)+"if (identifier instanceof Map) {"); - classStr=addLines(classStr,tabs(3)+"ids = (HashMap<String, String>) identifier;"); - classStr=addLines(classStr,tabs(2)+"} else {"); - classStr=addLines(classStr,tabs(3)+"logger.error(\"Identifier should be a map with the field name and it's value\");"); - classStr=addLines(classStr,tabs(3)+"throw new "+getExceptionClassName()+"(\"Identifier should be a map with the field name and it's value\");"); - classStr=addLines(classStr,tabs(2)+"}"); - } - classStr=addLines(classStr,tabs(2)+"EntityManager em = null;"); - classStr=addLines(classStr,tabs(2)+"try {"); - classStr=addLines(classStr,tabs(3)+"em = "+getJpaUtilsClassName()+".getEntityManager();"); - - classStr=addLines(classStr,tabs(3)+"em.getTransaction().begin();"); - classStr=addLines(classStr,tabs(3)+""+getQueryGeneratorClassName()+" generator = new "+getQueryGeneratorClassName()+"("+model.jpaClassModel.classNameConstant+");"); - if (model.jpaClassModel.generatePKClass){ - for(JPAClassField field:model.jpaClassModel.pkClassModel.pkFields){ - classStr=addLines(classStr,tabs(3)+"generator.setParameter("+model.jpaClassConstantClassName+"."+field.fieldNameConstant+", ids.get("+model.jpaClassConstantClassName+"."+field.fieldNameConstant+"));"); - } - }else{ - for(JPAClassField field:model.jpaClassModel.fields){ - if (field.primaryKey){ - classStr=addLines(classStr,tabs(3)+"generator.setParameter("+model.jpaClassConstantClassName+"."+field.fieldNameConstant+", identifier);"); - } - } - } - - classStr=addLines(classStr,tabs(3)+"Query q = generator.selectQuery(em);"); - String jpaObjVar=createVarNameFromClassName(model.jpaClassModel.className); - classStr=addLines(classStr,tabs(3)+model.jpaClassModel.className+" "+jpaObjVar+" = ("+model.jpaClassModel.className+") q.getSingleResult();"); - String jpaObjVarResource=createVarNameFromClassName(model.className); - classStr=addLines(classStr,tabs(3)+model.className+" "+jpaObjVarResource+" = ("+model.className+") "+getJpaUtilsClassName()+".getResource("+getResourceTypeClassName()+"."+model.jpaClassModel.classNameConstant+", "+jpaObjVar+");"); - classStr=addLines(classStr,tabs(3)+"em.getTransaction().commit();"); - classStr=addLines(classStr,tabs(3)+"em.close();"); - classStr=addLines(classStr,tabs(3)+"return "+jpaObjVarResource+";"); - classStr=addLines(classStr,tabs(2)+"} catch (ApplicationSettingsException e) {"); - classStr=addLines(classStr,tabs(3)+"logger.error(e.getMessage(), e);"); - classStr=addLines(classStr,tabs(3)+"throw new "+getExceptionClassName()+"(e);"); - classStr=addLines(classStr,tabs(2)+"} finally {"); - classStr=addLines(classStr,tabs(3)+"if (em != null && em.isOpen()) {"); - classStr=addLines(classStr,tabs(4)+"if (em.getTransaction().isActive()) {"); - classStr=addLines(classStr,tabs(5)+"em.getTransaction().rollback();"); - classStr=addLines(classStr,tabs(4)+"}"); - classStr=addLines(classStr,tabs(4)+"em.close();"); - classStr=addLines(classStr,tabs(3)+"}"); - classStr=addLines(classStr,tabs(2)+"}"); - classStr=addLines(classStr,tabs(1)+"}"); - - classStr=addLines(classStr,tabs(1)); - classStr=addLines(classStr,tabs(1)+"@Override"); - classStr=addLines(classStr,tabs(1)+"public List<Resource> get(String fieldName, Object value) throws "+getExceptionClassName()+" {"); - - String resultListVarName=createVarNameFromClassName(model.className)+"s"; - classStr=addLines(classStr,tabs(2)+"List<Resource> "+resultListVarName+" = new ArrayList<Resource>();"); - classStr=addLines(classStr,tabs(2)+"EntityManager em = null;"); - classStr=addLines(classStr,tabs(2)+"try {"); - classStr=addLines(classStr,tabs(3)+"em = "+getJpaUtilsClassName()+".getEntityManager();"); - - classStr=addLines(classStr,tabs(3)+"em.getTransaction().begin();"); - classStr=addLines(classStr,tabs(3)+""+getQueryGeneratorClassName()+" generator = new "+getQueryGeneratorClassName()+"("+model.jpaClassModel.classNameConstant+");"); - - classStr=addLines(classStr,tabs(3)+"Query q;"); - List<String> fieldNameValidations=new ArrayList<String>(); - for(JPAClassField field:model.jpaClassModel.fields){ - fieldNameValidations.add("(fieldName.equals("+model.jpaClassConstantClassName+"."+field.fieldNameConstant+"))"); - } - String fieldNameValidationLogic = commaSeperatedString(fieldNameValidations, " || "); - classStr=addLines(classStr,tabs(3)+"if ("+fieldNameValidationLogic+") {"); - classStr=addLines(classStr,tabs(4)+"generator.setParameter(fieldName, value);"); - classStr=addLines(classStr,tabs(4)+"q = generator.selectQuery(em);"); - classStr=addLines(classStr,tabs(4)+"List<?> results = q.getResultList();"); - classStr=addLines(classStr,tabs(4)+"for (Object result : results) {"); - classStr=addLines(classStr,tabs(5)+model.jpaClassModel.className+" "+jpaObjVar+" = ("+model.jpaClassModel.className+") result;"); - classStr=addLines(classStr,tabs(5)+model.className+" "+jpaObjVarResource+" = ("+model.className+") "+getJpaUtilsClassName()+".getResource("+getResourceTypeClassName()+"."+model.jpaClassModel.classNameConstant+", "+jpaObjVar+");"); - classStr=addLines(classStr,tabs(5)+resultListVarName+".add("+jpaObjVarResource+");"); - classStr=addLines(classStr,tabs(4)+"}"); - classStr=addLines(classStr,tabs(3)+"} else {"); - classStr=addLines(classStr,tabs(4)+"em.getTransaction().commit();"); - classStr=addLines(classStr,tabs(5)+"em.close();"); - classStr=addLines(classStr,tabs(4)+"logger.error(\"Unsupported field name for "+convertToTitleCaseString(model.className)+".\", new IllegalArgumentException());"); - classStr=addLines(classStr,tabs(4)+"throw new IllegalArgumentException(\"Unsupported field name for "+convertToTitleCaseString(model.className)+".\");"); - classStr=addLines(classStr,tabs(3)+"}"); - classStr=addLines(classStr,tabs(3)+"em.getTransaction().commit();"); - classStr=addLines(classStr,tabs(3)+"em.close();"); - classStr=addLines(classStr,tabs(2)+"} catch (ApplicationSettingsException e) {"); - classStr=addLines(classStr,tabs(3)+"logger.error(e.getMessage(), e);"); - classStr=addLines(classStr,tabs(3)+"throw new "+getExceptionClassName()+"(e);"); - classStr=addLines(classStr,tabs(2)+"} finally {"); - classStr=addLines(classStr,tabs(3)+"if (em != null && em.isOpen()) {"); - classStr=addLines(classStr,tabs(4)+"if (em.getTransaction().isActive()) {"); - classStr=addLines(classStr,tabs(5)+"em.getTransaction().rollback();"); - classStr=addLines(classStr,tabs(4)+"}"); - classStr=addLines(classStr,tabs(4)+"em.close();"); - classStr=addLines(classStr,tabs(3)+"}"); - classStr=addLines(classStr,tabs(2)+"}"); - classStr=addLines(classStr,tabs(2)+"return "+resultListVarName+";"); - classStr=addLines(classStr,tabs(1)+"}"); - - //id list method - classStr=addLines(classStr,tabs(1)); - classStr=addLines(classStr,tabs(1)+"@Override"); - classStr=addLines(classStr,tabs(1)+"public List<String> getIds(String fieldName, Object value) throws "+getExceptionClassName()+" {"); - - resultListVarName=createVarNameFromClassName(model.className)+"IDs"; - classStr=addLines(classStr,tabs(2)+"List<String> "+resultListVarName+" = new ArrayList<String>();"); - classStr=addLines(classStr,tabs(2)+"EntityManager em = null;"); - classStr=addLines(classStr,tabs(2)+"try {"); - classStr=addLines(classStr,tabs(3)+"em = "+getJpaUtilsClassName()+".getEntityManager();"); - - classStr=addLines(classStr,tabs(3)+"em.getTransaction().begin();"); - classStr=addLines(classStr,tabs(3)+""+getQueryGeneratorClassName()+" generator = new "+getQueryGeneratorClassName()+"("+model.jpaClassModel.classNameConstant+");"); - - classStr=addLines(classStr,tabs(3)+"Query q;"); - fieldNameValidations=new ArrayList<String>(); - for(JPAClassField field:model.jpaClassModel.fields){ - fieldNameValidations.add("(fieldName.equals("+model.jpaClassConstantClassName+"."+field.fieldNameConstant+"))"); - } - fieldNameValidationLogic = commaSeperatedString(fieldNameValidations, " || "); - classStr=addLines(classStr,tabs(3)+"if ("+fieldNameValidationLogic+") {"); - classStr=addLines(classStr,tabs(4)+"generator.setParameter(fieldName, value);"); - classStr=addLines(classStr,tabs(4)+"q = generator.selectQuery(em);"); - classStr=addLines(classStr,tabs(4)+"List<?> results = q.getResultList();"); - classStr=addLines(classStr,tabs(4)+"for (Object result : results) {"); - classStr=addLines(classStr,tabs(5)+model.jpaClassModel.className+" "+jpaObjVar+" = ("+model.jpaClassModel.className+") result;"); - classStr=addLines(classStr,tabs(5)+model.className+" "+jpaObjVarResource+" = ("+model.className+") "+getJpaUtilsClassName()+".getResource("+getResourceTypeClassName()+"."+model.jpaClassModel.classNameConstant+", "+jpaObjVar+");"); - String idFieldToAdd=null; - if (model.jpaClassModel.generatePKClass){ - for (JPAClassField field : model.jpaClassModel.fields) { - if (field.foriegnKey){ - idFieldToAdd=jpaObjVarResource+".get"+field.fieldTitle+"()"; - break; - } - } - }else{ - for (JPAClassField field : model.jpaClassModel.fields) { - if (field.primaryKey){ - idFieldToAdd=jpaObjVarResource+".get"+field.fieldTitle+"()"; - } - } - } - classStr=addLines(classStr,tabs(5)+resultListVarName+".add("+idFieldToAdd+");"); - classStr=addLines(classStr,tabs(4)+"}"); - classStr=addLines(classStr,tabs(3)+"} else {"); - classStr=addLines(classStr,tabs(4)+"em.getTransaction().commit();"); - classStr=addLines(classStr,tabs(5)+"em.close();"); - classStr=addLines(classStr,tabs(4)+"logger.error(\"Unsupported field name for "+convertToTitleCaseString(model.className)+".\", new IllegalArgumentException());"); - classStr=addLines(classStr,tabs(4)+"throw new IllegalArgumentException(\"Unsupported field name for "+convertToTitleCaseString(model.className)+".\");"); - classStr=addLines(classStr,tabs(3)+"}"); - classStr=addLines(classStr,tabs(3)+"em.getTransaction().commit();"); - classStr=addLines(classStr,tabs(3)+"em.close();"); - classStr=addLines(classStr,tabs(2)+"} catch (ApplicationSettingsException e) {"); - classStr=addLines(classStr,tabs(3)+"logger.error(e.getMessage(), e);"); - classStr=addLines(classStr,tabs(3)+"throw new "+getExceptionClassName()+"(e);"); - classStr=addLines(classStr,tabs(2)+"} finally {"); - classStr=addLines(classStr,tabs(3)+"if (em != null && em.isOpen()) {"); - classStr=addLines(classStr,tabs(4)+"if (em.getTransaction().isActive()) {"); - classStr=addLines(classStr,tabs(5)+"em.getTransaction().rollback();"); - classStr=addLines(classStr,tabs(4)+"}"); - classStr=addLines(classStr,tabs(4)+"em.close();"); - classStr=addLines(classStr,tabs(3)+"}"); - classStr=addLines(classStr,tabs(2)+"}"); - classStr=addLines(classStr,tabs(2)+"return "+resultListVarName+";"); - - - classStr=addLines(classStr,tabs(1)+"}"); - - //save method - classStr=addLines(classStr,tabs(1)); - classStr=addLines(classStr,tabs(1)+"@Override"); - classStr=addLines(classStr,tabs(1)+"public void save() throws "+getExceptionClassName()+" {"); - - classStr=addLines(classStr,tabs(2)+"EntityManager em = null;"); - classStr=addLines(classStr,tabs(2)+"try {"); - classStr=addLines(classStr,tabs(3)+"em = "+getJpaUtilsClassName()+".getEntityManager();"); - String existingJPAObjVar="existing"+model.jpaClassModel.className; - - String primaryKeySearchString=null; - if (model.jpaClassModel.generatePKClass){ - List<String> fieldStrings=new ArrayList<String>(); - for(JPAClassField field:model.jpaClassModel.pkClassModel.pkFields){ - fieldStrings.add(field.fieldName); - } - primaryKeySearchString="new "+model.jpaClassModel.pkClassModel.className+"("+commaSeperatedString(fieldStrings, ", ")+")"; - }else{ - for(JPAClassField field:model.jpaClassModel.fields){ - if (field.primaryKey){ - primaryKeySearchString=field.fieldName; - } - } - } - classStr=addLines(classStr,tabs(3)+model.jpaClassModel.className+" "+existingJPAObjVar+" = em.find("+model.jpaClassModel.className+".class, "+primaryKeySearchString+");"); - classStr=addLines(classStr,tabs(3)+"em.close();"); - classStr=addLines(classStr,tabs(3)+model.jpaClassModel.className+" "+jpaObjVar+";"); - classStr=addLines(classStr,tabs(3)+"em = "+getJpaUtilsClassName()+".getEntityManager();"); - classStr=addLines(classStr,tabs(3)+"em.getTransaction().begin();"); - classStr=addLines(classStr,tabs(3)+"if ("+existingJPAObjVar+" == null) {"); - classStr=addLines(classStr,tabs(4)+jpaObjVar+" = new "+model.jpaClassModel.className+"();"); - classStr=addLines(classStr,tabs(3)+"} else {"); - classStr=addLines(classStr,tabs(4)+jpaObjVar+" = "+existingJPAObjVar+";"); - classStr=addLines(classStr,tabs(3)+"}"); - for (JPAClassField field : model.jpaClassModel.fields) { - classStr=addLines(classStr,tabs(3)+jpaObjVar+".set"+field.fieldTitle+"(get"+field.fieldTitle+"());"); - if (field.foriegnKey){ - String varNameForForiegnKeyObj = createVarNameFromClassName(field.foriegnKeyJPAClass); - classStr=addLines(classStr,tabs(3)+field.foriegnKeyJPAClass+" "+varNameForForiegnKeyObj+" = em.find("+field.foriegnKeyJPAClass+".class, get"+field.fieldTitle+"());"); - classStr=addLines(classStr,tabs(3)+jpaObjVar+".set"+field.foriegnKeyJPAClass+"("+varNameForForiegnKeyObj+");"); - } - } - classStr=addLines(classStr,tabs(3)+"if ("+existingJPAObjVar+" == null) {"); - classStr=addLines(classStr,tabs(4)+"em.persist("+jpaObjVar+");"); - classStr=addLines(classStr,tabs(3)+"} else {"); - classStr=addLines(classStr,tabs(4)+"em.merge("+jpaObjVar+");"); - classStr=addLines(classStr,tabs(3)+"}"); - classStr=addLines(classStr,tabs(3)+"em.getTransaction().commit();"); - classStr=addLines(classStr,tabs(3)+"em.close();"); - classStr=addLines(classStr,tabs(2)+"} catch (Exception e) {"); - classStr=addLines(classStr,tabs(3)+"logger.error(e.getMessage(), e);"); - classStr=addLines(classStr,tabs(3)+"throw new "+getExceptionClassName()+"(e);"); - classStr=addLines(classStr,tabs(2)+"} finally {"); - classStr=addLines(classStr,tabs(3)+"if (em != null && em.isOpen()) {"); - classStr=addLines(classStr,tabs(4)+"if (em.getTransaction().isActive()) {"); - classStr=addLines(classStr,tabs(5)+"em.getTransaction().rollback();"); - classStr=addLines(classStr,tabs(4)+"}"); - classStr=addLines(classStr,tabs(4)+"em.close();"); - classStr=addLines(classStr,tabs(3)+"}"); - classStr=addLines(classStr,tabs(2)+"}"); - classStr=addLines(classStr,tabs(1)+"}"); - - //isexist method - - classStr=addLines(classStr,tabs(1)); - classStr=addLines(classStr,tabs(1)+"@Override"); - classStr=addLines(classStr,tabs(1)+"public boolean isExists(Object identifier) throws "+getExceptionClassName()+" {"); - - if (model.jpaClassModel.generatePKClass){ - classStr=addLines(classStr,tabs(2)+"HashMap<String, String> ids;"); - classStr=addLines(classStr,tabs(2)+"if (identifier instanceof Map) {"); - classStr=addLines(classStr,tabs(3)+"ids = (HashMap<String, String>) identifier;"); - classStr=addLines(classStr,tabs(2)+"} else {"); - classStr=addLines(classStr,tabs(3)+"logger.error(\"Identifier should be a map with the field name and it's value\");"); - classStr=addLines(classStr,tabs(3)+"throw new "+getExceptionClassName()+"(\"Identifier should be a map with the field name and it's value\");"); - classStr=addLines(classStr,tabs(2)+"}"); - } - - primaryKeySearchString=null; - if (model.jpaClassModel.generatePKClass){ - List<String> fieldStrings=new ArrayList<String>(); - for(JPAClassField field:model.jpaClassModel.pkClassModel.pkFields){ - fieldStrings.add("ids.get("+model.jpaClassConstantClassName+"."+field.fieldNameConstant+")"); - } - primaryKeySearchString="new "+model.jpaClassModel.pkClassModel.className+"("+commaSeperatedString(fieldStrings, ", ")+")"; - }else{ - for(JPAClassField field:model.jpaClassModel.fields){ - if (field.primaryKey){ - primaryKeySearchString="identifier"; - } - } - } - classStr=addLines(classStr,tabs(2)+"EntityManager em = null;"); - classStr=addLines(classStr,tabs(2)+"try {"); - classStr=addLines(classStr,tabs(3)+"em = "+getJpaUtilsClassName()+".getEntityManager();"); - classStr=addLines(classStr,tabs(3)+model.jpaClassModel.className+" "+jpaObjVar+" = em.find("+model.jpaClassModel.className+".class, "+primaryKeySearchString+");"); - - classStr=addLines(classStr,tabs(3)+"em.close();"); - classStr=addLines(classStr,tabs(3)+"return "+jpaObjVar+" != null;"); - classStr=addLines(classStr,tabs(2)+"} catch (ApplicationSettingsException e) {"); - classStr=addLines(classStr,tabs(3)+"logger.error(e.getMessage(), e);"); - classStr=addLines(classStr,tabs(3)+"throw new "+getExceptionClassName()+"(e);"); - classStr=addLines(classStr,tabs(2)+"} finally {"); - classStr=addLines(classStr,tabs(3)+"if (em != null && em.isOpen()) {"); - classStr=addLines(classStr,tabs(4)+"if (em.getTransaction().isActive()) {"); - classStr=addLines(classStr,tabs(5)+"em.getTransaction().rollback();"); - classStr=addLines(classStr,tabs(4)+"}"); - classStr=addLines(classStr,tabs(4)+"em.close();"); - classStr=addLines(classStr,tabs(3)+"}"); - classStr=addLines(classStr,tabs(2)+"}"); - classStr=addLines(classStr,tabs(1)+"}"); - - - classStr=addLines(classStr,fieldGetters.toArray(new String[]{})); - classStr=addLines(classStr,fieldSetters.toArray(new String[]{})); - - classStr=addLines(classStr,"}"); - return classStr; - } - - public String generateAbstractResourceClassUpdates(JPAResourceClassModel model){ - String classStr = null; - classStr=addLines(classStr,"public abstract class AbstractResource implements Resource {"); - - classStr=addLines(classStr,tabs(1)+"public static final String "+model.jpaClassModel.classNameConstant+" = \""+model.jpaClassModel.className+"\";"); - - classStr=addLines(classStr,tabs(1)+"// "+convertToTitleCaseString(model.jpaClassModel.className)+" Table"); - classStr=addLines(classStr,tabs(1)+"public final class "+model.jpaClassConstantClassName+" {"); - for (JPAClassField jpaField : model.jpaClassModel.fields) { - classStr=addLines(classStr,tabs(2)+"public static final String "+jpaField.fieldNameConstant+" = \""+jpaField.fieldName+"\";"); - } - classStr=addLines(classStr,tabs(1)+"}"); - classStr=addLines(classStr,"}"); - return classStr; - } - - public String generateAppCatalogJPAUtilUpdates(JPAResourceClassModel model){ - String classStr = null; - String conversionMethodName="create"+model.jpaClassModel.className; - classStr=addLines(classStr,"public class "+getJpaUtilsClassName()+" {"); - classStr=addLines(classStr,tabs(1)+"public static Resource getResource("+getResourceTypeClassName()+" type, Object o) {"); - classStr=addLines(classStr,tabs(2)+"switch (type){"); - classStr=addLines(classStr,tabs(3)+"case "+model.jpaClassModel.classNameConstant+":"); - classStr=addLines(classStr,tabs(4)+"if (o instanceof "+model.jpaClassModel.className+"){"); - classStr=addLines(classStr,tabs(5)+"return "+conversionMethodName+"(("+model.jpaClassModel.className+") o);"); - classStr=addLines(classStr,tabs(4)+"}else{"); - classStr=addLines(classStr,tabs(5)+"logger.error(\"Object should be a "+convertToTitleCaseString(model.jpaClassModel.className)+".\", new IllegalArgumentException());"); - classStr=addLines(classStr,tabs(5)+"throw new IllegalArgumentException(\"Object should be a "+convertToTitleCaseString(model.jpaClassModel.className)+".\");"); - classStr=addLines(classStr,tabs(4)+"}"); - classStr=addLines(classStr,tabs(2)+"}"); - classStr=addLines(classStr,tabs(1)+"}"); - classStr=addLines(classStr,tabs(1)); - - String resourceVariableName = createVarNameFromClassName(model.className); - classStr=addLines(classStr,tabs(1)+"private static Resource "+conversionMethodName+"("+model.jpaClassModel.className+" o) {"); - classStr=addLines(classStr,tabs(2)+model.className+" "+resourceVariableName+" = new "+model.className+"();"); - for(JPAClassField field:model.jpaClassModel.fields){ - classStr=addLines(classStr,tabs(2)+resourceVariableName+".set"+field.fieldTitle+"(o.get"+field.fieldTitle+"());"); - if (field.foriegnKey){ - classStr=addLines(classStr,tabs(2)+resourceVariableName+".set"+field.foriegnKeyJPAResourceClass+"(("+field.foriegnKeyJPAResourceClass+")create"+field.foriegnKeyJPAClass+"(o.get"+field.foriegnKeyJPAClass+"()));"); - } - } - classStr=addLines(classStr,tabs(2)+"return "+resourceVariableName+";"); - classStr=addLines(classStr,tabs(1)+"}"); - - classStr=addLines(classStr,"}"); - return classStr; - } - - public String generateAppCatalogResourceTypeUpdates(JPAResourceClassModel model){ - String classStr = null; - classStr=addLines(classStr,"public enum "+getResourceTypeClassName()+" {"); - classStr=addLines(classStr,tabs(1)+model.jpaClassModel.classNameConstant); - classStr=addLines(classStr,"}"); - return classStr; - } - - public String getExceptionClassName() { - return exceptionClassName; - } - - public void setExceptionClassName(String exceptionClassName) { - this.exceptionClassName = exceptionClassName; - } - - public String getJpaUtilsClassName() { - return jpaUtilsClassName; - } - - public void setJpaUtilsClassName(String jpaUtilsClassName) { - this.jpaUtilsClassName = jpaUtilsClassName; - } - - public String getResourceTypeClassName() { - return resourceTypeClassName; - } - - public void setResourceTypeClassName(String resourceTypeClassName) { - this.resourceTypeClassName = resourceTypeClassName; - } - - public String getQueryGeneratorClassName() { - return queryGeneratorClassName; - } - - public void setQueryGeneratorClassName(String queryGeneratorClassName) { - this.queryGeneratorClassName = queryGeneratorClassName; - } - - -}
http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/jpa-gen/src/main/java/generators/SQLGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/jpa-gen/src/main/java/generators/SQLGenerator.java b/modules/registry/jpa-gen/src/main/java/generators/SQLGenerator.java deleted file mode 100644 index 3d326ca..0000000 --- a/modules/registry/jpa-gen/src/main/java/generators/SQLGenerator.java +++ /dev/null @@ -1,77 +0,0 @@ -package generators; -import java.util.ArrayList; -import java.util.List; - -import model.SQLData; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -public class SQLGenerator extends AbstractGenerator { - private static final Logger log = LoggerFactory.getLogger(SQLGenerator.class); - - public static enum DataTypes{ - VARCHAR, - TIMESTAMP, - INTEGER, - LONGTEXT, - SMALLINT, - CLOB, - } - - public String generateSQLCreateQuery(SQLData sqlData){ - String sql = null; - sql="CREATE TABLE "+sqlData.getTableName()+"\n"; - sql+="("; - for (String fieldName : sqlData.getFieldData().keySet()) { - List<String> fieldData = new ArrayList<String>(); - fieldData.addAll(sqlData.getFieldData().get(fieldName)); - String dataTypeStr = fieldData.get(0); - fieldData.remove(0); - DataTypes.valueOf(dataTypeStr); - sql+="\n\t"+fieldName+" "+dataTypeStr; - for (String data : fieldData) { - sql+=" "+data; - } - sql+=","; - } - - if (sqlData.getPrimaryKeys().size()>0) { - sql+="\n\tPRIMARY KEY ("; - for (String primaryKey : sqlData.getPrimaryKeys()) { - sql+=primaryKey+","; - } - sql=removeLastChar(sql); - sql+="),"; - } - for (String foriegnKey : sqlData.getForiegnKeys().keySet()) { - sql+="\n\tFOREIGN KEY "; - sql+="("+foriegnKey+") REFERENCES "+sqlData.getForiegnKeys().get(foriegnKey).tableAndField+","; - } - sql=removeLastChar(sql)+"\n"; - sql+=");"; - return sql; - } - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/jpa-gen/src/main/java/model/JPAClassField.java ---------------------------------------------------------------------- diff --git a/modules/registry/jpa-gen/src/main/java/model/JPAClassField.java b/modules/registry/jpa-gen/src/main/java/model/JPAClassField.java deleted file mode 100644 index b0d0090..0000000 --- a/modules/registry/jpa-gen/src/main/java/model/JPAClassField.java +++ /dev/null @@ -1,47 +0,0 @@ -package model; -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - - -public class JPAClassField{ - public String tableColumnName; - public String fieldName; - public String fieldNameConstant; - public String fieldDataType; - public String fieldTitle; - public boolean primaryKey; - public boolean foriegnKey=false; - public String foriegnKeyJPAClass; - public String foriegnKeyJPAResourceClass; - public JPAClassField(String tableColumnName, String fieldName, - String fieldDataType, String fieldTitle, boolean primaryKey,boolean foriegnKey,String foriegnKeyJPAClass,String foriegnKeyJPAResourceClass) { - this.tableColumnName = tableColumnName; - this.fieldName = fieldName; - this.fieldDataType = fieldDataType; - this.fieldTitle = fieldTitle; - this.primaryKey=primaryKey; - this.foriegnKey=foriegnKey; - this.foriegnKeyJPAClass=foriegnKeyJPAClass; - this.foriegnKeyJPAResourceClass=foriegnKeyJPAResourceClass; - } - - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/jpa-gen/src/main/java/model/JPAClassModel.java ---------------------------------------------------------------------- diff --git a/modules/registry/jpa-gen/src/main/java/model/JPAClassModel.java b/modules/registry/jpa-gen/src/main/java/model/JPAClassModel.java deleted file mode 100644 index 8ac8ff8..0000000 --- a/modules/registry/jpa-gen/src/main/java/model/JPAClassModel.java +++ /dev/null @@ -1,34 +0,0 @@ -package model; -import java.util.ArrayList; -import java.util.List; - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - - -public class JPAClassModel{ - public String className; - public String classNameConstant; - public String tableName; - public boolean generatePKClass=false; - public List<JPAClassField> fields=new ArrayList<JPAClassField>(); - public JPAPKClassModel pkClassModel=new JPAPKClassModel(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/jpa-gen/src/main/java/model/JPAPKClassModel.java ---------------------------------------------------------------------- diff --git a/modules/registry/jpa-gen/src/main/java/model/JPAPKClassModel.java b/modules/registry/jpa-gen/src/main/java/model/JPAPKClassModel.java deleted file mode 100644 index f09f426..0000000 --- a/modules/registry/jpa-gen/src/main/java/model/JPAPKClassModel.java +++ /dev/null @@ -1,30 +0,0 @@ -package model; -import java.util.ArrayList; -import java.util.List; - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - - -public class JPAPKClassModel{ - public String className; - public List<JPAClassField> pkFields=new ArrayList<JPAClassField>(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/jpa-gen/src/main/java/model/JPAResourceClassModel.java ---------------------------------------------------------------------- diff --git a/modules/registry/jpa-gen/src/main/java/model/JPAResourceClassModel.java b/modules/registry/jpa-gen/src/main/java/model/JPAResourceClassModel.java deleted file mode 100644 index f0b4c21..0000000 --- a/modules/registry/jpa-gen/src/main/java/model/JPAResourceClassModel.java +++ /dev/null @@ -1,28 +0,0 @@ -package model; -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - - -public class JPAResourceClassModel{ - public String className; - public JPAClassModel jpaClassModel; - public String jpaClassConstantClassName; -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/jpa-gen/src/main/java/model/SQLData.java ---------------------------------------------------------------------- diff --git a/modules/registry/jpa-gen/src/main/java/model/SQLData.java b/modules/registry/jpa-gen/src/main/java/model/SQLData.java deleted file mode 100644 index 59f0332..0000000 --- a/modules/registry/jpa-gen/src/main/java/model/SQLData.java +++ /dev/null @@ -1,79 +0,0 @@ -package model; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -public class SQLData { - private String tableName; - private Map<String,List<String>> fieldData; - private List<String> primaryKeys; - private Map<String,ForiegnKeyData> foriegnKeys; - - public static class ForiegnKeyData{ - public String tableAndField; - public String jpaClassName; - public String jpaResourceClassName; - public ForiegnKeyData(String tableAndField, String jpaClassName,String jpaResourceClassName) { - this.tableAndField = tableAndField; - this.jpaClassName = jpaClassName; - this.jpaResourceClassName = jpaResourceClassName; - } - } - - public String getTableName() { - return tableName; - } - public void setTableName(String tableName) { - this.tableName = tableName; - } - public Map<String, List<String>> getFieldData() { - if (fieldData==null){ - fieldData=new HashMap<String, List<String>>(); - } - return fieldData; - } - - public void setFieldData(Map<String, List<String>> fieldData) { - this.fieldData = fieldData; - } - public List<String> getPrimaryKeys() { - if (primaryKeys==null){ - primaryKeys=new ArrayList<String>(); - } - return primaryKeys; - } - public void setPrimaryKeys(List<String> primaryKeys) { - this.primaryKeys = primaryKeys; - } - public Map<String,ForiegnKeyData> getForiegnKeys() { - if (foriegnKeys==null){ - foriegnKeys=new HashMap<String, ForiegnKeyData>(); - } - return foriegnKeys; - } - public void setForiegnKeys(Map<String,ForiegnKeyData> foriegnKeys) { - this.foriegnKeys = foriegnKeys; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/jpa-gen/src/main/java/test/Test.java ---------------------------------------------------------------------- diff --git a/modules/registry/jpa-gen/src/main/java/test/Test.java b/modules/registry/jpa-gen/src/main/java/test/Test.java deleted file mode 100644 index 9d5510d..0000000 --- a/modules/registry/jpa-gen/src/main/java/test/Test.java +++ /dev/null @@ -1,81 +0,0 @@ -package test; - -import generators.JPAClassGenerator; -import generators.JPAResourceClassGenerator; -import generators.SQLGenerator; - -import java.util.Arrays; - -import model.JPAClassModel; -import model.JPAResourceClassModel; -import model.SQLData; - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -public class Test { - - - private static SQLData createSQLData() { - SQLData data = new SQLData(); - data.setTableName("COMMUNITY_USER"); - data.getFieldData().put("GATEWAY_NAME", Arrays.asList(new String[]{"VARCHAR", "256", "NOT", "NULL"})); - data.getFieldData().put("COMMUNITY_USER_NAME", Arrays.asList(new String[]{"VARCHAR", "256", "NOT", "NULL"})); - data.getFieldData().put("TOKEN_ID", Arrays.asList(new String[]{"VARCHAR", "256", "NOT", "NULL"})); - data.getFieldData().put("COMMUNITY_USER_EMAIL", Arrays.asList(new String[]{"VARCHAR", "256", "NOT", "NULL"})); - data.getFieldData().put("CREATION_TIME", Arrays.asList(new String[]{"TIMESTAMP", "DEFAULT", "NOW()"})); - data.getFieldData().put("CPU_COUNT", Arrays.asList(new String[]{"INTEGER"})); - data.getPrimaryKeys().add("GATEWAY_NAME"); - data.getPrimaryKeys().add("COMMUNITY_USER_NAME"); - data.getPrimaryKeys().add("TOKEN_ID"); - data.getForiegnKeys().put("EXPERIMENT_ID", new SQLData.ForiegnKeyData("EXPERIMENT(EXPERIMENT_ID)","Experiment","ExperimentResource")); - return data; - } - public static void testSqlGen() { - SQLData data = createSQLData(); - SQLGenerator sqlGenerator = new SQLGenerator(); - System.out.println(sqlGenerator.generateSQLCreateQuery(data)); - } - - public static void testJPAClassGen() { - SQLData data = createSQLData(); - JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); - JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); - System.out.println(jpaClassGenerator.generateJPAClass(model)); - System.out.println(jpaClassGenerator.generateJPAPKClass(model.pkClassModel)); - } - - public static void testJPAResourceClassGen() { - SQLData data = createSQLData(); - JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); - JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); - JPAResourceClassGenerator jpaResourceClassGenerator = new JPAResourceClassGenerator(); - JPAResourceClassModel model2 = jpaResourceClassGenerator.createJPAResourceClassModel(model); - System.out.println(jpaResourceClassGenerator.generateJPAResourceClass(model2)); - System.out.println(jpaResourceClassGenerator.generateAbstractResourceClassUpdates(model2)); - System.out.println(jpaResourceClassGenerator.generateAppCatalogResourceTypeUpdates(model2)); - System.out.println(jpaResourceClassGenerator.generateAppCatalogJPAUtilUpdates(model2)); - - } - public static void main(String[] args) { - testJPAResourceClassGen(); - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/pom.xml ---------------------------------------------------------------------- diff --git a/modules/registry/pom.xml b/modules/registry/pom.xml index 0132411..9809db0 100644 --- a/modules/registry/pom.xml +++ b/modules/registry/pom.xml @@ -32,7 +32,7 @@ <modules> <module>registry-cpi</module> <module>registry-core</module> - <!--<module>jpa-gen</module>--> + <module>registry-tools</module> </modules> </profile> </profiles> http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java index dfc655d..9e6dff0 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java @@ -41,6 +41,7 @@ public class AppCatalogJPAUtils { private static final String APPCATALOG_JDBC_PWD = "appcatalog.jdbc.password"; private static final String APPCATALOG_VALIDATION_QUERY = "appcatalog.validationQuery"; private static final String JPA_CACHE_SIZE = "jpa.cache.size"; + private static final String JPA_CACHE_ENABLED = "cache.enable"; @PersistenceUnit(unitName="appcatalog_data") protected static EntityManagerFactory factory; @PersistenceContext(unitName="appcatalog_data") @@ -59,8 +60,8 @@ public class AppCatalogJPAUtils { properties.put("openjpa.ConnectionProperties", connectionProperties); properties.put("openjpa.DynamicEnhancementAgent", "true"); properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported"); - properties.put("openjpa.DataCache","true(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)"); - properties.put("openjpa.QueryCache","true(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)"); + properties.put("openjpa.DataCache","" + readServerProperties(JPA_CACHE_ENABLED) + "(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)"); + properties.put("openjpa.QueryCache","" + readServerProperties(JPA_CACHE_ENABLED) + "(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)"); properties.put("openjpa.RemoteCommitProvider","sjvm"); properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO"); properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/jpa-gen/pom.xml ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/jpa-gen/pom.xml b/modules/registry/registry-tools/jpa-gen/pom.xml new file mode 100644 index 0000000..663f3e2 --- /dev/null +++ b/modules/registry/registry-tools/jpa-gen/pom.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!--Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under + the Apache License, Version 2.0 (theà "License"); you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to + in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF + ANY ~ KIND, either express or implied. See the License for the specific language governing permissions and limitations under + the License. --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <parent> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-registry-tools</artifactId> + <version>0.16-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + <artifactId>jpa-gen</artifactId> + <packaging>jar</packaging> + <name>JPA Class Data Generator</name> + <url>http://airavata.apache.org/</url> + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/BatchQueueGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/BatchQueueGenerator.java b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/BatchQueueGenerator.java new file mode 100644 index 0000000..9cc6558 --- /dev/null +++ b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/BatchQueueGenerator.java @@ -0,0 +1,88 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package appcatalog.computeresource; + +import generators.JPAClassGenerator; +import generators.JPAResourceClassGenerator; +import generators.SQLGenerator; + +import java.util.Arrays; + +import model.JPAClassModel; +import model.JPAResourceClassModel; +import model.SQLData; + +public class BatchQueueGenerator { + private static SQLData createSQLData() { + SQLData data = new SQLData(); + data.setTableName("BATCH_QUEUE"); + data.getFieldData().put("COMPUTE_RESOURCE_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("QUEUE_NAME", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("QUEUE_DESCRIPTION", Arrays.asList(new String[]{"VARCHAR", "(255)",})); + data.getFieldData().put("MAX_RUNTIME", Arrays.asList(new String[]{"INTEGER"})); + data.getFieldData().put("MAX_NODES", Arrays.asList(new String[]{"INTEGER"})); + data.getFieldData().put("MAX_PROCESSORS", Arrays.asList(new String[]{"INTEGER"})); + data.getFieldData().put("MAX_JOB_IN_QUEUE", Arrays.asList(new String[]{"INTEGER"})); + data.getPrimaryKeys().add("COMPUTE_RESOURCE_ID"); + data.getPrimaryKeys().add("QUEUE_NAME"); + data.getForiegnKeys().put("COMPUTE_RESOURCE_ID", new SQLData.ForiegnKeyData("COMPUTE_RESOURCE(RESOURCE_ID)","ComputeResource","ComputeHostResource")); + return data; + } + public static void testSqlGen() { + SQLData data = createSQLData(); + SQLGenerator sqlGenerator = new SQLGenerator(); + System.out.println(sqlGenerator.generateSQLCreateQuery(data)); + } + + public static void testJPAClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + jpaClassGenerator.setJpaClassPackageName("org.apache.aiaravata.application.catalog.data.model"); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + System.out.println(jpaClassGenerator.generateJPAClass(model)); + System.out.println(jpaClassGenerator.generateJPAPKClass(model.pkClassModel)); + System.out.println(jpaClassGenerator.generatePersistenceXmlEntry(model)); + } + + public static void testJPAResourceClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + JPAResourceClassGenerator jpaResourceClassGenerator = new JPAResourceClassGenerator(); + jpaResourceClassGenerator.setExceptionClassName("AppCatalogException"); + jpaResourceClassGenerator.setJpaUtilsClassName("AppCatalogJPAUtils"); + jpaResourceClassGenerator.setResourceTypeClassName("AppCatalogResourceType"); + jpaResourceClassGenerator.setQueryGeneratorClassName("AppCatalogQueryGenerator"); + + JPAResourceClassModel model2 = jpaResourceClassGenerator.createJPAResourceClassModel(model); + System.out.println(jpaResourceClassGenerator.generateJPAResourceClass(model2)); + System.out.println(jpaResourceClassGenerator.generateAbstractResourceClassUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogResourceTypeUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogJPAUtilUpdates(model2)); + + } + public static void main(String[] args) { + testSqlGen(); + testJPAClassGen(); + testJPAResourceClassGen(); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/ComputeResourceDescriptionGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/ComputeResourceDescriptionGenerator.java b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/ComputeResourceDescriptionGenerator.java new file mode 100644 index 0000000..c61a518 --- /dev/null +++ b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/ComputeResourceDescriptionGenerator.java @@ -0,0 +1,82 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package appcatalog.computeresource; + +import generators.JPAClassGenerator; +import generators.JPAResourceClassGenerator; +import generators.SQLGenerator; + +import java.util.Arrays; + +import model.JPAClassModel; +import model.JPAResourceClassModel; +import model.SQLData; + +public class ComputeResourceDescriptionGenerator { + private static SQLData createSQLData() { + SQLData data = new SQLData(); + data.setTableName("COMPUTE_RESOURCE"); + data.getFieldData().put("RESOURCE_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("HOST_NAME", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("RESOURCE_DESCRIPTION", Arrays.asList(new String[]{"VARCHAR", "(255)"})); + data.getPrimaryKeys().add("RESOURCE_ID"); + return data; + } + public static void testSqlGen() { + SQLData data = createSQLData(); + SQLGenerator sqlGenerator = new SQLGenerator(); + System.out.println(sqlGenerator.generateSQLCreateQuery(data)); + } + + public static void testJPAClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + jpaClassGenerator.setJpaClassPackageName("org.apache.aiaravata.application.catalog.data.model"); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + System.out.println(jpaClassGenerator.generateJPAClass(model)); + System.out.println(jpaClassGenerator.generateJPAPKClass(model.pkClassModel)); + System.out.println(jpaClassGenerator.generatePersistenceXmlEntry(model)); + } + + public static void testJPAResourceClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + JPAResourceClassGenerator jpaResourceClassGenerator = new JPAResourceClassGenerator(); + jpaResourceClassGenerator.setExceptionClassName("AppCatalogException"); + jpaResourceClassGenerator.setJpaUtilsClassName("AppCatalogJPAUtils"); + jpaResourceClassGenerator.setResourceTypeClassName("AppCatalogResourceType"); + jpaResourceClassGenerator.setQueryGeneratorClassName("AppCatalogQueryGenerator"); + + JPAResourceClassModel model2 = jpaResourceClassGenerator.createJPAResourceClassModel(model); + System.out.println(jpaResourceClassGenerator.generateJPAResourceClass(model2)); + System.out.println(jpaResourceClassGenerator.generateAbstractResourceClassUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogResourceTypeUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogJPAUtilUpdates(model2)); + + } + public static void main(String[] args) { + testSqlGen(); + testJPAClassGen(); + testJPAResourceClassGen(); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/DataMovementInterfaceGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/DataMovementInterfaceGenerator.java b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/DataMovementInterfaceGenerator.java new file mode 100644 index 0000000..21c1028 --- /dev/null +++ b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/DataMovementInterfaceGenerator.java @@ -0,0 +1,85 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package appcatalog.computeresource; + +import generators.JPAClassGenerator; +import generators.JPAResourceClassGenerator; +import generators.SQLGenerator; + +import java.util.Arrays; + +import model.JPAClassModel; +import model.JPAResourceClassModel; +import model.SQLData; + +public class DataMovementInterfaceGenerator { + private static SQLData createSQLData() { + SQLData data = new SQLData(); + data.setTableName("DATA_MOVEMENT_INTERFACE"); + data.getFieldData().put("COMPUTE_RESOURCE_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("DATA_MOVEMENT_INTERFACE_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("DATA_MOVEMENT_PROTOCOL", Arrays.asList(new String[]{"VARCHAR", "(255)","NOT", "NULL"})); + data.getFieldData().put("PRIORITY_ORDER", Arrays.asList(new String[]{"INTEGER"})); + data.getPrimaryKeys().add("COMPUTE_RESOURCE_ID"); + data.getPrimaryKeys().add("DATA_MOVEMENT_INTERFACE_ID"); + data.getForiegnKeys().put("COMPUTE_RESOURCE_ID", new SQLData.ForiegnKeyData("COMPUTE_RESOURCE(RESOURCE_ID)","ComputeResource","ComputeHostResource")); + return data; + } + public static void testSqlGen() { + SQLData data = createSQLData(); + SQLGenerator sqlGenerator = new SQLGenerator(); + System.out.println(sqlGenerator.generateSQLCreateQuery(data)); + } + + public static void testJPAClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + jpaClassGenerator.setJpaClassPackageName("org.apache.aiaravata.application.catalog.data.model"); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + System.out.println(jpaClassGenerator.generateJPAClass(model)); + System.out.println(jpaClassGenerator.generateJPAPKClass(model.pkClassModel)); + System.out.println(jpaClassGenerator.generatePersistenceXmlEntry(model)); + } + + public static void testJPAResourceClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + JPAResourceClassGenerator jpaResourceClassGenerator = new JPAResourceClassGenerator(); + jpaResourceClassGenerator.setExceptionClassName("AppCatalogException"); + jpaResourceClassGenerator.setJpaUtilsClassName("AppCatalogJPAUtils"); + jpaResourceClassGenerator.setResourceTypeClassName("AppCatalogResourceType"); + jpaResourceClassGenerator.setQueryGeneratorClassName("AppCatalogQueryGenerator"); + + JPAResourceClassModel model2 = jpaResourceClassGenerator.createJPAResourceClassModel(model); + System.out.println(jpaResourceClassGenerator.generateJPAResourceClass(model2)); + System.out.println(jpaResourceClassGenerator.generateAbstractResourceClassUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogResourceTypeUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogJPAUtilUpdates(model2)); + + } + public static void main(String[] args) { + testSqlGen(); + testJPAClassGen(); + testJPAResourceClassGen(); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/FileSystemsGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/FileSystemsGenerator.java b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/FileSystemsGenerator.java new file mode 100644 index 0000000..34f07e7 --- /dev/null +++ b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/FileSystemsGenerator.java @@ -0,0 +1,84 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package appcatalog.computeresource; + +import generators.JPAClassGenerator; +import generators.JPAResourceClassGenerator; +import generators.SQLGenerator; + +import java.util.Arrays; + +import model.JPAClassModel; +import model.JPAResourceClassModel; +import model.SQLData; + +public class FileSystemsGenerator { + private static SQLData createSQLData() { + SQLData data = new SQLData(); + data.setTableName("COMPUTE_RESOURCE_FILE_SYSTEM"); + data.getFieldData().put("COMPUTE_RESOURCE_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("FILE_SYSTEM", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("PATH", Arrays.asList(new String[]{"VARCHAR", "(255)",})); + data.getPrimaryKeys().add("COMPUTE_RESOURCE_ID"); + data.getPrimaryKeys().add("FILE_SYSTEM"); + data.getForiegnKeys().put("COMPUTE_RESOURCE_ID", new SQLData.ForiegnKeyData("COMPUTE_RESOURCE(RESOURCE_ID)","ComputeResource","ComputeHostResource")); + return data; + } + public static void testSqlGen() { + SQLData data = createSQLData(); + SQLGenerator sqlGenerator = new SQLGenerator(); + System.out.println(sqlGenerator.generateSQLCreateQuery(data)); + } + + public static void testJPAClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + jpaClassGenerator.setJpaClassPackageName("org.apache.aiaravata.application.catalog.data.model"); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + System.out.println(jpaClassGenerator.generateJPAClass(model)); + System.out.println(jpaClassGenerator.generateJPAPKClass(model.pkClassModel)); + System.out.println(jpaClassGenerator.generatePersistenceXmlEntry(model)); + } + + public static void testJPAResourceClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + JPAResourceClassGenerator jpaResourceClassGenerator = new JPAResourceClassGenerator(); + jpaResourceClassGenerator.setExceptionClassName("AppCatalogException"); + jpaResourceClassGenerator.setJpaUtilsClassName("AppCatalogJPAUtils"); + jpaResourceClassGenerator.setResourceTypeClassName("AppCatalogResourceType"); + jpaResourceClassGenerator.setQueryGeneratorClassName("AppCatalogQueryGenerator"); + + JPAResourceClassModel model2 = jpaResourceClassGenerator.createJPAResourceClassModel(model); + System.out.println(jpaResourceClassGenerator.generateJPAResourceClass(model2)); + System.out.println(jpaResourceClassGenerator.generateAbstractResourceClassUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogResourceTypeUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogJPAUtilUpdates(model2)); + + } + public static void main(String[] args) { + testSqlGen(); + testJPAClassGen(); + testJPAResourceClassGen(); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/GridFTPDataMovementGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/GridFTPDataMovementGenerator.java b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/GridFTPDataMovementGenerator.java new file mode 100644 index 0000000..418fadc --- /dev/null +++ b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/GridFTPDataMovementGenerator.java @@ -0,0 +1,82 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package appcatalog.computeresource; + +import generators.JPAClassGenerator; +import generators.JPAResourceClassGenerator; +import generators.SQLGenerator; + +import java.util.Arrays; + +import model.JPAClassModel; +import model.JPAResourceClassModel; +import model.SQLData; + +public class GridFTPDataMovementGenerator { + private static SQLData createSQLData() { + SQLData data = new SQLData(); + data.setTableName("GRIDFTP_DATA_MOVEMENT"); + data.getFieldData().put("DATA_MOVEMENT_INTERFACE_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("SECURITY_PROTOCOL", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getPrimaryKeys().add("DATA_MOVEMENT_INTERFACE_ID"); + return data; + } + + public static void testSqlGen() { + SQLData data = createSQLData(); + SQLGenerator sqlGenerator = new SQLGenerator(); + System.out.println(sqlGenerator.generateSQLCreateQuery(data)); + } + + public static void testJPAClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + jpaClassGenerator.setJpaClassPackageName("org.apache.aiaravata.application.catalog.data.model"); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + System.out.println(jpaClassGenerator.generateJPAClass(model)); + System.out.println(jpaClassGenerator.generateJPAPKClass(model.pkClassModel)); + System.out.println(jpaClassGenerator.generatePersistenceXmlEntry(model)); + } + + public static void testJPAResourceClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + JPAResourceClassGenerator jpaResourceClassGenerator = new JPAResourceClassGenerator(); + jpaResourceClassGenerator.setExceptionClassName("AppCatalogException"); + jpaResourceClassGenerator.setJpaUtilsClassName("AppCatalogJPAUtils"); + jpaResourceClassGenerator.setResourceTypeClassName("AppCatalogResourceType"); + jpaResourceClassGenerator.setQueryGeneratorClassName("AppCatalogQueryGenerator"); + + JPAResourceClassModel model2 = jpaResourceClassGenerator.createJPAResourceClassModel(model); + System.out.println(jpaResourceClassGenerator.generateJPAResourceClass(model2)); + System.out.println(jpaResourceClassGenerator.generateAbstractResourceClassUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogResourceTypeUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogJPAUtilUpdates(model2)); + + } + public static void main(String[] args) { + testSqlGen(); + testJPAClassGen(); + testJPAResourceClassGen(); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/GridFTPEndpointsGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/GridFTPEndpointsGenerator.java b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/GridFTPEndpointsGenerator.java new file mode 100644 index 0000000..fc4e6ec --- /dev/null +++ b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/GridFTPEndpointsGenerator.java @@ -0,0 +1,83 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package appcatalog.computeresource; + +import generators.JPAClassGenerator; +import generators.JPAResourceClassGenerator; +import generators.SQLGenerator; + +import java.util.Arrays; + +import model.JPAClassModel; +import model.JPAResourceClassModel; +import model.SQLData; + +public class GridFTPEndpointsGenerator { + private static SQLData createSQLData() { + SQLData data = new SQLData(); + data.setTableName("GRIDFTP_ENDPOINT"); + data.getFieldData().put("DATA_MOVEMENT_INTERFACE_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("ENDPOINT", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getPrimaryKeys().add("DATA_MOVEMENT_INTERFACE_ID"); + data.getPrimaryKeys().add("ENDPOINT"); + data.getForiegnKeys().put("DATA_MOVEMENT_INTERFACE_ID", new SQLData.ForiegnKeyData("GRIDFTP_DATA_MOVEMENT(DATA_MOVEMENT_INTERFACE_ID)","GridftpDataMovement","GridftpDataMovementResource")); + return data; + } + public static void testSqlGen() { + SQLData data = createSQLData(); + SQLGenerator sqlGenerator = new SQLGenerator(); + System.out.println(sqlGenerator.generateSQLCreateQuery(data)); + } + + public static void testJPAClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + jpaClassGenerator.setJpaClassPackageName("org.apache.aiaravata.application.catalog.data.model"); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + System.out.println(jpaClassGenerator.generateJPAClass(model)); + System.out.println(jpaClassGenerator.generateJPAPKClass(model.pkClassModel)); + System.out.println(jpaClassGenerator.generatePersistenceXmlEntry(model)); + } + + public static void testJPAResourceClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + JPAResourceClassGenerator jpaResourceClassGenerator = new JPAResourceClassGenerator(); + jpaResourceClassGenerator.setExceptionClassName("AppCatalogException"); + jpaResourceClassGenerator.setJpaUtilsClassName("AppCatalogJPAUtils"); + jpaResourceClassGenerator.setResourceTypeClassName("AppCatalogResourceType"); + jpaResourceClassGenerator.setQueryGeneratorClassName("AppCatalogQueryGenerator"); + + JPAResourceClassModel model2 = jpaResourceClassGenerator.createJPAResourceClassModel(model); + System.out.println(jpaResourceClassGenerator.generateJPAResourceClass(model2)); + System.out.println(jpaResourceClassGenerator.generateAbstractResourceClassUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogResourceTypeUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogJPAUtilUpdates(model2)); + + } + public static void main(String[] args) { + testSqlGen(); + testJPAClassGen(); + testJPAResourceClassGen(); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/JobManagerCommandGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/JobManagerCommandGenerator.java b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/JobManagerCommandGenerator.java new file mode 100644 index 0000000..45cdbb6 --- /dev/null +++ b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/JobManagerCommandGenerator.java @@ -0,0 +1,84 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package appcatalog.computeresource; + +import generators.JPAClassGenerator; +import generators.JPAResourceClassGenerator; +import generators.SQLGenerator; + +import java.util.Arrays; + +import model.JPAClassModel; +import model.JPAResourceClassModel; +import model.SQLData; + +public class JobManagerCommandGenerator { + private static SQLData createSQLData() { + SQLData data = new SQLData(); + data.setTableName("JOB_MANAGER_COMMAND"); + data.getFieldData().put("RESOURCE_JOB_MANAGER_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("COMMAND_TYPE", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("COMMAND", Arrays.asList(new String[]{"VARCHAR", "(255)",})); + data.getPrimaryKeys().add("RESOURCE_JOB_MANAGER_ID"); + data.getPrimaryKeys().add("COMMAND_TYPE"); + data.getForiegnKeys().put("RESOURCE_JOB_MANAGER_ID", new SQLData.ForiegnKeyData("RESOURCE_JOB_MANAGER(RESOURCE_JOB_MANAGER_ID)","ResourceJobManager","ResourceJobManagerResource")); + return data; + } + public static void testSqlGen() { + SQLData data = createSQLData(); + SQLGenerator sqlGenerator = new SQLGenerator(); + System.out.println(sqlGenerator.generateSQLCreateQuery(data)); + } + + public static void testJPAClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + jpaClassGenerator.setJpaClassPackageName("org.apache.aiaravata.application.catalog.data.model"); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + System.out.println(jpaClassGenerator.generateJPAClass(model)); + System.out.println(jpaClassGenerator.generateJPAPKClass(model.pkClassModel)); + System.out.println(jpaClassGenerator.generatePersistenceXmlEntry(model)); + } + + public static void testJPAResourceClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + JPAResourceClassGenerator jpaResourceClassGenerator = new JPAResourceClassGenerator(); + jpaResourceClassGenerator.setExceptionClassName("AppCatalogException"); + jpaResourceClassGenerator.setJpaUtilsClassName("AppCatalogJPAUtils"); + jpaResourceClassGenerator.setResourceTypeClassName("AppCatalogResourceType"); + jpaResourceClassGenerator.setQueryGeneratorClassName("AppCatalogQueryGenerator"); + + JPAResourceClassModel model2 = jpaResourceClassGenerator.createJPAResourceClassModel(model); + System.out.println(jpaResourceClassGenerator.generateJPAResourceClass(model2)); + System.out.println(jpaResourceClassGenerator.generateAbstractResourceClassUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogResourceTypeUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogJPAUtilUpdates(model2)); + + } + public static void main(String[] args) { + testSqlGen(); + testJPAClassGen(); + testJPAResourceClassGen(); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/JobSubmissionInterfaceGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/JobSubmissionInterfaceGenerator.java b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/JobSubmissionInterfaceGenerator.java new file mode 100644 index 0000000..16fa903 --- /dev/null +++ b/modules/registry/registry-tools/jpa-gen/src/main/java/appcatalog/computeresource/JobSubmissionInterfaceGenerator.java @@ -0,0 +1,85 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package appcatalog.computeresource; + +import generators.JPAClassGenerator; +import generators.JPAResourceClassGenerator; +import generators.SQLGenerator; + +import java.util.Arrays; + +import model.JPAClassModel; +import model.JPAResourceClassModel; +import model.SQLData; + +public class JobSubmissionInterfaceGenerator { + private static SQLData createSQLData() { + SQLData data = new SQLData(); + data.setTableName("JOB_SUBMISSION_INTERFACE"); + data.getFieldData().put("COMPUTE_RESOURCE_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("JOB_SUBMISSION_INTERFACE_ID", Arrays.asList(new String[]{"VARCHAR", "(255)", "NOT", "NULL"})); + data.getFieldData().put("JOB_SUBMISSION_PROTOCOL", Arrays.asList(new String[]{"VARCHAR", "(255)","NOT", "NULL"})); + data.getFieldData().put("PRIORITY_ORDER", Arrays.asList(new String[]{"INTEGER"})); + data.getPrimaryKeys().add("COMPUTE_RESOURCE_ID"); + data.getPrimaryKeys().add("JOB_SUBMISSION_INTERFACE_ID"); + data.getForiegnKeys().put("COMPUTE_RESOURCE_ID", new SQLData.ForiegnKeyData("COMPUTE_RESOURCE(RESOURCE_ID)","ComputeResource","ComputeHostResource")); + return data; + } + public static void testSqlGen() { + SQLData data = createSQLData(); + SQLGenerator sqlGenerator = new SQLGenerator(); + System.out.println(sqlGenerator.generateSQLCreateQuery(data)); + } + + public static void testJPAClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + jpaClassGenerator.setJpaClassPackageName("org.apache.aiaravata.application.catalog.data.model"); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + System.out.println(jpaClassGenerator.generateJPAClass(model)); + System.out.println(jpaClassGenerator.generateJPAPKClass(model.pkClassModel)); + System.out.println(jpaClassGenerator.generatePersistenceXmlEntry(model)); + } + + public static void testJPAResourceClassGen() { + SQLData data = createSQLData(); + JPAClassGenerator jpaClassGenerator = new JPAClassGenerator(); + JPAClassModel model = jpaClassGenerator.createJPAClassModel(data); + JPAResourceClassGenerator jpaResourceClassGenerator = new JPAResourceClassGenerator(); + jpaResourceClassGenerator.setExceptionClassName("AppCatalogException"); + jpaResourceClassGenerator.setJpaUtilsClassName("AppCatalogJPAUtils"); + jpaResourceClassGenerator.setResourceTypeClassName("AppCatalogResourceType"); + jpaResourceClassGenerator.setQueryGeneratorClassName("AppCatalogQueryGenerator"); + + JPAResourceClassModel model2 = jpaResourceClassGenerator.createJPAResourceClassModel(model); + System.out.println(jpaResourceClassGenerator.generateJPAResourceClass(model2)); + System.out.println(jpaResourceClassGenerator.generateAbstractResourceClassUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogResourceTypeUpdates(model2)); + System.out.println(jpaResourceClassGenerator.generateAppCatalogJPAUtilUpdates(model2)); + + } + public static void main(String[] args) { + testSqlGen(); + testJPAClassGen(); + testJPAResourceClassGen(); + } +}
