List of usage examples for org.hibernate.mapping PrimaryKey setName
public void setName(String name)
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected void createPKComposite(Mappings mappings, com.manydesigns.portofino.model.database.Table mdTable, String pkName, RootClass clazz, Table tab, List<com.manydesigns.portofino.model.database.Column> columnPKList) { PrimaryKey primaryKey = new PrimaryKey(); primaryKey.setName(pkName); primaryKey.setTable(tab);/*from w ww . j a v a2 s .co m*/ clazz.setEmbeddedIdentifier(true); Component component = new Component(mappings, clazz); component.setDynamic(mdTable.getActualJavaClass() == null); String name; name = mdTable.getQualifiedName(); component.setRoleName(name + ".id"); component.setEmbedded(true); //component.setNodeName("id"); component.setKey(true); component.setNullValue("undefined"); if (!component.isDynamic()) { component.setComponentClassName(mdTable.getJavaClass()); //TODO verificare se non si intende actualJavaClass } boolean hasErrors = false; for (com.manydesigns.portofino.model.database.Column column : columnPKList) { if (column == null) { throw new InternalError("Null column"); } Column col = createColumn(mappings, tab, column); hasErrors = col == null || hasErrors; if (col != null) { primaryKey.addColumn(col); Property prop = createProperty(column, col.getValue()); prop.setCascade("none"); //prop.setPropertyAccessorName("property"); interferisce con il generator pi sotto prop.setPersistentClass(clazz); component.addProperty(prop); //Generator not supported for embedded map identifier //See https://forum.hibernate.org/viewtopic.php?t=945273 //See Component.buildIdentifierGenerator() /*String columnName = column.getColumnName(); PrimaryKeyColumn pkCol = mdTable.getPrimaryKey().findPrimaryKeyColumnByName(columnName); if(pkCol == null) { logger.error("Column without corresponding PrimaryKeyColumn: {}", columnName); hasErrors = true; continue; } Generator generator = pkCol.getGenerator(); setPKColumnGenerator(mappings, clazz, tab, column, value, generator);*/ } } if (hasErrors) { // TODO PAOLO: se la PK non e' buona, tutta la tabella dovrebbe saltare logger.error("Skipping primary key"); return; } tab.setIdentifierValue(component); clazz.setIdentifier(component); clazz.setDiscriminatorValue(name); tab.setPrimaryKey(primaryKey); }
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected void createPKSingle(Mappings mappings, com.manydesigns.portofino.model.database.Table mdTable, String pkName, RootClass clazz, Table tab, List<com.manydesigns.portofino.model.database.Column> columnPKList) { PrimaryKeyColumn pkcol = mdTable.getPrimaryKey().getPrimaryKeyColumns().get(0); com.manydesigns.portofino.model.database.Column column = columnPKList.get(0); final PrimaryKey primaryKey = new PrimaryKey(); primaryKey.setName(pkName); primaryKey.setTable(tab);// w w w .j a va 2 s.c o m tab.setPrimaryKey(primaryKey); Column col = createColumn(mappings, tab, column); if (col == null) { // TODO PAOLO: se la PK non e' buona, tutta la tabella dovrebbe saltare logger.error("Skipping primary key"); return; } SimpleValue id = (SimpleValue) col.getValue(); //Make the defaults explicit. See section 5.1.4.5. Assigned identifiers in the Hibernate reference //(http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html) id.setIdentifierGeneratorStrategy("assigned"); id.setNullValue("undefined"); tab.getPrimaryKey().addColumn(col); Property prop = createProperty(column, id); clazz.addProperty(prop); prop.setPropertyAccessorName(mappings.getDefaultAccess()); //PropertyGeneration generation = PropertyGeneration.parse(null); //prop.setGeneration(generation); prop.setInsertable(false); prop.setUpdateable(false); Generator generator = pkcol.getGenerator(); setPKColumnGenerator(mappings, clazz, tab, column, id, generator); tab.setIdentifierValue(id); clazz.setIdentifier(id); clazz.setIdentifierProperty(prop); clazz.setDiscriminatorValue(mdTable.getQualifiedName()); }
From source file:org.processbase.engine.bam.db.ScriptGenerator.java
License:Open Source License
public ArrayList<String> getCreateTableScript(MetaKpi metaKpi, int type) { try {/* www .j a v a2 s . c o m*/ Configuration config = new Configuration(); Dialect d = (Dialect) Class.forName(BAMConstants.BAM_DB_DIALECT).newInstance(); Mappings mappings = config.createMappings(); table = mappings.addTable(null, null, metaKpi.getCode(), null, false); Column id = new Column("ID"); SimpleValue idVal = new SimpleValue(table); idVal.setTypeName(TypeFactory.basic("long").getName()); id.setValue(idVal); Column kpiTimeStamp = new Column("KPI_TIMESTAMP"); kpiTimeStamp.setSqlType(TypeFactory.basic(java.util.Date.class.getName()).getName()); Column kpiYear = new Column("KPI_YEAR"); SimpleValue kpiYearVal = new SimpleValue(table); kpiYearVal.setTypeName(TypeFactory.basic("short").getName()); kpiYear.setLength(4); kpiYear.setValue(kpiYearVal); addIndex(kpiYear); Column kpiQuater = new Column("KPI_QUATER"); SimpleValue kpiQuaterVal = new SimpleValue(table); kpiQuaterVal.setTypeName(TypeFactory.basic("short").getName()); kpiQuater.setLength(4); kpiQuater.setValue(kpiQuaterVal); addIndex(kpiQuater); Column kpiMonth = new Column("KPI_MONTH"); SimpleValue kpiMonthVal = new SimpleValue(table); kpiMonthVal.setTypeName(TypeFactory.basic("short").getName()); kpiMonth.setLength(4); kpiMonth.setValue(kpiMonthVal); addIndex(kpiMonth); Column kpiWeek = new Column("KPI_WEEK"); SimpleValue kpiWeekVal = new SimpleValue(table); kpiWeekVal.setTypeName(TypeFactory.basic("short").getName()); kpiWeek.setLength(4); kpiWeek.setValue(kpiWeekVal); addIndex(kpiWeek); Column kpiDay = new Column("KPI_DAY"); SimpleValue kpiDayVal = new SimpleValue(table); kpiDayVal.setTypeName(TypeFactory.basic("short").getName()); kpiDay.setLength(4); kpiDay.setValue(kpiDayVal); addIndex(kpiDay); Column kpiHour = new Column("KPI_HOUR"); SimpleValue kpiHourVal = new SimpleValue(table); kpiHourVal.setTypeName(TypeFactory.basic("short").getName()); kpiHour.setLength(4); kpiHour.setValue(kpiHourVal); addIndex(kpiHour); Column kpiMinute = new Column("KPI_MINUTE"); SimpleValue kpiMinuteVal = new SimpleValue(table); kpiMinuteVal.setTypeName(TypeFactory.basic("short").getName()); kpiMinute.setLength(4); kpiMinute.setValue(kpiMinuteVal); addIndex(kpiMinute); Column kpiDayOfWeek = new Column("KPI_DAY_OF_WEEK"); SimpleValue kpiDayOfWeekVal = new SimpleValue(table); kpiDayOfWeekVal.setTypeName(TypeFactory.basic("short").getName()); kpiDayOfWeek.setLength(4); kpiDayOfWeek.setValue(kpiDayOfWeekVal); addIndex(kpiDayOfWeek); Column serverId = new Column("SERVER_ID"); SimpleValue serverIdVal = new SimpleValue(table); serverIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); serverId.setValue(serverIdVal); serverId.setLength(200); addIndex(serverId); Column eventId = new Column("EVENT_ID"); SimpleValue eventIdVal = new SimpleValue(table); eventIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); eventId.setValue(eventIdVal); eventId.setLength(200); addIndex(eventId); Column eventName = new Column("EVENT_NAME"); SimpleValue eventNameVal = new SimpleValue(table); eventNameVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); eventName.setValue(eventNameVal); eventName.setLength(200); addIndex(eventName); Column processDefinitionId = new Column("PROCESS_DEF_ID"); SimpleValue processDefinitionIdVal = new SimpleValue(table); processDefinitionIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); processDefinitionId.setValue(processDefinitionIdVal); processDefinitionId.setLength(200); addIndex(processDefinitionId); Column processDefinitionName = new Column("PROCESS_DEF_NAME"); SimpleValue processDefinitionNameVal = new SimpleValue(table); processDefinitionNameVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); processDefinitionName.setValue(processDefinitionNameVal); processDefinitionName.setLength(200); addIndex(processDefinitionName); Column processDefinitionVersion = new Column("PROCESS_DEF_VERSION"); SimpleValue processDefinitionVersionVal = new SimpleValue(table); processDefinitionVersionVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); processDefinitionVersion.setValue(processDefinitionVersionVal); processDefinitionVersion.setLength(200); addIndex(processDefinitionVersion); Column processInstanceId = new Column("PROCESS_INST_ID"); SimpleValue processInstanceIdVal = new SimpleValue(table); processInstanceIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); processInstanceId.setValue(processInstanceIdVal); processInstanceId.setLength(200); addIndex(processInstanceId); Column activityInstanceId = new Column("ACT_INST_ID"); SimpleValue activityInstanceIdVal = new SimpleValue(table); activityInstanceIdVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); activityInstanceId.setValue(activityInstanceIdVal); activityInstanceId.setLength(200); addIndex(activityInstanceId); Column activityInstanceName = new Column("ACT_INST_NAME"); SimpleValue activityInstanceNameVal = new SimpleValue(table); activityInstanceNameVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); activityInstanceName.setValue(activityInstanceNameVal); activityInstanceName.setLength(200); addIndex(activityInstanceName); Column activityInstanceIter = new Column("ACT_INST_ITER"); SimpleValue activityInstanceIterVal = new SimpleValue(table); activityInstanceIterVal.setTypeName(TypeFactory.basic("java.lang.String").getName()); activityInstanceIter.setValue(activityInstanceIterVal); activityInstanceIter.setLength(200); addIndex(activityInstanceIter); PrimaryKey key = new PrimaryKey(); key.setName(metaKpi.getCode() + "_PK"); key.addColumn(id); table.setPrimaryKey(key); table.addColumn(id); table.addColumn(kpiTimeStamp); table.addColumn(kpiYear); table.addColumn(kpiQuater); table.addColumn(kpiMonth); table.addColumn(kpiWeek); table.addColumn(kpiDay); table.addColumn(kpiDayOfWeek); table.addColumn(kpiHour); table.addColumn(kpiMinute); table.addColumn(serverId); table.addColumn(eventId); table.addColumn(eventName); table.addColumn(processDefinitionId); table.addColumn(processDefinitionVersion); table.addColumn(processDefinitionName); table.addColumn(processInstanceId); table.addColumn(activityInstanceId); table.addColumn(activityInstanceName); table.addColumn(activityInstanceIter); for (Iterator<MetaDim> i = metaKpi.getMetaDims().iterator(); i.hasNext();) { MetaDim metaDim = i.next(); Column dim = new Column(metaDim.getCode()); SimpleValue dimVal = new SimpleValue(table); dimVal.setTypeName(TypeFactory.basic(metaDim.getValueType()).getName()); dim.setValue(dimVal); if (metaDim.getValueLength() != null) { dim.setLength(metaDim.getValueLength()); } table.addColumn(dim); addIndex(dim); } for (Iterator<MetaFact> i = metaKpi.getMetaFacts().iterator(); i.hasNext();) { MetaFact metaFact = i.next(); Column dim = new Column(metaFact.getCode()); SimpleValue dimVal = new SimpleValue(table); dimVal.setTypeName(TypeFactory.basic("java.math.BigDecimal").getName()); dim.setValue(dimVal); table.addColumn(dim); } if (type == CREATE_SCRIPT) { result.add(0, table.sqlCreateString(d, config.buildMapping(), null, null)); } else if (type == DROP_SCRIPT) { result.clear(); result.add(table.sqlDropString(d, null, null)); } } catch (Exception ex) { ex.printStackTrace(); } return result; }