×

Notice

The forum is in read only mode.
×
Getting new Releases

To get notified on new releases you may follow us on twitter @expandframework or subscribe in our main RSS feed.

Topic-icon WorldCreator -> indexes, relationships

  • Marek
  • Marek's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
More
2 years 3 months ago #10548 by Marek
Hello,
All custom fields created by WC are properly added to TypesInfo and appropriate columns is created as well.
But there is one problem: if we want to create reference field, then indexes and relationships arent created.

I found that this code is createing columns:

private static void ApplicationOnObjectSpaceCreated(object sender, ObjectSpaceCreatedEventArgs e){
var application = ((XafApplication) sender);
application.ObjectSpaceCreated-=ApplicationOnObjectSpaceCreated;
var memberInfoGroups = _members.Where(info => info.IsPersistent).GroupBy(info => info.MemberType);
foreach (var memberInfoGroup in memberInfoGroups){
using (var objectSpace = application.CreateObjectSpace(memberInfoGroup.Key)){
foreach (var info in memberInfoGroup){
objectSpace.CreateColumn(info);
}
}
}
}



So, objectSpace.CreateColumn(info) is creating just columns. If I want to update fields properly, I need to call ObjectSpaceProvider.UpdateSchema() method.
Maybe good solution is to hold some flag in db and setting it to true if we want to update db (after create custom field), and on application starting just checking this flag, and if needed updadint schema, and then setting this flag to false.
More
2 years 3 months ago #10550 by Tolis
Replied by Tolis on topic WorldCreator -> indexes, relationships
thnks for the suggestion I will review it and update you. on a quick view I am not sure about the flag need since the CreateColumn handles exceptions and is only called once. So I think we can live by always try to create the index without checking if exists (must be done agnostic for at least the major db engines)



p.s. if you want to purse that case your self let me know so we do not duplicate the efforts

To get notified on new releases follow us on twitter @expandframework or subscribe RSS feed. I am also available @tolisss . Also see How to debug eXpand
  • Marek
  • Marek's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
More
2 years 2 months ago #10566 by Marek
Replied by Marek on topic WorldCreator -> indexes, relationships
Yes, CreateColumn is called only once, but on every application runs. It need to be called once too, but just after first application run, after makes some modifications in WC. We can try to create index, but in future maybe we need do something more and this code will have to be changed again. I think , the most clear solution is to call UpdateSchema methond, which will handle all ways and will be simple.

My solution:
1. Create UpdateSchemaOnChangedAttribute, which can be applied to any class (include WC classes)
2. Create manager class:

public class UpdateSchemaOnChangedManager
{
private static UpdateSchemaOnChangedManager _instance;
private XafApplication Application;

public static UpdateSchemaOnChangedManager Instance
{
get
{
if (_instance == null)
_instance = new UpdateSchemaOnChangedManager();
return _instance;
}
}

public void Register(XafApplication Application)
{
this.Application = Application;
Application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
Application.LoggedOn += Application_LoggedOn;
}

private void Application_LoggedOn(object sender, LogonEventArgs e)
{
if (NeedUpdateSchema())
{
Application.ObjectSpaceProvider.UpdateSchema();
ChangeDbNeedUpdateSchema(false);
}
}

private void Application_ObjectSpaceCreated(object sender, ObjectSpaceCreatedEventArgs e)
{
if (!(e.ObjectSpace is INestedObjectSpace))
e.ObjectSpace.ObjectSaved += ObjectSpace_ObjectSaved;
}

private void ObjectSpace_ObjectSaved(object sender, ObjectManipulatingEventArgs e)
{
var typeInfo = XafTypesInfo.CastTypeToTypeInfo(e.Object.GetType());
var updateSchemaAttribute = typeInfo.FindAttribute<Attributes.UpdateSchemaOnChangedAttribute>();
if (updateSchemaAttribute != null)
ChangeDbNeedUpdateSchema(true);
}
public void ChangeDbNeedUpdateSchema(bool value)
{
var ObjectSpace = Application.CreateObjectSpace(typeof(GlobalSettings));
var settings = GlobalSettings.GetInstance<GlobalSettings>(ObjectSpace);
settings.UpdateSchema= value;
ObjectSpace.CommitChanges();
}
public bool NeedUpdateSchema()
{
var session = new DevExpress.Xpo.Session(BMSession.DefaultDataLayer);
return Database.ConvertFromDBValue<bool>(session.ExecuteScalar(string.Format("select top 1 {0} from {1}", nameof(GlobalSettings.UpdateSchema),
XafTypesInfo.CastTypeToTypeInfo(typeof(GlobalSettings)).GetTableName())));
}
}

3. Register class logic:

public override void Setup(ApplicationModulesManager moduleManager)
{
base.Setup(moduleManager);
Utils.UpdateSchemaOnChangedManager.Instance.Register(Application);
}


I m using this soultion with WC classes and my own classes. After modify any classes decorated with UpdateSchemaOnChangedAttribute, then schema is updating just on first application run.

What do you think about this?
More
2 years 2 months ago #10567 by Tolis
Replied by Tolis on topic WorldCreator -> indexes, relationships
the reason behind the direct column creations was that for Oracle the updateschema is awfully slow, your suggestioin is to call over a flag and is interesting (wondering if the direct column calls can be replaced everywhere).

> m using this soultion with WC classes and my own classes. After modify any classes decorated with UpdateSchemaOnChangedAttribute, then schema is updating just on first application run.

can you example over the "my own classe" case?

To get notified on new releases follow us on twitter @expandframework or subscribe RSS feed. I am also available @tolisss . Also see How to debug eXpand
  • Marek
  • Marek's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
More
2 years 2 months ago #10569 by Marek
Replied by Marek on topic WorldCreator -> indexes, relationships

Tolis wrote: the reason behind the direct column creations was that for Oracle the updateschema is awfully slow, your suggestioin is to call over a flag and is interesting (wondering if the direct column calls can be replaced everywhere).

In this solution schema is updating just one time, so there will be no problem with time. And all connection types supported by DevExpress will work with UpdateSchema method, so I think direct column calls can be replaced everywhere.

Tolis wrote: > m using this soultion with WC classes and my own classes. After modify any classes decorated with UpdateSchemaOnChangedAttribute, then schema is updating just on first application run.

can you example over the "my own classe" case?

Yes. I have own module that extends WC features,eg. own dictionary field, custom sql field (receiving data via sql query), etc.) So I have decorated WC classes(using reflection), and my own classes with UpdateSchemaOnChangedAttribute, because I need to update db schema after any of this objects will changed. So this is simple and flexible solution.
More
2 years 2 weeks ago #10734 by Tolis
Replied by Tolis on topic WorldCreator -> indexes, relationships
i checked this case and I see the the CreateColumn method was called only in the case of existent members creation. I have removed this called because it was needed and my reference members are created fine by XAF and its call to the UpdateSchema. I also see the indexes in my db are created fine.

The call has been commented out in 16.2.2.1
github.com/expand/eXpand/blob/fcec13c9de...Creator.cs#L116-L127

So bottom line I could not find how the index are not created and IMHO your suggestion is not needed as WC uses XAF for updates. If you still face issues please post more details and repro instructions

To get notified on new releases follow us on twitter @expandframework or subscribe RSS feed. I am also available @tolisss . Also see How to debug eXpand
Moderators: expand
Time to create page: 0.209 seconds