I have an implementation of CustomChange that I need access to the file name of the changeSet in which it is defined.
Any ideas? The CustomChangeWrapper has a reference to the ChangeSet that does have the value I need (changeSet.filePath) but is not passed as part of the CustomChange interface.
Looking at the source, I would try using the public SortedSet<String> getParams() and/or the public String getParamValue(String key) methods that are defined in CustomChangeWrapper
Related
I have a #PlanningSolution class, that has one field with a custom List implementation as type.
When solving I run into the following issue (as described in the optaplanner documentation):
java.lang.IllegalStateException: The cloneCollectionClass (class java.util.ArrayList) created for originalCollectionClass (class Solution$1) is not assignable to the field's type (class CustomListImpl).
Maybe consider replacing the default SolutionCloner.
As this field has no impact on planning, can I prevent FieldAccessingSolutionCloner from trying to clone that particular field e.g. by adding some annotation? I dont want to provide a complete custom SolutionCloner.
When inspecting the sources of FieldAccessingSolutionCloner I found out that I only needed to override the method retrieveCachedFields(...) or constructCloneCollection(...) so I tried to extend FieldAccessingSolutionCloner but then I need a public no-args-constructor. There I dont know how to initialise the field solutionDescriptor in the no-args-constructor to use my ExtendedFieldAccessingSolutionCloner as solution cloner.
If the generic solution cloner decided to clone that List, there is probably a good reason for it do so: one of the the elements in that list probably has a reference to a planning entity or the planning solution - and therefore the entire list needs to be planning cloned.
If that's not the case, this is a bug in OptaPlanner. Please provide the classes source code of the class with that field and the CustomListImpl class too, so we can reproduce and fix it.
To supply a custom SolutionCloner, follow the docs which will show something like this (but this is a simple case without chained variables, so it's easy to get right, but solution cloning is notoriously difficult!).
#PlanningSolution(solutionCloner = VaccinationSolutionCloner.class)
public class VaccinationSolution {...}
public class VaccinationSolutionCloner implements SolutionCloner<VaccinationSolution> {
#Override
public VaccinationSolution cloneSolution(VaccinationSolution solution) {
List<PersonAssignment> personAssignmentList = solution.getPersonAssignmentList();
List<PersonAssignment> clonedPersonAssignmentList = new ArrayList<>(personAssignmentList.size());
for (PersonAssignment personAssignment : personAssignmentList) {
PersonAssignment clonedPersonAssignment = new PersonAssignment(personAssignment);
clonedPersonAssignmentList.add(clonedPersonAssignment);
}
return new VaccinationSolution(solution.getVaccineTypeList(), solution.getVaccinationCenterList(), solution.getAppointmentList(),
solution.getVaccinationSlotList(), clonedPersonAssignmentList, solution.getScore());
}
}
I want to use a class generated with TypeSpec.classBuilder as a property in another class that I am generating. But for this I need to get a TypeName and I cannot find a way to access it. Only from the superclass. Anyone knows a way to do this?
You should be perfectly fine with using ClassName there.
And the easiest way of obtaining the ClassName is to pass the package and the name of the generated type:
ClassName("your.package.here", "NameOfType")
You can see here how I'm specifying a receiver of an extension function ("similar" use-case):
I just setup a new EF6 project. In my database I have 2 tables:
- languages
- langugesDescriptions
(with relation)
the context lazyLoadingEnabled is set to false.
(both on edmx as in code)
When getting data from languages:
return context.languages
gives me on FIRST RUN, correct ouput, all language records.
But, when running context.languageDescriptions, and then again context.languages, in the output are also descriptions included.
any ideas? caching ?
Language class is auto generated: (under the .tt file)
Partial Public Class Language
Public Property Lang_ID As Integer
Public Property Lang_Name As String
Public Property Lang_Code As String
Public Overridable Property LanguageDescription As ICollection(Of LanguageDescription) = New HashSet(Of LanguageDescription)
End Class
Internally, Entity Framework leverages the Identity Map pattern which
Ensures that each object gets loaded only once by keeping every loaded
object in a map. Looks up objects using the map when referring to
them.
When you're getting Languages from the context, then LangaugesDescriptions, EF knows that LanguageDescriptions is a Navigation-Property of Language so even if your Lazy-Loading is turned off, each loaded Langauge will contain its associated LanguageDescriptions because it's already loaded.
However, some will argue that LanguageDescriptions is actually a Value-Object and should not be exposed directly on your context, it should only be accessible as part of its (root entity) Language.
Update (as per your comment):
If you want to explicitly disable auto-filling of the LanguageDescription property, you can try to clear the local cache using:
context.LanguageDescription.Local.Clear()
You can also get the list of LanguageDescription using the AsNoTracking() method to prevent the entities from tracking each other:
context.LanguageDescription.AsNoTracking();
Or project the existing Language collection into a new collection that doesn't fill the LanguageDescription property:
From Lang In context.Languages
Select New Language With {
.Lang_ID = Lang.Lang_ID,
.Lang_Name = Lang.Lang_Name,
.Lang_Code = Lang.Lang_Code,
}
In the auto-generated resource designer file, there are properties for each resource. The property calls "GetString" which returns the string value. I would like to override this getstring function so I can do logic to see if I need to retrieve this value or a different value. I can't figure out how to do this because the designer file is auto-generated.
Public ReadOnly Property General() As String
Get
Return ResourceManager.GetString("General", resourceCulture)
End Get
End Property
For example, in my version of the GetString function, I would check the key passed in ("General") and see if there is a custom value for this key in a database. If the custom value exists, I would use that value. If the custom value does not exist, I would call the base GetString function to get the Resource value. I'd like to use the built in Resource class for this because then in my code I can just use "#Resources.General" and take advantage of the auto-complete functionality that already exists.
Refer to ASP.NET Resourcemanager to read local .resx. It's in C# but you can just convert it over. It isn't 100% of what you are looking for but shows a way of overriding in which you may be able to adjust to work with your needs.
I am using Linq to Sql that generated a data contract for a table. I have a date field in that table which is a non-nullable field. I need to override the auto generated property of the date field to return a specific value, something like
Get
if_dt<>date.minvalue
return _dt
else
return string.empty
End Get
Is it possible to override an autogenerated property in the designer.vb file using a partial class? I dont want to create a new property as it is currently being accessed in n number of places and I dont want to change it in every place.
No, you'll need to modify the .designer file or inherit from it and change the behavior of that property (but I guess the auto-generated property won't be virtual so you'll need to edit it anyway)