Skip to content

Commit

Permalink
WIP #68
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdog71 committed Sep 12, 2022
1 parent 20f0dbc commit 245b5f7
Showing 1 changed file with 94 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,44 @@ public static synchronized void generateTablesDatamodel(int initHibernate) {
elementid.addAttribute("name", "cf_id");
elementid.addAttribute("column", "CF_ID__");
elementid.addAttribute("type", "long");
//elementid.addAttribute("insert", "false");
//elementid.addAttribute("update", "false");
Element elementgenerator = elementid.addElement("generator");
elementgenerator.addAttribute("class", "native");
makePrimaryKey(attributlist, elementclass, idCount);
// Set the properties
for (CfAttribut attribut : attributlist) {
if (!attribut.getIdentity()) {
Element elementproperty = elementclass.addElement("property");
elementproperty.addAttribute("name", attribut.getName());
elementproperty.addAttribute("column", attribut.getName() + "_");
elementproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName()));
elementproperty.addAttribute("not-null", "false");
if (attribut.getIsindex()) {
elementproperty.addAttribute("index", "idx_" + attribut.getName());
if ((0 == attribut.getAttributetype().getName().compareToIgnoreCase("classref")) && (1 == attribut.getRelationtype())) {
Element elementmanytoone = elementclass.addElement("many-to-one");
elementmanytoone.addAttribute("name", attribut.getName() + "_ref_");
elementmanytoone.addAttribute("class", attribut.getRelationref().getName());
CfClass foreignclass = cfclassservice.findByName(attribut.getRelationref().getName());
List<CfAttribut> foreignattributlist = cfattributservice.findByClassref(foreignclass);
for (CfAttribut foreignattribut : foreignattributlist) {
if (foreignattribut.getIdentity()) {
Element elementcolumn = elementmanytoone.addElement("column");
elementcolumn.addAttribute("name", foreignattribut.getName());
elementcolumn.addAttribute("not-null", "false");
}
}
} else {
Element elementproperty = elementclass.addElement("property");
elementproperty.addAttribute("name", attribut.getName());
if (0 == attribut.getAttributetype().getName().compareToIgnoreCase("classref")) {
//if (0 == attribut.getRelationtype()) {
elementproperty.addAttribute("column", attribut.getName() + "_ref_n_m_");
//} else {
// elementproperty.addAttribute("column", attribut.getName() + "_ref_1_n_");
//}
} else {
elementproperty.addAttribute("column", attribut.getName() + "_");
}
elementproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName(), attribut.getRelationtype()));
elementproperty.addAttribute("not-null", "false");
if (attribut.getIsindex()) {
elementproperty.addAttribute("index", "idx_" + attribut.getName());
}
}
}
}
Expand All @@ -134,7 +159,7 @@ public static synchronized void generateTablesDatamodel(int initHibernate) {
elementproperty.addAttribute("not-null", "true");
elementproperty.addAttribute("index", "idx_cf_contentref");
}
//System.out.println(xmldoc.asXML());
System.out.println(xmldoc.asXML());
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure().applySetting("hibernate.connection.url", datasourceURL).build();
SessionFactory sessionFactory = new MetadataSources(standardRegistry).addInputStream(new ByteArrayInputStream(xmldoc.asXML().getBytes("UTF-8"))).buildMetadata().buildSessionFactory();
Session session_tables = sessionFactory.openSession();
Expand Down Expand Up @@ -184,6 +209,8 @@ public static synchronized void generateTablesDatamodel(String classname, int in
elementid.addAttribute("name", "cf_id");
elementid.addAttribute("column", "CF_ID__");
elementid.addAttribute("type", "long");
//elementid.addAttribute("insert", "false");
//elementid.addAttribute("update", "false");
Element elementgenerator = elementid.addElement("generator");
elementgenerator.addAttribute("class", "native");
makePrimaryKey(attributlist, elementclass, idCount);
Expand All @@ -192,8 +219,16 @@ public static synchronized void generateTablesDatamodel(String classname, int in
if (!attribut.getIdentity()) {
Element elementproperty = elementclass.addElement("property");
elementproperty.addAttribute("name", attribut.getName());
elementproperty.addAttribute("column", attribut.getName() + "_");
elementproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName()));
if (0 == attribut.getAttributetype().getName().compareToIgnoreCase("classref")) {
if (0 == attribut.getRelationtype()) {
elementproperty.addAttribute("column", attribut.getName() + "_ref_n_m_");
} else {
elementproperty.addAttribute("column", attribut.getName() + "_ref_1_n_");
}
} else {
elementproperty.addAttribute("column", attribut.getName() + "_");
}
elementproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName(), attribut.getRelationtype()));
elementproperty.addAttribute("not-null", "false");
if (attribut.getIsindex()) {
elementproperty.addAttribute("index", "idx_" + attribut.getName());
Expand Down Expand Up @@ -303,7 +338,7 @@ public void deleteContent(CfClasscontent classcontent) {
}
}

private static String getHibernateType(String clownfishtype) {
private static String getHibernateType(String clownfishtype, int relationtype) {
switch (clownfishtype) {
case "boolean":
return "boolean";
Expand All @@ -326,7 +361,11 @@ private static String getHibernateType(String clownfishtype) {
case "text":
return "text";
case "classref":
return "string";
if (0 == relationtype) {
return "string";
} else {
return "long";
}
case "assetref":
return "string";
default:
Expand Down Expand Up @@ -358,8 +397,10 @@ private static void makePrimaryKey(List<CfAttribut> attributlist, Element elemen
Element elementproperty = elementclass.addElement("property");
elementproperty.addAttribute("name", attribut.getName());
elementproperty.addAttribute("column", attribut.getName() + "_");
elementproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName()));
elementproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName(), attribut.getRelationtype()));
elementproperty.addAttribute("index", "idx_" + attribut.getName());
//elementproperty.addAttribute("insert", "false");
//elementproperty.addAttribute("update", "false");
}
}
} else {
Expand All @@ -368,8 +409,10 @@ private static void makePrimaryKey(List<CfAttribut> attributlist, Element elemen
Element elementkeyproperty = elementclass.addElement("property");
elementkeyproperty.addAttribute("name", attribut.getName());
elementkeyproperty.addAttribute("column", attribut.getName() + "_");
elementkeyproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName()));
elementkeyproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName(), attribut.getRelationtype()));
elementkeyproperty.addAttribute("index", "idx_" + attribut.getName());
//elementkeyproperty.addAttribute("insert", "false");
//elementkeyproperty.addAttribute("update", "false");
}
}
}
Expand All @@ -385,34 +428,36 @@ public static synchronized void generateRelationsDatamodel(int initHibernate) {
for (CfAttribut attribut : attributlist) {
switch (attribut.getAttributetype().getName()) {
case "classref":
Element elementclass = root.addElement("class");
elementclass.addAttribute("entity-name", clazz.getName() + "_" + attribut.getName());
elementclass.addAttribute("table", "usr_rel_" + clazz.getName() + "_" + attribut.getName());

Element elementproperty = elementclass.addElement("composite-id");
elementproperty.addAttribute("name", "id_");

Element elementkeyproperty1 = elementproperty.addElement("key-property");
elementkeyproperty1.addAttribute("name", clazz.getName() + "_ref");
elementkeyproperty1.addAttribute("column", clazz.getName() + "_ref_");
elementkeyproperty1.addAttribute("type", "long");

Element elementkeyproperty2 = elementproperty.addElement("key-property");
elementkeyproperty2.addAttribute("name", attribut.getName() + "_ref");
elementkeyproperty2.addAttribute("column", attribut.getName() + "_ref_");
elementkeyproperty2.addAttribute("type", "long");

Element elementproperty3 = elementclass.addElement("property");
elementproperty3.addAttribute("name", clazz.getName() + "_usr_ref");
elementproperty3.addAttribute("column", clazz.getName() + "_usr_ref_");
elementproperty3.addAttribute("type", "long");
elementproperty3.addAttribute("not-null", "false");

Element elementproperty4 = elementclass.addElement("property");
elementproperty4.addAttribute("name", attribut.getName() + "_usr_ref");
elementproperty4.addAttribute("column", attribut.getName() + "_usr_ref_");
elementproperty4.addAttribute("type", "long");
elementproperty4.addAttribute("not-null", "false");
if (0 == attribut.getRelationtype()) {
Element elementclass = root.addElement("class");
elementclass.addAttribute("entity-name", clazz.getName() + "_" + attribut.getName());
elementclass.addAttribute("table", "usr_rel_" + clazz.getName() + "_" + attribut.getName());

Element elementproperty = elementclass.addElement("composite-id");
elementproperty.addAttribute("name", "id_");

Element elementkeyproperty1 = elementproperty.addElement("key-property");
elementkeyproperty1.addAttribute("name", clazz.getName() + "_ref");
elementkeyproperty1.addAttribute("column", clazz.getName() + "_ref_");
elementkeyproperty1.addAttribute("type", "long");

Element elementkeyproperty2 = elementproperty.addElement("key-property");
elementkeyproperty2.addAttribute("name", attribut.getName() + "_ref");
elementkeyproperty2.addAttribute("column", attribut.getName() + "_ref_");
elementkeyproperty2.addAttribute("type", "long");

Element elementproperty3 = elementclass.addElement("property");
elementproperty3.addAttribute("name", clazz.getName() + "_usr_ref");
elementproperty3.addAttribute("column", clazz.getName() + "_usr_ref_");
elementproperty3.addAttribute("type", "long");
elementproperty3.addAttribute("not-null", "false");

Element elementproperty4 = elementclass.addElement("property");
elementproperty4.addAttribute("name", attribut.getName() + "_usr_ref");
elementproperty4.addAttribute("column", attribut.getName() + "_usr_ref_");
elementproperty4.addAttribute("type", "long");
elementproperty4.addAttribute("not-null", "false");
}
break;
case "assetref":
break;
Expand All @@ -422,16 +467,19 @@ public static synchronized void generateRelationsDatamodel(int initHibernate) {
//System.out.println(xmldoc.asXML());
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure().applySetting("hibernate.connection.url", datasourceURL).build();
SessionFactory sessionFactory = new MetadataSources(standardRegistry).addInputStream(new ByteArrayInputStream(xmldoc.asXML().getBytes())).buildMetadata().buildSessionFactory();
System.out.println(xmldoc.asXML());
Session session_relations = sessionFactory.openSession();
Session session_tables = classsessions.get("tables").getSessionFactory().openSession();
classsessions.put("relations", session_relations);
for (CfClass clazz : classlist) {
List<CfAttribut> attributlist = cfattributservice.findByClassref(clazz);
for (CfAttribut attribut : attributlist) {
switch (attribut.getAttributetype().getName()) {
case "classref":
if (initHibernate > 0) {
fillRelation(clazz.getName(), attribut.getName(), session_tables, session_relations);
case "classref":
if (0 == attribut.getRelationtype()) {
if (initHibernate > 0) {
fillRelation(clazz.getName(), attribut.getName(), session_tables, session_relations);
}
}
break;
}
Expand Down Expand Up @@ -602,7 +650,7 @@ private static Map fillEntity(Map entity, CfClasscontent classcontent, List<CfAt
}
} else {
if (null != attributcontent.getContentInteger()) {
entity.put(attributcontent.getAttributref().getName(), attributcontent.getContentInteger());
entity.put(attributcontent.getAttributref().getName(), attributcontent.getContentInteger().longValue());
} else {
entity.put(attributcontent.getAttributref().getName(), null);
}
Expand Down

0 comments on commit 245b5f7

Please sign in to comment.