Skip to content

Commit

Permalink
domain generate index
Browse files Browse the repository at this point in the history
  • Loading branch information
llsand committed Apr 21, 2023
1 parent 6daa4e6 commit 54e14d6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.EcoreUtil2;

import de.opitzconsulting.orcasDsl.Column;
import de.opitzconsulting.orcasDsl.*;
import de.opitzconsulting.orcasDsl.ColumnDomain;
import de.opitzconsulting.orcasDsl.ColumnRef;
import de.opitzconsulting.orcasDsl.Constraint;
Expand All @@ -18,7 +18,7 @@
import de.opitzconsulting.orcasDsl.Sequence;
import de.opitzconsulting.orcasDsl.Table;
import de.opitzconsulting.orcasDsl.UniqueKey;
import de.opitzconsulting.orcasDsl.impl.ColumnRefImpl;
import de.opitzconsulting.orcasDsl.impl.*;
import de.opitzconsulting.orcasDsl.impl.ConstraintImpl;
import de.opitzconsulting.orcasDsl.impl.ForeignKeyImpl;
import de.opitzconsulting.orcasDsl.impl.PrimaryKeyImpl;
Expand Down Expand Up @@ -137,14 +137,36 @@ private void handleTable( Table pTable, Model pModel )

if( lColumnDomain.getGenerateUk() != null )
{
UniqueKey lUniqueKey = new UniqueKeyImpl();
String lName = DomainExtensionHelper.getGeneratedNameColumn(lColumnDomain.getGenerateUk().getConstraintNameRules(), lColumn.getName(), pTable.getName(), pTable.getAlias());

UniqueKey lUniqueKey = (UniqueKey) pTable.getInd_uks().stream().filter(it -> lName.equals(it.getConsName())).findFirst().orElse(null);

if (lUniqueKey == null) {
lUniqueKey = new UniqueKeyImpl();
lUniqueKey.setConsName(lName);
pTable.getInd_uks().add(lUniqueKey);
}

ColumnRef lColumnRef = new ColumnRefImpl();
lUniqueKey.getUk_columns().add( lColumnRef );
lColumnRef.setColumn_name( lColumn.getName() );
lUniqueKey.setConsName( DomainExtensionHelper.getGeneratedNameColumn( lColumnDomain.getGenerateUk().getConstraintNameRules(), lColumn.getName(), pTable.getName(), pTable.getAlias() ) );
lUniqueKey.getUk_columns().add(lColumnRef);
lColumnRef.setColumn_name(lColumn.getName());
}

pTable.getInd_uks().add( lUniqueKey );
if( lColumnDomain.getGenerateIndex() != null )
{
String lName = DomainExtensionHelper.getGeneratedNameColumn(lColumnDomain.getGenerateIndex().getIndexNameRules(), lColumn.getName(), pTable.getName(), pTable.getAlias());

Index lIndex = (Index) pTable.getInd_uks().stream().filter(it -> lName.equals(it.getConsName())).findFirst().orElse(null);

if (lIndex == null) {
lIndex = new IndexImpl();
lIndex.setConsName(lName);
pTable.getInd_uks().add(lIndex);
}

ColumnRef lColumnRef = new ColumnRefImpl();
lIndex.getIndex_columns().add(lColumnRef);
lColumnRef.setColumn_name(lColumn.getName());
}

if( lColumnDomain.getGenerateCc() != null )
Expand Down
14 changes: 14 additions & 0 deletions orcas_domain_extension_java/extensions/DomainSyntaxExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ public void run()
lRuleNormal.getRule_entries().add( createConstantRuleEntry( ")" ) );
}

{
RuleNormal lRuleNormal = createRuleNormal( "GenerateIndex" );
lRuleNormal.getRule_entries().add( createConstantRuleEntry( "generate-index" ) );
lRuleNormal.getRule_entries().add( createConstantRuleEntry( "(" ) );
lRuleNormal.getRule_entries().add( createConstantRuleEntry( "index-name" ) );
lRuleNormal.getRule_entries().add( createConstantRuleEntry( "(" ) );
lRuleNormal.getRule_entries().add( createMarkerRuleEntry( "(" ) );
lRuleNormal.getRule_entries().add( createMultiValueRuleEntry( "indexNameRules", "GenNameRule" ) );
lRuleNormal.getRule_entries().add( createMarkerRuleEntry( ")*" ) );
lRuleNormal.getRule_entries().add( createConstantRuleEntry( ")" ) );
lRuleNormal.getRule_entries().add( createConstantRuleEntry( ")" ) );
}

{
RuleNormal lRuleNormal = createRuleNormal( "GenerateCc" );
lRuleNormal.getRule_entries().add( createConstantRuleEntry( "generate-check-constraint" ) );
Expand Down Expand Up @@ -243,6 +256,7 @@ public void run()
addField( lRuleNormal, new NewFieldDataIdentifierWithoutKeyword( "name", true ) );
addField( lRuleNormal, new NewFieldDataTypeWithoutKeyword( "generatePk", "GeneratePk", false ) );
addField( lRuleNormal, new NewFieldDataTypeWithoutKeyword( "generateUk", "GenerateUk", false ) );
addField( lRuleNormal, new NewFieldDataTypeWithoutKeyword( "generateIndex", "GenerateIndex", false ) );
addField( lRuleNormal, new NewFieldDataTypeWithoutKeyword( "generateCc", "GenerateCc", false ) );
addField( lRuleNormal, new NewFieldDataTypeWithoutKeyword( "generateFk", "GenerateFk", false ) );
lRuleNormal.getRule_entries().add( createConstantRuleEntry( "(" ) );
Expand Down

0 comments on commit 54e14d6

Please sign in to comment.