Skip to content

Commit

Permalink
add support for virtual fields #46
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Mar 6, 2024
1 parent af7d76c commit 8f32956
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.fugerit.java.core.cfg.ConfigException;
import org.fugerit.java.core.cfg.xml.CustomListCatalogConfig;
import org.fugerit.java.core.cfg.xml.ListMapCatalogConfig;
import org.fugerit.java.core.cfg.xml.XmlBeanHelper;
import org.fugerit.java.core.io.helper.CustomPrintWriter;
import org.fugerit.java.core.io.helper.StreamHelper;
Expand Down Expand Up @@ -130,7 +131,11 @@ public static DaogenCatalogConfig loadConfig( InputStream input, Class<?> c, Pro
}
return config;
}


private void finishingTouch() {
this.getIdSet().forEach( entityId -> this.getListMap( entityId ).finishingTouch() );
}

@Override
public void configure(Element tag) throws ConfigException {
super.configure(tag);
Expand All @@ -148,6 +153,8 @@ public void configure(Element tag) throws ConfigException {
throw new ConfigException( e );
}
}
// finishing touch
this.finishingTouch();
}

private Properties classConfig;
Expand Down Expand Up @@ -192,5 +199,5 @@ public String getLineSeparator() {
public void setLineSeparator(String lineSeparator) {
this.lineSeparator = lineSeparator;
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.fugerit.java.daogen.base.config;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.fugerit.java.core.cfg.xml.IdConfigType;
import org.fugerit.java.core.javagen.GeneratorNameHelper;
import org.fugerit.java.core.lang.helpers.BooleanUtils;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.core.util.collection.ListMapStringKey;

Expand Down Expand Up @@ -50,6 +52,7 @@ public boolean equals(Object o) {

public DaogenCatalogEntity() {
this.relations = new ListMapStringKey<>();
this.allFields = new ListMapStringKey<>();
}

private ListMapStringKey<DaogenCatalogRelation> relations;
Expand Down Expand Up @@ -207,5 +210,26 @@ public String describe() {
public boolean containsDefaultId() {
return this.get( DEFAULT_ID_FIELD.toLowerCase() ) != null || this.get( DEFAULT_ID_FIELD.toUpperCase() ) != null;
}


private ListMapStringKey<DaogenCatalogField> allFields;

public ListMapStringKey<DaogenCatalogField> getAllFields() {
return allFields;
}

public void setAllFields(ListMapStringKey<DaogenCatalogField> allFields) {
this.allFields = allFields;
}

protected void finishingTouch() {
this.allFields.clear();
this.allFields.addAll( this );
Iterator<DaogenCatalogField> it = this.iterator();
while ( it.hasNext() ) {
if (BooleanUtils.isTrue( it.next().getVirtual() )) {
it.remove();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class DaogenCatalogField extends BasicIdConfigType {
public static final String ATT_COMMENTS = "comments";
public static final String ATT_UDT = "udt";
public static final String ATT_STRUCT_TYPE = "structType";

public static final String ATT_VIRTUAL = "virtual";

/**
*
Expand All @@ -44,6 +46,8 @@ public class DaogenCatalogField extends BasicIdConfigType {

private String structType;

private String virtual;

public boolean isUserType() {
return BooleanUtils.isTrue( this.getUdt() );
}
Expand Down Expand Up @@ -127,7 +131,15 @@ public String getStructType() {
public void setStructType(String structType) {
this.structType = structType;
}


public String getVirtual() {
return virtual;
}

public void setVirtual(String virtual) {
this.virtual = virtual;
}

public String describe() {
List<String> list = new ArrayList<>();
list.add( StringUtils.concat( ":" , ATT_SQL_TYPE, this.getSqlType() ) );
Expand All @@ -138,6 +150,7 @@ public String describe() {
list.add( StringUtils.concat( ":" , ATT_COMMENTS, this.getComments() ) );
list.add( StringUtils.concat( ":" , ATT_UDT, this.getUdt() ) );
list.add( StringUtils.concat( ":" , ATT_STRUCT_TYPE, this.getStructType() ) );
list.add( StringUtils.concat( ":" , ATT_VIRTUAL, this.getVirtual() ) );
return StringUtils.concat( ",", list );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void handleEntity(DaogenCatalogEntity entity, List<Entry> reflectConfig
// init methods
methods.add( new EntryMethod( "<init>" ) );
// main properties getter
methods.addAll( entity.stream().map( field -> {
methods.addAll( entity.getAllFields().stream().map( field -> {
EntryMethod m = new EntryMethod();
m.setName( "get"+GeneratorNameHelper.toClassName( field.getId() ) );
return m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void generateDaogenBody() throws IOException {
this.getWriter().println( TAB+"/*" );
this.getWriter().println( TAB+" * fields generated for entity attributes " );
this.getWriter().println( TAB+" */" );
for ( DaogenCatalogField field : this.getCurrentEntity() ) {
for ( DaogenCatalogField field : this.getCurrentEntity().getAllFields() ) {
// property
String javaProperty = GeneratorNameHelper.toPropertyName( field.getId() );
String javaSuffix = GeneratorNameHelper.toClassName( field.getId() );
Expand Down Expand Up @@ -107,7 +107,7 @@ public void generateDaogenBody() throws IOException {
this.getWriter().println( TAB_2+"StringBuilder buffer = new StringBuilder();" );
this.getWriter().println( TAB_2+"buffer.append( this.getClass().getSimpleName() );" );
boolean firstColumn = true;
for ( DaogenCatalogField field : this.getCurrentEntity() ) {
for ( DaogenCatalogField field : this.getCurrentEntity().getAllFields() ) {
String javaProperty = GeneratorNameHelper.toPropertyName( field.getId() );
String javaSuffix = GeneratorNameHelper.toClassName( field.getId() );
if ( firstColumn ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void generateDaogenBody() throws IOException {
if ( !relationLast ) {
this.generateRelations();
}
for ( DaogenCatalogField field : this.getCurrentEntity() ) {
for ( DaogenCatalogField field : this.getCurrentEntity().getAllFields() ) {
String propertyName = GeneratorNameHelper.toPropertyName( field.getId() );
String className = GeneratorNameHelper.toClassName( field.getId() );
String type = this.getDaogenConfig().getTypeMapper().mapForModel( field );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void generateDaogenBody() throws IOException {
this.getWriter().println( TAB+"/*" );
this.getWriter().println( TAB+" * fields generated for entity attributes " );
this.getWriter().println( TAB+" */" );
for ( DaogenCatalogField field : this.getCurrentEntity() ) {
for ( DaogenCatalogField field : this.getCurrentEntity().getAllFields() ) {
// property
String javaSuffix = GeneratorNameHelper.toClassName( field.getId() );
String realJavaType = this.getDaogenConfig().getTypeMapper().mapForModel( field );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @project : fj-daogen
* @creation : 2020-11-12
* @version : 1.0.0-rc.6 (2024-03-01)
* @version : 1.0.0-rc.7 (2024-03-06)
*
* XSD for fugerit daogen configuration
*/
Expand Down Expand Up @@ -515,6 +515,11 @@ The entry point for daogen-config documentation is : https://marsdocs.fugerit.or
<xsd:documentation>(e.g. 'java.lang.Long')</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute type="xsd:string" name="virtual" use="optional" default="false">
<xsd:annotation>
<xsd:documentation>Virtual ('true') field will be included in model, but not in persistente (i.e. CRUD) operations.</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>

</xsd:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<field comments="" id="DATE_UPDATE" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
<field comments="1 active, 0 not active" id="STATE" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
<field comments="1 active, 0 not active" id="STATE_TEST" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
<field virtual="true" comments="1 active, 0 not active" id="STATE_VIRTUAL" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
</entity>
<entity catalog="PUBLIC" comments="Contains addresses data" foreignKeys="PUBLIC.FUGERIT.USER" id="PUBLIC.FUGERIT.ADDRESS" name="ADDRESS" primaryKey="ID" schema="FUGERIT">
<field comments="Address system id" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT"/>
Expand Down
11 changes: 11 additions & 0 deletions src/docs/config/daogen-config-xsd-ref.html
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,17 @@ <h1 style="font-weight: bold;">Reference daogen-config.xsd documentation for Ma
<td id="cell_8_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >string</span>
</td>
</tr>
<tr>
<td id="cell_9_0" style="width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >virtual</span>
</td>
<td id="cell_9_1" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >Virtual ('true') field will be included in model, but not in persistente (i.e. CRUD) operations.</span>
</td>
<td id="cell_9_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >string</span>
</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 8f32956

Please sign in to comment.