Example usage for org.hibernate.type StandardBasicTypes TIMESTAMP

List of usage examples for org.hibernate.type StandardBasicTypes TIMESTAMP

Introduction

In this page you can find the example usage for org.hibernate.type StandardBasicTypes TIMESTAMP.

Prototype

TimestampType TIMESTAMP

To view the source code for org.hibernate.type StandardBasicTypes TIMESTAMP.

Click Source Link

Document

The standard Hibernate type for mapping java.util.Date ( java.sql.Timestamp ) to JDBC java.sql.Types#TIMESTAMP TIMESTAMP .

Usage

From source file:ch.wisv.areafiftylan.utils.LocalDateTimeUserType.java

License:Open Source License

@Override
public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Object timestamp = StandardBasicTypes.TIMESTAMP.nullSafeGet(resultSet, names, session, owner);
    if (timestamp == null) {
        return null;
    }/*from w w w  .  j a  va 2s.  c  o  m*/
    Date ts = (Date) timestamp;
    Instant instant = Instant.ofEpochMilli(ts.getTime());
    return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
}

From source file:ch.wisv.areafiftylan.utils.LocalDateTimeUserType.java

License:Open Source License

@Override
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index,
        SessionImplementor session) throws HibernateException, SQLException {
    if (value == null) {
        StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, null, index, session);
    } else {//from ww w  .j av a  2  s.  co m
        LocalDateTime ldt = ((LocalDateTime) value);
        Instant instant = ldt.atZone(ZoneId.systemDefault()).toInstant();
        Date timestamp = Date.from(instant);
        StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, timestamp, index, session);
    }
}

From source file:com.mysema.query.jpa.support.TeradataDialect.java

License:Open Source License

/**
 * Constructor/*  w w  w .j a  v  a2  s . c o m*/
 */
public TeradataDialect() {
    super();
    // registerColumnType data types
    registerColumnType(Types.NUMERIC, "NUMERIC($p,$s)");
    registerColumnType(Types.DOUBLE, "DOUBLE PRECISION");
    registerColumnType(Types.BIGINT, "NUMERIC(18,0)");
    registerColumnType(Types.BIT, "BYTEINT");
    registerColumnType(Types.TINYINT, "BYTEINT");
    registerColumnType(Types.VARBINARY, "VARBYTE($l)");
    registerColumnType(Types.BINARY, "BYTEINT");
    registerColumnType(Types.LONGVARCHAR, "LONG VARCHAR");
    registerColumnType(Types.CHAR, "CHAR(1)");
    registerColumnType(Types.DECIMAL, "DECIMAL");
    registerColumnType(Types.INTEGER, "INTEGER");
    registerColumnType(Types.SMALLINT, "SMALLINT");
    registerColumnType(Types.FLOAT, "FLOAT");
    registerColumnType(Types.VARCHAR, "VARCHAR($l)");
    registerColumnType(Types.DATE, "DATE");
    registerColumnType(Types.TIME, "TIME");
    registerColumnType(Types.TIMESTAMP, "TIMESTAMP");
    registerColumnType(Types.BOOLEAN, "BYTEINT"); // hibernate seems to
                                                  // ignore this type...
    registerColumnType(Types.BLOB, "BLOB");
    registerColumnType(Types.CLOB, "CLOB");

    registerFunction("year", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "extract(year from ?1)"));
    registerFunction("length", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "character_length(?1)"));
    registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "(", "||", ")"));
    registerFunction("substring",
            new SQLFunctionTemplate(StandardBasicTypes.STRING, "substring(?1 from ?2 for ?3)"));
    registerFunction("locate", new SQLFunctionTemplate(StandardBasicTypes.STRING, "position(?1 in ?2)"));
    registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.STRING, "?1 mod ?2"));
    registerFunction("str", new SQLFunctionTemplate(StandardBasicTypes.STRING, "cast(?1 as varchar(255))"));

    // bit_length feels a bit broken to me. We have to cast to char in order
    // to
    // pass when a numeric value is supplied. But of course the answers
    // given will
    // be wildly different for these two datatypes. 1234.5678 will be 9
    // bytes as
    // a char string but will be 8 or 16 bytes as a true numeric.
    // Jay Nance 2006-09-22
    registerFunction("bit_length",
            new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "octet_length(cast(?1 as char))*4"));

    // The preference here would be
    // SQLFunctionTemplate( Hibernate.TIMESTAMP, "current_timestamp(?1)",
    // false)
    // but this appears not to work.
    // Jay Nance 2006-09-22
    registerFunction("current_timestamp",
            new SQLFunctionTemplate(StandardBasicTypes.TIMESTAMP, "current_timestamp"));
    registerFunction("current_time", new SQLFunctionTemplate(StandardBasicTypes.TIME, "current_time"));
    registerFunction("current_date", new SQLFunctionTemplate(StandardBasicTypes.DATE, "current_date"));
    // IBID for current_time and current_date

    registerKeyword("account");
    registerKeyword("alias");
    registerKeyword("class");
    registerKeyword("column");
    registerKeyword("first");
    registerKeyword("map");
    registerKeyword("month");
    registerKeyword("password");
    registerKeyword("role");
    registerKeyword("summary");
    registerKeyword("title");
    registerKeyword("type");
    registerKeyword("value");
    registerKeyword("year");

    // Tell hibernate to use getBytes instead of getBinaryStream
    getDefaultProperties().setProperty(Environment.USE_STREAMS_FOR_BINARY, "false");
    // No batch statements
    getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
}

From source file:com.processpuzzle.persistence.typemapping.domain.TimePeriodTypeMapping.java

License:Open Source License

public Type[] getPropertyTypes() {
    return new Type[] { StandardBasicTypes.TIMESTAMP, StandardBasicTypes.TIMESTAMP };
}

From source file:com.processpuzzle.persistence.typemapping.domain.TimePeriodTypeMapping.java

License:Open Source License

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Date begin = (Date) StandardBasicTypes.TIMESTAMP.nullSafeGet(rs, names[0], session);
    Date end = (Date) StandardBasicTypes.TIMESTAMP.nullSafeGet(rs, names[1], session);
    if (begin == null && end == null)
        return null;
    else {/*  w w w.  j a va 2  s  . co m*/
        return new TimePeriod(begin != null ? new TimePoint(begin) : null,
                end != null ? new TimePoint(end) : null);
    }
}

From source file:com.processpuzzle.persistence.typemapping.domain.TimePeriodTypeMapping.java

License:Open Source License

public void nullSafeSet(PreparedStatement statement, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    if (value != null) {
        if (((TimePeriod) value).getBegin() != null) {
            StandardBasicTypes.TIMESTAMP.nullSafeSet(statement, ((TimePeriod) value).getBegin().getValue(),
                    index, session);//from   w w  w.  j  a  va2 s.  c o m
        } else {
            statement.setNull(index, Types.TIMESTAMP);
        }
        if (((TimePeriod) value).getEnd() != null) {
            StandardBasicTypes.TIMESTAMP.nullSafeSet(statement, ((TimePeriod) value).getEnd().getValue(),
                    index + 1, session);
        } else {
            statement.setNull(index + 1, Types.TIMESTAMP);
        }
    } else {
        statement.setNull(index, Types.TIMESTAMP);
        statement.setNull(index + 1, Types.TIMESTAMP);
    }
}

From source file:com.processpuzzle.persistence.typemapping.domain.TimePointToTimeStampMapping.java

License:Open Source License

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {

    Timestamp timeStamp = (Timestamp) StandardBasicTypes.TIMESTAMP.nullSafeGet(rs, names[0], session);
    return new TimePoint(new Date(timeStamp.getTime()));
}

From source file:com.processpuzzle.persistence.typemapping.domain.TimePointToTimeStampMapping.java

License:Open Source License

public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    if (value == null) {
        st.setNull(index + 1, Types.TIMESTAMP);
    } else {//w w w . ja  va 2  s.  co m
        StandardBasicTypes.TIMESTAMP.nullSafeSet(st, ((TimePoint) value).getValue(), index, session);
    }
}

From source file:com.processpuzzle.persistence.typemapping.domain.TimePointToTimeStampMapping.java

License:Open Source License

public Type[] getPropertyTypes() {
    return new Type[] { StandardBasicTypes.TIMESTAMP };
}

From source file:com.syndiceo.MySQLDialect.java

License:Open Source License

public MySQLDialect() {
    super();// w w  w .  ja v a2s.c  o  m
    registerColumnType(Types.BIT, "bit");
    registerColumnType(Types.BIGINT, "int8");
    registerColumnType(Types.SMALLINT, "smallint");
    registerColumnType(Types.TINYINT, "tinyint");
    registerColumnType(Types.INTEGER, "integer");
    registerColumnType(Types.CHAR, "char(1)");
    registerColumnType(Types.FLOAT, "float");
    registerColumnType(Types.DOUBLE, "double precision");
    registerColumnType(Types.DATE, "date");
    registerColumnType(Types.TIME, "time");
    registerColumnType(Types.TIMESTAMP, "datetime");
    registerColumnType(Types.VARBINARY, "longblob");
    registerColumnType(Types.VARBINARY, 16777215, "mediumblob");
    registerColumnType(Types.VARBINARY, 65535, "blob");
    registerColumnType(Types.VARBINARY, 255, "tinyblob");
    registerColumnType(Types.BINARY, "binary($l)");
    registerColumnType(Types.LONGVARBINARY, "longblob");
    registerColumnType(Types.LONGVARBINARY, 16777215, "mediumblob");
    registerColumnType(Types.NUMERIC, "decimal($p,$s)");
    registerColumnType(Types.BLOB, "longblob");
    //      registerColumnType( Types.BLOB, 16777215, "mediumblob" );
    //      registerColumnType( Types.BLOB, 65535, "blob" );
    registerColumnType(Types.CLOB, "longtext");
    //      registerColumnType( Types.CLOB, 16777215, "mediumtext" );
    //      registerColumnType( Types.CLOB, 65535, "text" );
    registerVarcharTypes();

    registerFunction("ascii", new StandardSQLFunction("ascii", StandardBasicTypes.INTEGER));
    registerFunction("bin", new StandardSQLFunction("bin", StandardBasicTypes.STRING));
    registerFunction("char_length", new StandardSQLFunction("char_length", StandardBasicTypes.LONG));
    registerFunction("character_length", new StandardSQLFunction("character_length", StandardBasicTypes.LONG));
    registerFunction("lcase", new StandardSQLFunction("lcase"));
    registerFunction("lower", new StandardSQLFunction("lower"));
    registerFunction("ltrim", new StandardSQLFunction("ltrim"));
    registerFunction("ord", new StandardSQLFunction("ord", StandardBasicTypes.INTEGER));
    registerFunction("quote", new StandardSQLFunction("quote"));
    registerFunction("reverse", new StandardSQLFunction("reverse"));
    registerFunction("rtrim", new StandardSQLFunction("rtrim"));
    registerFunction("soundex", new StandardSQLFunction("soundex"));
    registerFunction("space", new StandardSQLFunction("space", StandardBasicTypes.STRING));
    registerFunction("ucase", new StandardSQLFunction("ucase"));
    registerFunction("upper", new StandardSQLFunction("upper"));
    registerFunction("unhex", new StandardSQLFunction("unhex", StandardBasicTypes.STRING));

    registerFunction("abs", new StandardSQLFunction("abs"));
    registerFunction("sign", new StandardSQLFunction("sign", StandardBasicTypes.INTEGER));

    registerFunction("acos", new StandardSQLFunction("acos", StandardBasicTypes.DOUBLE));
    registerFunction("asin", new StandardSQLFunction("asin", StandardBasicTypes.DOUBLE));
    registerFunction("atan", new StandardSQLFunction("atan", StandardBasicTypes.DOUBLE));
    registerFunction("cos", new StandardSQLFunction("cos", StandardBasicTypes.DOUBLE));
    registerFunction("cot", new StandardSQLFunction("cot", StandardBasicTypes.DOUBLE));
    registerFunction("crc32", new StandardSQLFunction("crc32", StandardBasicTypes.LONG));
    registerFunction("exp", new StandardSQLFunction("exp", StandardBasicTypes.DOUBLE));
    registerFunction("ln", new StandardSQLFunction("ln", StandardBasicTypes.DOUBLE));
    registerFunction("log", new StandardSQLFunction("log", StandardBasicTypes.DOUBLE));
    registerFunction("log2", new StandardSQLFunction("log2", StandardBasicTypes.DOUBLE));
    registerFunction("log10", new StandardSQLFunction("log10", StandardBasicTypes.DOUBLE));
    registerFunction("pi", new NoArgSQLFunction("pi", StandardBasicTypes.DOUBLE));
    registerFunction("rand", new NoArgSQLFunction("rand", StandardBasicTypes.DOUBLE));
    registerFunction("sin", new StandardSQLFunction("sin", StandardBasicTypes.DOUBLE));
    registerFunction("sqrt", new StandardSQLFunction("sqrt", StandardBasicTypes.DOUBLE));
    registerFunction("tan", new StandardSQLFunction("tan", StandardBasicTypes.DOUBLE));

    registerFunction("radians", new StandardSQLFunction("radians", StandardBasicTypes.DOUBLE));
    registerFunction("degrees", new StandardSQLFunction("degrees", StandardBasicTypes.DOUBLE));

    registerFunction("ceiling", new StandardSQLFunction("ceiling", StandardBasicTypes.INTEGER));
    registerFunction("ceil", new StandardSQLFunction("ceil", StandardBasicTypes.INTEGER));
    registerFunction("floor", new StandardSQLFunction("floor", StandardBasicTypes.INTEGER));
    registerFunction("round", new StandardSQLFunction("round"));

    registerFunction("datediff", new StandardSQLFunction("datediff", StandardBasicTypes.INTEGER));
    registerFunction("timediff", new StandardSQLFunction("timediff", StandardBasicTypes.TIME));
    registerFunction("date_format", new StandardSQLFunction("date_format", StandardBasicTypes.STRING));

    registerFunction("curdate", new NoArgSQLFunction("curdate", StandardBasicTypes.DATE));
    registerFunction("curtime", new NoArgSQLFunction("curtime", StandardBasicTypes.TIME));
    registerFunction("current_date", new NoArgSQLFunction("current_date", StandardBasicTypes.DATE, false));
    registerFunction("current_time", new NoArgSQLFunction("current_time", StandardBasicTypes.TIME, false));
    registerFunction("current_timestamp",
            new NoArgSQLFunction("current_timestamp", StandardBasicTypes.TIMESTAMP, false));
    registerFunction("date", new StandardSQLFunction("date", StandardBasicTypes.DATE));
    registerFunction("day", new StandardSQLFunction("day", StandardBasicTypes.INTEGER));
    registerFunction("dayofmonth", new StandardSQLFunction("dayofmonth", StandardBasicTypes.INTEGER));
    registerFunction("dayname", new StandardSQLFunction("dayname", StandardBasicTypes.STRING));
    registerFunction("dayofweek", new StandardSQLFunction("dayofweek", StandardBasicTypes.INTEGER));
    registerFunction("dayofyear", new StandardSQLFunction("dayofyear", StandardBasicTypes.INTEGER));
    registerFunction("from_days", new StandardSQLFunction("from_days", StandardBasicTypes.DATE));
    registerFunction("from_unixtime", new StandardSQLFunction("from_unixtime", StandardBasicTypes.TIMESTAMP));
    registerFunction("hour", new StandardSQLFunction("hour", StandardBasicTypes.INTEGER));
    registerFunction("last_day", new StandardSQLFunction("last_day", StandardBasicTypes.DATE));
    registerFunction("localtime", new NoArgSQLFunction("localtime", StandardBasicTypes.TIMESTAMP));
    registerFunction("localtimestamp", new NoArgSQLFunction("localtimestamp", StandardBasicTypes.TIMESTAMP));
    registerFunction("microseconds", new StandardSQLFunction("microseconds", StandardBasicTypes.INTEGER));
    registerFunction("minute", new StandardSQLFunction("minute", StandardBasicTypes.INTEGER));
    registerFunction("month", new StandardSQLFunction("month", StandardBasicTypes.INTEGER));
    registerFunction("monthname", new StandardSQLFunction("monthname", StandardBasicTypes.STRING));
    registerFunction("now", new NoArgSQLFunction("now", StandardBasicTypes.TIMESTAMP));
    registerFunction("quarter", new StandardSQLFunction("quarter", StandardBasicTypes.INTEGER));
    registerFunction("second", new StandardSQLFunction("second", StandardBasicTypes.INTEGER));
    registerFunction("sec_to_time", new StandardSQLFunction("sec_to_time", StandardBasicTypes.TIME));
    registerFunction("sysdate", new NoArgSQLFunction("sysdate", StandardBasicTypes.TIMESTAMP));
    registerFunction("time", new StandardSQLFunction("time", StandardBasicTypes.TIME));
    registerFunction("timestamp", new StandardSQLFunction("timestamp", StandardBasicTypes.TIMESTAMP));
    registerFunction("time_to_sec", new StandardSQLFunction("time_to_sec", StandardBasicTypes.INTEGER));
    registerFunction("to_days", new StandardSQLFunction("to_days", StandardBasicTypes.LONG));
    registerFunction("unix_timestamp", new StandardSQLFunction("unix_timestamp", StandardBasicTypes.LONG));
    registerFunction("utc_date", new NoArgSQLFunction("utc_date", StandardBasicTypes.STRING));
    registerFunction("utc_time", new NoArgSQLFunction("utc_time", StandardBasicTypes.STRING));
    registerFunction("utc_timestamp", new NoArgSQLFunction("utc_timestamp", StandardBasicTypes.STRING));
    registerFunction("week", new StandardSQLFunction("week", StandardBasicTypes.INTEGER));
    registerFunction("weekday", new StandardSQLFunction("weekday", StandardBasicTypes.INTEGER));
    registerFunction("weekofyear", new StandardSQLFunction("weekofyear", StandardBasicTypes.INTEGER));
    registerFunction("year", new StandardSQLFunction("year", StandardBasicTypes.INTEGER));
    registerFunction("yearweek", new StandardSQLFunction("yearweek", StandardBasicTypes.INTEGER));

    registerFunction("hex", new StandardSQLFunction("hex", StandardBasicTypes.STRING));
    registerFunction("oct", new StandardSQLFunction("oct", StandardBasicTypes.STRING));

    registerFunction("octet_length", new StandardSQLFunction("octet_length", StandardBasicTypes.LONG));
    registerFunction("bit_length", new StandardSQLFunction("bit_length", StandardBasicTypes.LONG));

    registerFunction("bit_count", new StandardSQLFunction("bit_count", StandardBasicTypes.LONG));
    registerFunction("encrypt", new StandardSQLFunction("encrypt", StandardBasicTypes.STRING));
    registerFunction("md5", new StandardSQLFunction("md5", StandardBasicTypes.STRING));
    registerFunction("sha1", new StandardSQLFunction("sha1", StandardBasicTypes.STRING));
    registerFunction("sha", new StandardSQLFunction("sha", StandardBasicTypes.STRING));

    registerFunction("concat", new StandardSQLFunction("concat", StandardBasicTypes.STRING));

    getDefaultProperties().setProperty(Environment.MAX_FETCH_DEPTH, "2");
    getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
}