Skip to content

Commit f4a15dd

Browse files
committed
Merge branch '36-add-external-type-parsing' into dev
2 parents 39ea906 + 0b71450 commit f4a15dd

33 files changed

+2711
-466
lines changed

.gitlab-ci.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ bt:mac:
5353
paths:
5454
- objectbox-generator-macOS.zip
5555

56-
# TODO: Prepare CI/Windows to build and test this project; Prerequisites: MinGW Make
5756
t:cmake:win-x64:
58-
tags: [ windows ]
59-
script:
60-
- cd test/integration/cmake/projects && cmake -DMULTI="Visual Studio 17 2022" -P test-cmake-generators.cmake
57+
extends: [ .build ]
58+
tags: [ windows, go ]
59+
after_script:
60+
- zip objectbox-generator-Windows.zip objectbox-generator.exe
61+
artifacts:
62+
expire_in: 1 day
63+
paths:
64+
- objectbox-generator-Windows.zip

internal/generator/binding/annotation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func ParseAnnotations(str string, annotations *map[string]*Annotation, supported
8888
s.value.Details = make(map[string]*Annotation)
8989
var supportedDetails map[string]bool
9090
if s.name == "relation" {
91-
supportedDetails = map[string]bool{"to": true, "name": true, "uid": true}
91+
supportedDetails = map[string]bool{"to": true, "name": true, "uid": true, "external-name": true, "external-type": true}
9292
} else if s.name == "sync" {
9393
supportedDetails = map[string]bool{"sharedglobalids": true}
9494
} else if s.name == "id" {

internal/generator/binding/field.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ func (field *Field) ProcessAnnotations(a map[string]*Annotation) error {
121121
}
122122
}
123123

124+
if a["external-name"] != nil {
125+
field.ModelProperty.ExternalName = a["external-name"].Value
126+
}
127+
if a["external-type"] != nil {
128+
externalTypeValue := a["external-type"].Value
129+
externalType, exists := model.ExternalTypeValues[externalTypeValue]
130+
if !exists {
131+
return fmt.Errorf("invalid external-type '%s' for property %s - must be one of the supported external types", externalTypeValue, field.Name)
132+
}
133+
field.ModelProperty.ExternalType = externalType
134+
}
135+
124136
if a["index"] != nil {
125137
switch strings.ToLower(a["index"].Value) {
126138
case "":

internal/generator/binding/object.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func (object *Object) ProcessAnnotations(a map[string]*Annotation) error {
8888
}
8989
}
9090

91+
if a["external-name"] != nil {
92+
object.ModelEntity.ExternalName = a["external-name"].Value
93+
}
94+
9195
if a["uid"] != nil {
9296
if len(a["uid"].Value) == 0 {
9397
// in case the user doesn't provide `objectbox:"uid"` value, it's considered in-process of setting up UID
@@ -131,6 +135,19 @@ func (object *Object) AddRelation(details map[string]*Annotation) (*model.Standa
131135
return nil, fmt.Errorf("to annotation value must not be empty on relation %s - specify target entity", relation.Name)
132136
}
133137

138+
if details["external-name"] != nil {
139+
relation.ExternalName = details["external-name"].Value
140+
}
141+
142+
if details["external-type"] != nil {
143+
externalTypeValue := details["external-type"].Value
144+
externalType, exists := model.ExternalTypeValues[externalTypeValue]
145+
if !exists {
146+
return nil, fmt.Errorf("invalid external-type '%s' for relation %s - must be one of the supported external types", externalTypeValue, relation.Name)
147+
}
148+
relation.ExternalType = externalType
149+
}
150+
134151
// NOTE: we don't need an actual entity pointer, it's resolved during stored model merging.
135152
relation.Target = &model.Entity{Name: details["to"].Value}
136153

internal/generator/c/schema-reader.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ import (
3232
)
3333

3434
var supportedEntityAnnotations = map[string]bool{
35-
"name": true,
36-
"relation": true, // to-many, standalone
37-
"sync": true,
38-
"transient": true,
39-
"uid": true,
35+
"name": true,
36+
"relation": true, // to-many, standalone
37+
"sync": true,
38+
"transient": true,
39+
"uid": true,
40+
"external-name": true,
4041
}
4142

4243
var supportedPropertyAnnotations = map[string]bool{
@@ -58,6 +59,8 @@ var supportedPropertyAnnotations = map[string]bool{
5859
"hnsw-flags": true,
5960
"hnsw-reparation-backlink-probability": true,
6061
"hnsw-vector-cache-hint-size-kb": true,
62+
"external-name": true,
63+
"external-type": true,
6164
}
6265

6366
// fbSchemaReader reads FlatBuffers schema and populates a model

internal/generator/c/templates/functions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ var funcMap = template.FuncMap{
103103
}
104104
return "OBXHnswFlags_NONE"
105105
},
106+
"CoreExternalTypes": func(val model.ExternalType) string {
107+
return "OBXExternalPropertyType_" + model.ExternalTypeNames[val]
108+
},
106109
"PrintComments": func(tabs int, comments []string) string {
107110
var result string
108111
for _, comment := range comments {

internal/generator/c/templates/model.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ObjectBox Generator - a build time tool for ObjectBox
3-
* Copyright (C) 2018-2024 ObjectBox Ltd. All rights reserved.
3+
* Copyright (C) 2018-2025 ObjectBox Ltd. All rights reserved.
44
* https://objectbox.io
55
*
66
* This file is part of ObjectBox Generator.
@@ -55,11 +55,20 @@ static inline OBX_model* create_obx_model() {
5555
{{- with $entity.Flags}}
5656
obx_model_entity_flags(model, {{CoreEntityFlags .}});
5757
{{- end -}}
58+
{{- if $entity.ExternalName}}
59+
obx_model_entity_external_name(model, "{{ $entity.ExternalName }}");
60+
{{- end -}}
5861
{{range $property := $entity.Properties}}
5962
obx_model_property(model, "{{$property.Name}}", OBXPropertyType_{{PropTypeName $property.Type}}, {{$property.Id.GetId}}, {{$property.Id.GetUid}});
6063
{{- with $property.Flags}}
6164
obx_model_property_flags(model, {{CorePropFlags .}});
6265
{{- end -}}
66+
{{- if $property.ExternalName}}
67+
obx_model_property_external_name(model, "{{ $property.ExternalName }}");
68+
{{- end -}}
69+
{{- if $property.ExternalType}}
70+
obx_model_property_external_type(model, {{CoreExternalTypes $property.ExternalType}});
71+
{{- end -}}
6372
{{- if $property.HnswParams -}}
6473
{{- if $property.HnswParams.Dimensions}}
6574
obx_model_property_index_hnsw_dimensions(model, {{$property.HnswParams.Dimensions}});
@@ -93,6 +102,12 @@ static inline OBX_model* create_obx_model() {
93102
{{- end}}
94103
{{range $relation := $entity.Relations -}}
95104
obx_model_relation(model, {{$relation.Id.GetId}}, {{$relation.Id.GetUid}}, {{$relation.Target.Id.GetId}}, {{$relation.Target.Id.GetUid}});
105+
{{- if $relation.ExternalName}}
106+
obx_model_relation_external_name(model, "{{$relation.ExternalName}}");
107+
{{- end}}
108+
{{- if $relation.ExternalType}}
109+
obx_model_relation_external_type(model, {{CoreExternalTypes $relation.ExternalType}});
110+
{{- end}}
96111
{{end -}}
97112
obx_model_entity_last_property_id(model, {{$entity.LastPropertyId.GetId}}, {{$entity.LastPropertyId.GetUid}});
98113
{{end}}

internal/generator/go/ast-reader.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ type uid = uint64
3939
type id = uint32
4040

4141
var supportedEntityAnnotations = map[string]bool{
42-
"name": false, // TODO
43-
"sync": true,
44-
"transient": true,
45-
"uid": true,
42+
"name": false, // TODO
43+
"sync": true,
44+
"transient": true,
45+
"uid": true,
46+
"external-name": true,
4647
}
4748

4849
var supportedPropertyAnnotations = map[string]bool{
@@ -60,6 +61,8 @@ var supportedPropertyAnnotations = map[string]bool{
6061
"type": true,
6162
"uid": true,
6263
"unique": true,
64+
"external-name": true,
65+
"external-type": true,
6366
}
6467

6568
// astReader contains information about the processed set of Entities
@@ -509,6 +512,12 @@ func (field *Field) processType(f field) (fields fieldList, err error) {
509512
relDetails["name"] = &binding.Annotation{Value: field.Name}
510513
relDetails["to"] = property.annotations["link"]
511514
relDetails["uid"] = property.annotations["uid"]
515+
if property.annotations["external-name"] != nil {
516+
relDetails["external-name"] = property.annotations["external-name"]
517+
}
518+
if property.annotations["external-type"] != nil {
519+
relDetails["external-type"] = property.annotations["external-type"]
520+
}
512521
if rel, err := field.Entity.AddRelation(relDetails); err != nil {
513522
return nil, err
514523
} else {
@@ -568,7 +577,6 @@ func (field *Field) fillInfo(f field, typ typeErrorful) {
568577

569578
func (entity *Entity) setAnnotations(comments []*ast.Comment) error {
570579
lines := parseCommentsLines(comments)
571-
572580
var annotations = make(map[string]*binding.Annotation)
573581

574582
for _, tags := range lines {

internal/generator/go/templates/binding.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,33 @@ func ({{$entityNameCamel}}_EntityInfo) AddToModel(model *objectbox.Model) {
118118
{{with $entity.Flags -}}
119119
model.EntityFlags({{.}})
120120
{{end -}}
121+
{{with $entity.ExternalName -}}
122+
model.EntityExternalName("{{.}}")
123+
{{end -}}
121124
{{range $property := $entity.Properties -}}
122125
model.Property("{{$property.Name}}", {{$property.Type}}, {{$property.Id.GetId}}, {{$property.Id.GetUid}})
123126
{{with $property.Flags -}}
124127
model.PropertyFlags({{.}})
125128
{{end -}}
129+
{{with $property.ExternalName -}}
130+
model.PropertyExternalName("{{$property.ExternalName}}")
131+
{{end -}}
132+
{{with $property.ExternalType -}}
133+
model.PropertyExternalType({{$property.ExternalType}})
134+
{{end -}}
126135
{{if $property.RelationTarget}}model.PropertyRelation("{{$property.RelationTarget}}", {{$property.IndexId.GetId}}, {{$property.IndexId.GetUid}})
127136
{{else if $property.IndexId}}model.PropertyIndex({{$property.IndexId.GetId}}, {{$property.IndexId.GetUid}})
128137
{{end -}}
129138
{{end -}}
130139
model.EntityLastPropertyId({{$entity.LastPropertyId.GetId}}, {{$entity.LastPropertyId.GetUid}})
131140
{{range $relation := $entity.Relations -}}
132141
model.Relation({{$relation.Id.GetId}}, {{$relation.Id.GetUid}}, {{$relation.Target.Name}}Binding.Id, {{$relation.Target.Name}}Binding.Uid)
142+
{{with $relation.ExternalName -}}
143+
model.RelationExternalName("{{$relation.ExternalName}}")
144+
{{end -}}
145+
{{with $relation.ExternalType -}}
146+
model.RelationExternalType({{$relation.ExternalType}})
147+
{{end -}}
133148
{{end -}}
134149
}
135150

internal/generator/merge.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func mergeModelEntity(currentEntity *model.Entity, storedEntity *model.Entity, s
8888
storedEntity.Name = currentEntity.Name
8989
storedEntity.Flags = currentEntity.Flags
9090
storedEntity.Comments = currentEntity.Comments
91+
storedEntity.ExternalName = currentEntity.ExternalName
9192

9293
if currentEntity.Meta != nil {
9394
storedEntity.Meta = currentEntity.Meta.Merge(storedEntity)
@@ -275,6 +276,8 @@ func mergeModelProperty(currentProperty *model.Property, storedProperty *model.P
275276
storedProperty.Type = currentProperty.Type
276277
storedProperty.Flags = currentProperty.Flags
277278
storedProperty.HnswParams = currentProperty.HnswParams
279+
storedProperty.ExternalName = currentProperty.ExternalName
280+
storedProperty.ExternalType = currentProperty.ExternalType
278281

279282
return nil
280283
}
@@ -323,6 +326,8 @@ func getModelRelation(currentRelation *model.StandaloneRelation, storedEntity *m
323326

324327
func mergeModelRelation(currentRelation *model.StandaloneRelation, storedRelation *model.StandaloneRelation, storedModel *model.ModelInfo) (err error) {
325328
storedRelation.Name = currentRelation.Name
329+
storedRelation.ExternalName = currentRelation.ExternalName
330+
storedRelation.ExternalType = currentRelation.ExternalType
326331

327332
if currentRelation.Meta != nil {
328333
storedRelation.Meta = currentRelation.Meta.Merge(storedRelation)

0 commit comments

Comments
 (0)