SqlKata - Is there any way to tell the SqlKata compiler to NOT wrap Identifiers when building the query string? - sqlkata

Is there any way to tell the SqlKata compiler to NOT wrap Identifiers when building the query string? (Double quotes for PostgreSql and Square brackets for SqlServer)
For example, when building a query against a PostgreSql database I would like the compiler to create: SELECT CDR.InstanceID FROM CallDetails as CDR
instead of:
SELECT "CDR"."InstanceID" FROM "CallDetails as "CDR"

You can extend the desired compiler and change the default OpeningIdentifier and ClosingIdentifier.
public class MyCompiler: PostgresCompiler
{
protected override string OpeningIdentifier { get; set; } = "";
protected override string ClosingIdentifier { get; set; } = "";
}
and use it instead

Related

Salesforce Apex/JSON serialization with change on variable name

In Salesforce/Apex how can i serialize an Apex Class to Json/String with a change of variable names mapping ? like in java we can use #SerializedName annotation.
So far, Apex does not support annotation for serialization. The supported annotations are
here
But, in this type of scenario, I always follows
public class TestClass
{
public string oldA { get; set; }
public string oldB { get; set; }
public string oldC { get; set; }
}
String jsonStr = JSON.serialize(objectTestClass);
jsonStr = jsonStr.replaceAll('"oldA":','"newA":');
You can use JSONGenerator to create the output yourself
There's no out of the box way for remapping variables via an annotation or a similar facility. To remap a variable you'd have to roll your own parser via JSONParser or use untyped deserialization and encapsulate it into your own Apex class.

How to create MatchQueryDescriptor using field name as a string?

After upgrading Nest from 5.4 to 6.2 I could not find the right syntax to create MatchPhraseQueryDescriptor using known field name as a string. It appears that .Field() method no longer takes a string but takes an object path instead.
What is the easiest way to re-write following Nest 5.4 snippet for Nest 6.2 ?
var matchPhrase = new MatchPhraseQueryDescriptor<MyType>()
.Field("MyField")
.Query("MyQuery");
?
MatchPhraseQueryDescriptor<T> accepts Field or Expression<Func<T, object>> as parameters to .Field(...), which it inherits from FieldNameQueryDescriptorBase:
public abstract class FieldNameQueryDescriptorBase<TDescriptor, TInterface, T>
: QueryDescriptorBase<TDescriptor, TInterface>, IFieldNameQuery
where TDescriptor : FieldNameQueryDescriptorBase<TDescriptor, TInterface, T>, TInterface
where TInterface : class, IFieldNameQuery
where T : class
{
Field IFieldNameQuery.Field { get; set; }
bool IQuery.IsVerbatim { get; set; }
bool IQuery.IsStrict { get; set; }
public TDescriptor Field(Field field) => Assign(a => a.Field = field);
public TDescriptor Field(Expression<Func<T, object>> objectPath) =>
Assign(a => a.Field = objectPath);
}
There is an implicit operator that converts from string to Field.

How to provide hints to IntelliJ to exclude properties when using generate

With IntelliJ 2016.2 is there a way to mark a property/method that should not be included when generation of code is done?
For example this class
public class Person {
private String firstName;
private String lastName;
public void setFirstName(String firstName){ ... }
public String getFirstName() { ... };
public void setLastName(String firstName){ ... }
public String getLastName() { ... };
public String getFullName() { // returns first + last };
}
I would like to mark getFullName so it is not used when generating things like equals or toString since it is merely a connivence function.
This isn't a full answer, but when you generate equals/hashcode, the first screen has an option to select a template. Choose "..." and you can create your own new template for creating equals and hashcode. You might therefore be able to code something, eg reading an annotation on a field, that would allow you to exclude it from the generation.
These look suspiciously like Velocity macros to me but my understanding of them isn't good enough to take the solution any further.

Mapping multi-value field to IList<> with FluentHibernate

I have following problem:
We have multi-value fields in DB like ProductLineIdList which stores every allowed productLines separated by comma (for example "2,13,27,33"). I would like to map this field to IList (list with 4 entities). Is it possible to do that? Thx
How about saving the productLines as a string, and then use a non mapped property to return the list of product lines? I suspect you'd have a hard time pulling that off with pure NHibernate.
public class Product
{
// protected so we can't see this
protected virtual string productLines { get; set; }
// instruct NHibernate to ignore this property!
public IList<string> ProductLines
{
get
{
if (!string.IsNullOrEmpty(productLines))
{
return productLines.Split(',').ToList();
}
else
{
return new List<string>();
}
}
}
}

HQL to CriteriaQuery conversion

Class is defined as this:
class User {
public int ID { get; set; }
public string OpenID { get; set; }
public IList<Tag> Tags { get; set; }
}
OpenID is set as natural-id, so that the second level cache recognizes this.
I have this HQL query which returns a list of user tags.
db.CreateQuery("select Tags from User where OpenID = :openId")
.SetString("openId", openId)
.List<Tag>();
As far as I know HQL does not have a syntax to identify OpenID as natural-id, but CriteriaQuery has that (Restrictions.NaturalId()...)
So I need to convert this query to CriteriaQuery.
Something in this direction:
db.CreateCriteria<User>()
.Add(Restrictions.NaturalId().Set("OpenID", openId))
//I need to tell criteria query that I want to return Tags property here - I don't know how to do that
.List<Tag>();
db.CreateCriteria<User>()
.SetProjection(Projections.Property("Tags"));
.Add(Restrictions.Eq("OpenID", openId));
.List<Tag>();
Not sure about this NaturalId, never used it, I probably would just add a normal restriction.