Dapper.plus get tablename and key column name from DapperPlusManager - dapper

I'm using Dapper.Plus with DapperPlusManager to map objects from database.
I map my class like this:
DapperPlusManager.Entity<Order>()
.Key(order => order.OrderID)
.Table("zzz.customers");
I would like to receive the table name and the column name in my dao class. Is it possible?

Disclaimer: I'm the owner of Dapper Plus
That is currently impossible (no easy syntax for it)
I recommend you to create an issue here: https://github.com/zzzprojects/Dapper-Plus/issues and link this Stack Overflow post. We will surely try to find something that will meet your requirement.

Related

Avoiding database queries in Anylogic

I would like to avoid costly repeated data base queries in Anylogic. I have seen the following thread in Stack Overflow What is the fastest way to look up continuous data on Anylogic (Java, SQL) where a simple three step answer is provided but I'm not sure what the second point of the three actually means:
Save all rows as instances of that class at model start-up into a map - you can use Origin/Destination as the key (use Anylogic's Pair object) and the class instance as the value
I have created a class that takes as inputs the information from each column of my database. I would now like to save each row as an instance of that class - is there an easy way to do this? I may be missing something simple as I'm new to Anylogic.
I'm also unsure of how to create a mapping, if anyone could add more detail to point 2 above I'd be very grateful!
this is effectively the best advice, you created the class, which is a great step, but now, one element of that class, will be used as the key... for example the name... for instance if your class has firstName as one variable and lastName as another variable, you will use a string that is the concatenation of firstName and lastName as your key. Of course any key is fine, assuming that it is unique for all your table. Also an integer as an id is ok too.
create a collection of type LinkedHashMap
Create a class (you did that)
Your collection will take as the key a String (first + last name) and as the value of the elment the class...
now, when you read your database you will have something like this:
for(Tuple t : yourQueryResults){
YourClass yc=new YourClass(t.get(db.var1),t.get(db.var2));
String totalName=t.get(db.first_name)+"_"+t.get(db.last_name);
yourCollection.put(totalName,yc);
}
Now every time you want to find someone with the a name, for example "John Doe", instead of making a query, you will do
yourCollection.get("John_Doe").theVarYouWant;
if you use an id instead of the name, you can set an int as the key, and then you will just do yourCollection.get(theId).theVarYouWant

Laravel show records as flat array or single record

I have 2 column in my table setting
with the following values
KEY VALUE
company ABC
phone 14344
address Somerset City
I need to display this like a single record or a flatten
array in the view/blade page
something like
{{$sett->company}}
{{$sett->phone}}
or an array with lookup
{{$myarray('company')}}
{{$myarray('phone')}}
The idea is if I add another settings like contact us email address
for my website I don't want to add another column.
I know this is achievable in controller by creating different variable
and executing different query but I'm kind of looking for some options here.
Thanks for the help really appreciated.
You can use $settings->pluck('value', 'key') to get your result. Read more here: https://laravel.com/docs/5.4/collections#method-pluck

Finding an id from the given table by using selenium web driver

How can I find "id" of above web table, if I only know name of a particular customer. For example from the above table how can I find "CUSTOMER ID" of "THOMAS HANDY".
The code you are looking for looks similar this (Note this is written in Ruby)
if(tab['class'].include?(var))
tab is a selector variable.
var would be what you want it to have.
So something like the following...
#Logic to Loop through each table - Parameterising it as table
if(table.text.include?('Thomas Hardy'))
table['id']
end
#End of Loop Logic
Although as people have said, you're missing lots of info

mybatis- 3.1.1. how to override the resultmap returned from mybatis

we using mybatis 3.1.1.
we found for oracle the result map returned contains column name in Capital letters and in case of mySql the result map returned contains column name in small letters.
My question is : Is there is any way i can to write some sort of interceptor so that i can modify the result returned by result map.
Thanks.
I'm afraid the answer is that MyBatis doesn't provide any direct way to control the case of the keys in a result map. I asked this question recently on the MyBatis Google Group: https://groups.google.com/forum/?fromgroups#!topic/mybatis-user/tETs_JiugNE
The outcome is dependent on the behavior of the JBDC driver.
It also turns out that doing column aliasing as suggested by #jddsantaella doesn't work in all cases. I've tested MyBatis-3.1.1 with three databases in the past: MySQL, PostgreSQL and H2 and got different answers. With MySQL, the case of the column alias does dictate the case of the key in the hashmap. But with PostgreSQL it is always lowercase and with H2, it is always uppercase. I didn't test whether column aliases will work with Oracle, but by default it appears to return capital letters.
I see two options:
Option 1: Create some helper method that your code will always use to pull the data out of the returned map. For example:
private Object getFromMap(Map<String, Object> map, String key) {
if (map.containsKey(key.toLowerCase())) {
return map.get(key.toLowerCase());
} else {
return map.get(key.toUpperCase());
}
}
Option 2: Write a LowerCaseMap class that extends from java.util.AbstractMap or java.util.HashMap and wrappers all calls to put, putAll and/or get to always be lower case. Then specify that MyBatis should use your specific LowerCaseMap rather than a standard HashMap, when populating the data from the query.
If you like this idea and want help on how to tell MyBatis how to use a different concrete collection class, see my answer to this StackOverflow question: https://stackoverflow.com/a/11596014/871012
What if you modify the query so you get the exactly column name you need? For example:
select my_column as MY_COLUMN from ...
The idea of a LowerCaseMap as the ResultType is sound, but you can probably avoid writing your own. In my case I'm using org.apache.commons.collections4.map.CaseInsensitiveMap:
<select id="getTableValues"
resultType="org.apache.commons.collections.map.CaseInsensitiveMap">
SELECT *
FROM my_table
WHERE seq_val=#{seq_val}
</select>

Naming of boolean column in database table [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 months ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I have 'Service' table and the following column description as below
Is User Verification Required for service ?
Is User's Email Activation Required for the service ?
Is User's Mobile Activation required for the service ?
I Hesitate in naming these columns as below
IsVerificationRequired
IsEmailActivationRequired
IsMobileActivationRequired
or
RequireVerification
RequireEmailActivation
RequireMobileActivation
I can't determined which way is the best .So, Is one of the above suggested name is the best or is there other better ones ?
I would (and do) use "IsVerificationRequired"
I try to add some meaning to my column names so it's obvious (ValueDate, InsertedDateTime, IsActive, HazCheezBurger, ProductName etc). "Isxxxx" implies yes/no for example without thinking and you only have 2 states unlike "ProductName".
Run with the Is variants, or at the very least swap the Require to Requires. Booleans should be phrased as questions. Is, Can, Has, Should, they're all good prefixes for Boolean functions/columns. See 1370840 for more arguments on this
I would choose VerificationRequired, EmailActivationRequired etc.
Database is the snapshot of the state, so the above said column names goes better over the ones you have mentioned in my opinion.
I would go for the one that fits more the syntax you are using in your current project. Either one is fine since they describe what the variable contains, the only thing you need to worry about is that you keep the same naming standard for all your project. If you haven't decide any naming standard for your project yet, the first one would be better since it is what is closer of the Java Bean naming standard which is something that a lot of developer are used to.
Neither. Name the column such that it makes sense if "is" were to be prepended, but don't prepend it:
VerificationRequired
EmailActivationRequired
MobileActivationRequired
The datatype being boolean implies the "is" - you don't need to load it into the variable/field name. Just as you shouldn't name timestamp columns with "timestamp", eg define the column as expiry timestamp not expiry_timestamp timestamp.
Adding is to the name is a form of Hungarian notation, which has long been accepted as an anti-pattern.
In java, the convention is to name of the accessor method of a field (especially on a DTO) as isX rather than the usual getX because it reads more naturally, eg:
public boolean isVerificationRequired { return verificationRequired; }`
reads more naturally than:
public boolean getVerificationRequired { return verificationRequired; }`
Or name the accessor hasX if it reads more naturally.
Whether you name the accessor isX or hasX, a boolean field (in your case a database column) should not have is or has in its name.

Resources