private MemberAnnotation idmemb() { Expect( Token.AT, Token.ID, Token.ROUNDOPEN, Token.NAME, Token.EQUALS, Token.QUOTEDLITERAL ); string nameAttribute = lexan.TokenValue; Expect(Token.ROUNDCLOSE); string fieldType = str(); Expect(Token.WHITESPACE); string fieldName = str(); Expect(Token.SEMICOLON); var memberAnnotation = new MemberAnnotation( "Id", fieldType, fieldName ); memberAnnotation.Attributes.Add("name", nameAttribute); return(memberAnnotation); }
private MemberAnnotation colmemb() { Expect( Token.COLUMN, Token.ROUNDOPEN, Token.NAME, Token.EQUALS, Token.QUOTEDLITERAL ); string nameAttribute = lexan.TokenValue; string lengthAttribute = null; if (lexan.Lookahead != Token.ROUNDCLOSE) { Expect( Token.COMMA, Token.WHITESPACE, Token.LENGTH, Token.EQUALS, Token.QUOTEDLITERAL ); int numb = 0; if (!int.TryParse(lexan.TokenValue, out numb)) { throw new Exception("Not a number."); } if (numb <= 0) { throw new Exception("Not a positive number."); } lengthAttribute = numb.ToString(); } Expect(Token.ROUNDCLOSE); string fieldType = str(); Expect(Token.WHITESPACE); string fieldName = str(); Expect(Token.SEMICOLON); var memberAnnotation = new MemberAnnotation( "Column", fieldType, fieldName ); memberAnnotation.Attributes.Add("name", nameAttribute); if (lengthAttribute != null) { memberAnnotation.Attributes.Add("length", lengthAttribute); } return(memberAnnotation); }
private string GenerateInterfaceCode(MemberAnnotation membAnn) { if (membAnn.AnnotationName == "One2Many" || membAnn.AnnotationName == "Many2One") { return($"public {membAnn.FieldType} {membAnn.FieldName};"); } return($"public {langToCSharp[membAnn.FieldType]} {membAnn.FieldName};"); }
private MemberAnnotation relmemb() { Expect(Token.RELATIONSHIP); string relType = lexan.TokenValue; Expect(Token.ROUNDOPEN, Token.NAME, Token.EQUALS, Token.QUOTEDLITERAL); string nameAttribute = lexan.TokenValue; Expect(Token.COMMA, Token.WHITESPACE, Token.TARGET, Token.EQUALS, Token.QUOTEDLITERAL); string targetAttribute = lexan.TokenValue; string mappedByAttribute = null; if (relType == "One2Many") { Expect( Token.COMMA, Token.WHITESPACE, Token.MAPPEDBY, Token.EQUALS, Token.QUOTEDLITERAL ); mappedByAttribute = lexan.TokenValue; } Expect(Token.ROUNDCLOSE); string fieldType = str(); Expect(Token.WHITESPACE); string fieldName = str(); Expect(Token.SEMICOLON); var memberAnnotation = new MemberAnnotation( relType, fieldType, fieldName ); memberAnnotation.Attributes.Add("name", nameAttribute); memberAnnotation.Attributes.Add("target", targetAttribute); if (mappedByAttribute != null) { memberAnnotation.Attributes.Add("mappedBy", mappedByAttribute); } return(memberAnnotation); }
private string GenerateSQLCode(MemberAnnotation membAnn) { var strBuilder = new StringBuilder(); switch (membAnn.AnnotationName) { case "Id": strBuilder.Append( $"{membAnn.Attributes["name"]} {GetSQLType(membAnn.FieldType)} " + "NOT NULL PRIMARY KEY" ); break; case "Column": strBuilder.Append($"{membAnn.Attributes["name"]} {GetSQLType(membAnn.FieldType)}"); if (membAnn.Attributes.ContainsKey("length") && membAnn.FieldType == "String") { strBuilder.Append($"({membAnn.Attributes["length"]})"); } break; case "Many2One": string name = membAnn.Attributes["name"]; strBuilder.Append($"{name} "); var tabAnn = tableAnnotations.Find(ann => ann.InterfaceName == membAnn.Attributes["target"] ); var referencedMemb = tabAnn.MemberAnnotations.Find(mem => mem.AnnotationName == "Id" ); string sqlType = langToSQL[referencedMemb.FieldType]; strBuilder.Append($"{sqlType}, FOREIGN KEY ({name}) REFERENCES " + $"{tabAnn.Attributes["name"]}" + $"({referencedMemb.Attributes["name"]})"); break; } return(strBuilder.ToString()); }