Cannot map the timestamp type --mybatis generator - generator

When I use the mybatis generator,I get a trouble:
in the database ,I have two columns which their type is timestamp(mysql) like the following.
enter image description here
but at the end it generate a date type for me in the source code.how can I map them to a timestamp type?
the xml config:
`<table schema="system-account" tableName="person" domainObjectName="Person"
mapperName="PersonDao">
<generatedKey column="person_id" sqlStatement="JDBC"/>
<columnOverride column ="name" javaType="java.lang.String"/>
<columnOverride column ="create_time" javaType="java.sql.Timestamp"/>
<columnOverride column ="used" javaType="java.lang.Boolean"/>
<columnOverride column ="update_time" javaType="java.sql.Timestamp"/>
</table>`
the source code:
public class Person {
/**
* This field was generated by MyBatis Generator. This field corresponds to
the database column person.person_id
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
private Long personId;
/**
* This field was generated by MyBatis Generator. This field corresponds to
the database column person.name
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
private String name;
/**
* This field was generated by MyBatis Generator. This field corresponds to
the database column person.createtime
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
private Date createtime;
/**
* This field was generated by MyBatis Generator. This field corresponds to
the database column person.used
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
private Boolean used;
/**
* This field was generated by MyBatis Generator. This field corresponds to
the database column person.updatetime
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
private Date updatetime;
/**
* This method was generated by MyBatis Generator. This method returns the
value of the database column person.person_id
* #return the value of person.person_id
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public Long getPersonId() {
return personId;
}
/**
* This method was generated by MyBatis Generator. This method sets the
value of the database column person.person_id
* #param personId the value for person.person_id
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public void setPersonId(Long personId) {
this.personId = personId;
}
/**
* This method was generated by MyBatis Generator. This method returns the
value of the database column person.name
* #return the value of person.name
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public String getName() {
return name;
}
/**
* This method was generated by MyBatis Generator. This method sets the
value of the database column person.name
* #param name the value for person.name
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public void setName(String name) {
this.name = name;
}
/**
* This method was generated by MyBatis Generator. This method returns the
value of the database column person.createtime
* #return the value of person.createtime
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public Date getCreatetime() {
return createtime;
}
/**
* This method was generated by MyBatis Generator. This method sets the
value of the database column person.createtime
* #param createtime the value for person.createtime
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
/**
* This method was generated by MyBatis Generator. This method returns the
value of the database column person.used
* #return the value of person.used
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public Boolean getUsed() {
return used;
}
/**
* This method was generated by MyBatis Generator. This method sets the
value of the database column person.used
* #param used the value for person.used
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public void setUsed(Boolean used) {
this.used = used;
}
/**
* This method was generated by MyBatis Generator. This method returns the
value of the database column person.updatetime
* #return the value of person.updatetime
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public Date getUpdatetime() {
return updatetime;
}
/**
* This method was generated by MyBatis Generator. This method sets the
value of the database column person.updatetime
* #param updatetime the value for person.updatetime
* #mbg.generated Tue Sep 11 09:09:49 GMT+08:00 2018
*/
public void setUpdatetime(Date updatetime) {
this.updatetime = updatetime;
}
}

Related

Apps Script JDBC reads DATETIME with wrong timezone

I'm trying to read from a DATETIME field in MySQL using the Apps Script JDBC service. The database has its timezone set to UTC (##global.time_zone == ##session.time_zone == '+00:00'), and I've double-checked this by doing SELECT UNIX_TIMESTAMP(COL) FROM TABLE. My script is also set to use UTC.
However, when I read the value from the JDBC result set using getTimestamp, it is skewed forwards by 8 hours. This occurs regardless of whether I pass a timezone to getTimestamp (indeed, there is no change whatsoever, regardless of what timezone I pass), and regardless of whether useJDBCCompliantTimeZoneShift is enabled or not.
If I read the result using getString, it gives the correct time (in UTC). Barring using getString and parsing it into a JavaScript Date, how can I fix this issue?
Edit
Here's a testing script I used, and its output:
export function tzTest(): void {
const dbIp = DB_IP
const dbPw = DB_PW
let conn = Jdbc.getConnection(`jdbc:mysql://${dbIp}/mydb`, { user: "myuser", password: dbPw })
let stmt = conn.prepareStatement("SELECT COL FROM MYTABLE WHERE OWNER_ID=1")
stmt.execute()
let res = stmt.getResultSet()
res.next()
console.log("==== DEFAULT ====")
console.log("=== getTimestamp ===")
console.log(`plain: ${new Date(res.getTimestamp(1).getTime())} (${res.getTimestamp(1).getTime()})`)
console.log(`utc: ${new Date(res.getTimestamp(1, "UTC").getTime())} (${res.getTimestamp(1, "UTC").getTime()})`)
console.log("=== getTime ===")
console.log(`plain: ${new Date(res.getTime(1).getTime())} (${res.getTime(1).getTime()})`)
console.log(`utc: ${new Date(res.getTime(1, "UTC").getTime())} (${res.getTime(1, "UTC").getTime()})`)
console.log("=== getDate ===")
console.log(`plain: ${new Date(res.getDate(1).getTime())} (${res.getDate(1).getTime()})`)
console.log(`utc: ${new Date(res.getDate(1, "UTC").getTime())} (${res.getDate(1, "UTC").getTime()})`)
conn.close()
conn = Jdbc.getConnection(`jdbc:mysql://${dbIp}/mydb`, { user: "myuser", password: dbPw, useJDBCCompliantTimeZoneShift: true })
stmt = conn.prepareStatement("SELECT COL FROM MYTABLE WHERE OWNER_ID=1")
stmt.execute()
res = stmt.getResultSet()
res.next()
console.log("==== useJDBCCompliantTimeZoneShift ====")
console.log("=== getTimestamp ===")
console.log(`plain: ${new Date(res.getTimestamp(1).getTime())} (${res.getTimestamp(1).getTime()})`)
console.log(`utc: ${new Date(res.getTimestamp(1, "UTC").getTime())} (${res.getTimestamp(1, "UTC").getTime()})`)
console.log("=== getTime ===")
console.log(`plain: ${new Date(res.getTime(1).getTime())} (${res.getTime(1).getTime()})`)
console.log(`utc: ${new Date(res.getTime(1, "UTC").getTime())} (${res.getTime(1, "UTC").getTime()})`)
console.log("=== getDate ===")
console.log(`plain: ${new Date(res.getDate(1).getTime())} (${res.getDate(1).getTime()})`)
console.log(`utc: ${new Date(res.getDate(1, "UTC").getTime())} (${res.getDate(1, "UTC").getTime()})`)
conn.close()
}
This results in the following output:
==== DEFAULT ====
=== getTimestamp ===
plain: Sat Dec 21 2019 15:39:17 GMT+0000 (Coordinated Universal Time) (1576942757000)
utc: Sat Dec 21 2019 15:39:17 GMT+0000 (Coordinated Universal Time) (1576942757000)
=== getTime ===
plain: Thu Jan 01 1970 15:39:17 GMT+0000 (Coordinated Universal Time) (56357000)
utc: Thu Jan 01 1970 15:39:17 GMT+0000 (Coordinated Universal Time) (56357000)
=== getDate ===
plain: Sat Dec 21 2019 08:00:00 GMT+0000 (Coordinated Universal Time) (1576915200000)
utc: Sat Dec 21 2019 00:00:00 GMT+0000 (Coordinated Universal Time) (1576886400000)
==== useJDBCCompliantTimeZoneShift ====
=== getTimestamp ===
plain: Sat Dec 21 2019 15:39:17 GMT+0000 (Coordinated Universal Time) (1576942757000)
utc: Sat Dec 21 2019 15:39:17 GMT+0000 (Coordinated Universal Time) (1576942757000)
=== getTime ===
plain: Thu Jan 01 1970 15:39:17 GMT+0000 (Coordinated Universal Time) (56357000)
utc: Thu Jan 01 1970 15:39:17 GMT+0000 (Coordinated Universal Time) (56357000)
=== getDate ===
plain: Sat Dec 21 2019 08:00:00 GMT+0000 (Coordinated Universal Time) (1576915200000)
utc: Sat Dec 21 2019 00:00:00 GMT+0000 (Coordinated Universal Time) (1576886400000)
For comparison, SELECT COL,(UNIX_TIMESTAMP(COL) * 1000) FROM MYTABLE WHERE OWNER_ID=1 gives 2019-12-21 07:39:17 and 1576913957000.
This issue seems to be a bug in the past and should already be fixed.
Including useJDBCCompliantTimezoneShift=true in the connection parameter should fix the issue to interpret the timezone correctly.
Noting here that the timezone shown when converting a JavaScript Date to a string will always be the timezone of the server (in this case UTC) that's why your workaround fixed it.

OpenShift Cronjob schedule to run on only on 1st Wednesday of a month

I'm converting my cronjob schedule from Unix to OpenShift (by creating yaml file) and i'm not finding the option to schedule it to run on a certain day in yaml file. I tried these options, but it still doesn't work.
00 5 0-7 * * [ date +\%u = 3 ] && > (this is what i've in Unix)
schedule: '00 05 * * 3/1' (this runs even on second Wednesday)
schedule: '00 05 0-7 * 3'
schedule: '00 05 0-7 * "[ date +\%u = 3 ]"' - Throws error while creation (Invalid value: "00 05 * * "[ date +\\%u = 3 ]"": Expected exactly 5 fields)
schedule: '00 05 * * 3#1' - Throws error while creation ("00 05 * * 3#1": Failed to parse int from 3#1: strconv.Atoi: parsing "3#1")

Set age group based on DOB

I would like to create a Google Sheet function that if supplied with a date of birth, looks up the below table and gives the appropriate age group. I will be using this table to group 200 kids for surf lifesaving.
for example...date of Birth is 11 Oct 2011, then the age group will be U7. I have use the query function to get this data but I would like to contain it in a function and store the table as a array and compare the date to the array table.
- U 5 01 Oct 2013 30 Sep 2017
- U 6 01 Oct 2012 30 Sep 2013
- U 7 01 Oct 2011 30 Sep 2012
- U 8 01 Oct 2010 30 Sep 2011
- U 9 01 Oct 2009 30 Sep 2010
- U 10 01 Oct 2008 30 Sep 2009
- U 11 01 Oct 2007 30 Sep 2008
- U 12 01 Oct 2006 30 Sep 2007
- U 13 01 Oct 2005 30 Sep 2006
- U 14 01 Oct 2004 30 Sep 2005
Dates can be a little tricky. See This question to get a better idea. But this script can at least get you started.
This Google Sheet demonstrates a custom formula (AGEGROUP) to compare the input date to a "age-groups" sheet.
Note: Only add to "age-groups" sheet if needed.
The last row with a value is used to consider if someone is too old.
The first row of the sheet is used to see if someone is too young.
AGEGROUP() will accept a cell reference to look up
Example AGEGROUP(B2)would check cell B2, assuming it contains a date, and return a group assignment (U 5, U 6, U7...).
Looking up dates manually (instead of referencing another cell) can be accomplished by nesting DATE inside of AGEGROUP. You must follow the right arguments for DATE (year, month, day).
Example AGEGROUP(DATE(2010,1,21))
I'm new to custom functions and did not look into the options for supporting function details like #param or #return and so on.
Apps Script
/**
* Finds age group of the input value (date).
*
* #param {date} Input the date to compare to date ranges.
* #return Returns age groupd based on provided date.
* #customfunction
*/
function AGEGROUP(date) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var ages = ss.getSheetByName("age-groups");
var range = ages.getDataRange();
var values = range.getValues();
var i = 0;
var ranges = values.length;
var lastRow = ranges -1;
// loop through dateRanges
for(i; i < ranges; i++) {
// if date in AGEGROUP()
if(date >= values[i][1] && date <= values[i][2]) {
// return age group
return values[i][0];
}
// if child is too old
if(date > values[0][2]) {
return "Child is too young.";
}
// if child is too young
if(date < values[lastRow][1]) {
return "Child is too old.";
}
}
}

How to fetch JSON content values dynamically using JSON slurper in groovy

I am trying to filter out the JSON response values by passing on few parameters dynamically. Below is the code.
import com.eviware.soapui.support.XmlHolder
import groovy.json.JsonSlurper
responseContent = testRunner.testCase.getTestStepByName("Request 1").getPropertyValue("Response")
jsonresponse = new JsonSlurper().parseText(responseContent)
log.info jsonresponse.context["parameter"]
context["parameter"] stores the values from an Excel sheet and doing only a log.info for context["parameter"], it shows those values correctly. Below is the output of the code log.info context["parameter"].
Thu Dec 14 07:18:53 CST 2017:INFO:firstName
Thu Dec 14 07:18:53 CST 2017:INFO:lastName
Thu Dec 14 07:18:54 CST 2017:INFO:frNum
Thu Dec 14 07:18:54 CST 2017:INFO:notes
But when I execute the code
log.info jsonresponse.context["parameter"]
Result:
Thu Dec 14 07:20:41 CST 2017:INFO:[]
Thu Dec 14 07:20:41 CST 2017:INFO:[]
Thu Dec 14 07:20:41 CST 2017:INFO:[]
Thu Dec 14 07:20:42 CST 2017:INFO:[]
Thu Dec 14 07:20:42 CST 2017:INFO:[]
log.info jsonresponse yields the below response out of which I need to get certain values (values stored in the context["parameter"])
Thu Dec 14 07:21:45 CST 2017:INFO:[{errorMessage=null, middleName=null, lastName=Kosnick, frName=Kosnick Steven H , mplastName=null, competeRgnTxt=null, doNum=null, gddUnitStDate=null, fdNum=null, mpfirstName=null, legalEntityID=null, noNum=null, contractType=Financial Rep, frNum=046426, offcNum=NO 091, notes=Active, fullTmeSrvDt=null, firstName=Steven, networkOfficeNum=091}]
Instead of this :
log.info jsonresponse.context["parameter"]
Try this :
log.info jsonresponse[context["parameter"]]
This should resolve your issue :)

How to get start date and end date of current month in AS3

I have 2 DateFields named startDate and endDate I want to set startDate's Selected date to Current months start date and endDate's Selected date to Current months End date.
How can I achieve this?
Thanks in advance...
You mean this?
package
{
import flash.display.Sprite;
public class DateExample extends Sprite
{
public function DateExample()
{
super();
var now:Date = new Date();
trace("now: " + now.toString());
var startDate:Date = new Date(now.fullYear, now.month, 1);
trace("start: " + startDate.toString());
var endDate:Date = new Date(now.fullYear, ++now.month, 0);
trace("end: " + endDate.toString());
}
}
}
output:
now: Fri Oct 21 00:15:09 GMT-0500 2011
start: Sat Oct 1 00:00:00 GMT-0500 2011
end: Mon Oct 31 00:00:00 GMT-0500 2011