@Override protected void createTableBody( final StringBuilder createTableSql, final List<FieldDefinition> fieldDefinitions) { final List<FieldDefinition> keyDefinitionList = new ArrayList<FieldDefinition>(); for (FieldDefinition fieldDefinition : fieldDefinitions) { final String type = fieldDefinition.getType(); if (type == null) { throw new RuntimeException("the type of fieldDefinitions should not be null"); } final Mapping mapping = getJdbcTypeMapping().get(type); if (mapping != null) { createTableSql.append(mapping.toDataBaseSting(fieldDefinition)).append(", "); if (fieldDefinition.getIsKey()) { keyDefinitionList.add(fieldDefinition); } } else { throw new RuntimeException( "the type[" + fieldDefinition.getType() + "] is not register for mapping "); } } if (keyDefinitionList.size() < 0) { throw new RuntimeException("no key talbe is not allow"); } else { createTableSql.append(createKeyDefinition(keyDefinitionList)); } }
/** * the keyDefinitionList tableSql. * * @param keyDefinitionList keyDefinitionList * @return createKeyDefinitionsql */ private String createKeyDefinition(final List<FieldDefinition> keyDefinitionList) { final StringBuilder sql = new StringBuilder(); sql.append(" PRIMARY KEY"); boolean isFirst = true; for (FieldDefinition fieldDefinition : keyDefinitionList) { if (isFirst) { sql.append("("); isFirst = false; } else { sql.append(","); } sql.append(fieldDefinition.getName()); } sql.append(")"); return sql.toString(); }