Skip to content

Commit

Permalink
Correct errors in Java metdata generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
scharris committed May 21, 2021
1 parent cb007e7 commit 6f511e5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sqljson-query",
"version": "1.0.12",
"version": "1.1.0",
"description": "Command line tool to generate SQL/JSON queries and Typescript types for query results.",
"keywords": [
"SQL",
Expand Down Expand Up @@ -35,7 +35,7 @@
"devDependencies": {
"@types/ajv": "^1.0.0",
"@types/jest": "^26.0.23",
"@types/lodash": "^4.14.169",
"@types/lodash": "^4.14.170",
"@types/minimist": "^1.2.1",
"@types/node": "^14.17.0",
"@types/pg": "^7.14.11",
Expand Down
9 changes: 6 additions & 3 deletions src/relations-md-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,24 @@ function relationsJavaSource(dbmd: DatabaseMetadata): string
relMd => relMd
);

parts.push('public class Relations');
parts.push('public class RelationsMetadata');
parts.push('{');

for ( const [schema, relMds] of schemaToRelMdsMap.entries() )
{
parts.push(` public static class ${schema} = { // schema '${schema}'\n`);
parts.push(` public static class ${schema} // schema '${schema}'`);
parts.push(' {');

for ( const relMd of relMds )
{
parts.push(indentLines(relationMetadataJavaSource(relMd), 4));
}

parts.push("}"); // close schema object
parts.push(" }"); // schema class
}

parts.push("}"); // Relations class

return parts.join('\n');
}

Expand Down
44 changes: 26 additions & 18 deletions src/result-types-source-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,26 +227,34 @@ function javaResultTypeDeclaration
)
: string
{
const lines: string[] = [];
const resTypeName = resTypeNameAssignments.get(resType)!;
const fieldDecls: string[] = [];

resType.tableFieldProperties.forEach(f => {
const fieldType = tableFieldPropertyType(f, resType, customPropTypeFn, 'Java');
fieldDecls.push(`public ${fieldType} ${f.name};`);
});
resType.tableExpressionProperty.forEach(f => {
const fieldType = tableExpressionPropertyType(f, 'Java');
fieldDecls.push(`public ${fieldType} ${f.name};`);
});
resType.parentReferenceProperties.forEach(f => {
const fieldType = parentReferencePropertyType(f, resTypeNameAssignments, 'Java');
fieldDecls.push(`public ${fieldType} ${f.name};`);
});
resType.childCollectionProperties.forEach(f => {
const fieldType = childCollectionPropertyType(f, resTypeNameAssignments, customPropTypeFn, 'Java');
fieldDecls.push(`public ${fieldType} ${f.name};`);
});

lines.push(`public static class ${resTypeName}`);
lines.push('{');
resType.tableFieldProperties.forEach(f => lines.push(' ' +
`public ${tableFieldPropertyType(f, resType, customPropTypeFn, 'Java')} ${f.name};`
));
resType.tableExpressionProperty.forEach(f => lines.push(' ' +
`public ${tableExpressionPropertyType(f, 'Java')} ${f.name};`
));
resType.parentReferenceProperties.forEach(f => lines.push(' ' +
`public ${parentReferencePropertyType(f, resTypeNameAssignments, 'Java')} ${f.name};`
));
resType.childCollectionProperties.forEach(f => lines.push(' ' +
`public ${childCollectionPropertyType(f, resTypeNameAssignments, customPropTypeFn, 'Java')} ${f.name};`
));
lines.push('}')
const resTypeName = resTypeNameAssignments.get(resType)!;

return lines.join('\n');
return (
'@SuppressWarnings("nullness") // because fields will be set directly by the deserializer not by constructor\n' +
`public static class ${resTypeName}\n` +
'{\n' +
indentLines(fieldDecls.join('\n'), 2) + '\n' +
'}'
);
}

function tableFieldPropertyType
Expand Down

0 comments on commit 6f511e5

Please sign in to comment.