List of usage examples for org.hibernate.type StandardBasicTypes TIMESTAMP
TimestampType TIMESTAMP
To view the source code for org.hibernate.type StandardBasicTypes TIMESTAMP.
Click Source Link
From source file:debop4k.data.orm.hibernate.usertypes.jodatime.DateTimeUserType.java
License:Apache License
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { Timestamp timestamp = (value instanceof DateTime) ? new Timestamp(((DateTime) value).getMillis()) : null; StandardBasicTypes.TIMESTAMP.nullSafeSet(st, timestamp, index, session); }
From source file:debop4k.data.orm.hibernate.usertypes.jodatime.TimePeriodAsTimestampUserType.java
License:Apache License
@Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { Timestamp start = (Timestamp) StandardBasicTypes.TIMESTAMP.nullSafeGet(rs, names[0], session, owner); Timestamp end = (Timestamp) StandardBasicTypes.TIMESTAMP.nullSafeGet(rs, names[1], session, owner); return new TimeRange(KodaTimex.toDateTime(start), KodaTimex.toDateTime(end)); }
From source file:debop4k.data.orm.hibernate.usertypes.jodatime.TimePeriodAsTimestampUserType.java
License:Apache License
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { ITimePeriod period = asTimePeriod(value); if (period == null) { StandardBasicTypes.TIMESTAMP.nullSafeSet(st, null, index, session); StandardBasicTypes.TIMESTAMP.nullSafeSet(st, null, index + 1, session); } else {/* www.j a v a2 s . co m*/ Timestamp start = period.hasStart() ? new Timestamp(period.getStart().getMillis()) : null; Timestamp end = period.hasEnd() ? new Timestamp(period.getEnd().getMillis()) : null; StandardBasicTypes.TIMESTAMP.nullSafeSet(st, start, index, session); StandardBasicTypes.TIMESTAMP.nullSafeSet(st, end, index + 1, session); } }
From source file:debop4k.data.orm.hibernate.usertypes.jodatime.TimestampAndTimeZoneUserType.java
License:Apache License
@Override public int[] sqlTypes() { return new int[] { StandardBasicTypes.TIMESTAMP.sqlType(), StandardBasicTypes.STRING.sqlType() }; }
From source file:debop4k.data.orm.hibernate.usertypes.jodatime.TimestampAndTimeZoneUserType.java
License:Apache License
@Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { Timestamp timestamp = (Timestamp) StandardBasicTypes.TIMESTAMP.nullSafeGet(rs, names[0], session, owner); String zoneId = (String) StandardBasicTypes.STRING.nullSafeGet(rs, names[1], session, owner); if (timestamp != null) { return (zoneId != null) ? new DateTime(timestamp, DateTimeZone.forID(zoneId)) : new DateTime(timestamp, DateTimeZone.UTC); } else {//from w w w. ja v a2 s .c om return null; } }
From source file:debop4k.data.orm.hibernate.usertypes.jodatime.TimestampAndTimeZoneUserType.java
License:Apache License
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { DateTime time = (DateTime) value;/*from w w w . j av a 2s . c o m*/ if (time == null) { StandardBasicTypes.TIMESTAMP.nullSafeSet(st, null, index, session); StandardBasicTypes.STRING.nullSafeSet(st, null, index + 1, session); } else { StandardBasicTypes.TIMESTAMP.nullSafeSet(st, new Timestamp(time.getMillis()), index, session); StandardBasicTypes.STRING.nullSafeSet(st, time.getZone().getID(), index + 1, session); } }
From source file:edu.psu.iam.cpr.core.database.tables.AddressesTable.java
License:Apache License
/** * This routine will obtain a list of addresses for a person id * @param db contains the Database object * @param personId contains the personID * /* w w w.ja v a 2 s .c o m*/ * @return list of addresses */ public AddressReturn[] getAddress(final Database db, final long personId) { final Session session = db.getSession(); final List<AddressReturn> results = new ArrayList<AddressReturn>(); final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append( "SELECT addresses.address_key, addresses.data_type_key, addresses.document_type_key, addresses.group_id,"); sb.append("addresses.primary_flag,addresses.address1, addresses.address2, addresses.address3, "); sb.append("addresses.city, addresses.state, addresses.postal_code, addresses.province, verified_flag, "); sb.append("addresses.start_date, "); sb.append("addresses.end_date, "); sb.append("addresses.last_update_by, "); sb.append("addresses.last_update_on, "); sb.append("addresses.created_by, "); sb.append("addresses.created_on, "); sb.append("campus_cs.campus_code, campus_cs.campus, "); sb.append("country.country_code_three, country.country "); sb.append("FROM {h-schema}addresses "); sb.append("LEFT JOIN {h-schema}campus_cs ON addresses.campus_code_key = campus_cs.campus_code_key "); sb.append("LEFT JOIN {h-schema}country ON addresses.country_key = country.country_key "); sb.append("WHERE addresses.person_id = :person_id_in "); if (getAddressType() != null) { sb.append("AND addresses.data_type_key = :data_type_key_in "); } // If we are not returning all records, we need to just return the active ones. if (!isReturnHistoryFlag()) { sb.append("AND addresses.end_date IS NULL "); } if (getAddressKey() > 0L) { sb.append("AND addresses.address_key = :address_key_in "); } sb.append("ORDER BY addresses.data_type_key ASC, addresses.start_date ASC "); final SQLQuery query = session.createSQLQuery(sb.toString()); query.setParameter("person_id_in", personId); if (getAddressType() != null) { query.setParameter("data_type_key_in", getAddressType().index()); } if (getAddressKey() > 0L) { query.setParameter("address_key_in", getAddressKey()); } query.addScalar(ADDRESS_KEY_STRING, StandardBasicTypes.LONG); query.addScalar(DATA_TYPE_KEY_STRING, StandardBasicTypes.LONG); query.addScalar(DOCUMENT_TYPE_KEY_STRING, StandardBasicTypes.LONG); query.addScalar(GROUP_ID_STRING, StandardBasicTypes.LONG); query.addScalar("primary_flag", StandardBasicTypes.STRING); query.addScalar("address1", StandardBasicTypes.STRING); query.addScalar("address2", StandardBasicTypes.STRING); query.addScalar("address3", StandardBasicTypes.STRING); query.addScalar("city", StandardBasicTypes.STRING); query.addScalar("state", StandardBasicTypes.STRING); query.addScalar("postal_code", StandardBasicTypes.STRING); query.addScalar("province", StandardBasicTypes.STRING); query.addScalar("verified_flag", StandardBasicTypes.STRING); query.addScalar("start_date", StandardBasicTypes.TIMESTAMP); query.addScalar("end_date", StandardBasicTypes.TIMESTAMP); query.addScalar("last_update_by", StandardBasicTypes.STRING); query.addScalar("last_update_on", StandardBasicTypes.TIMESTAMP); query.addScalar("created_by", StandardBasicTypes.STRING); query.addScalar("created_on", StandardBasicTypes.TIMESTAMP); query.addScalar("campus_code", StandardBasicTypes.STRING); query.addScalar("campus", StandardBasicTypes.STRING); query.addScalar("country_code_three", StandardBasicTypes.STRING); query.addScalar("country", StandardBasicTypes.STRING); for (final Iterator<?> it = query.list().iterator(); it.hasNext();) { Object[] res = (Object[]) it.next(); AddressReturn anAddress = new AddressReturn(); anAddress.setAddressKey(((Long) res[ADDRESS_KEY]).toString()); anAddress.setAddressType(AddressType.get((Long) res[ADDRESS_TYPE]).toString()); if (res[DOCUMENT_TYPE] != null) { anAddress.setDocumentType(DocumentType.get((Long) res[DOCUMENT_TYPE]).toString()); } else { anAddress.setDocumentType(null); } anAddress.setGroupId((Long) res[GROUP_ID]); anAddress.setPrimaryFlag((String) res[PRIMARY_FLAG]); anAddress.setAddress1((String) res[ADDRESS1]); anAddress.setAddress2((String) res[ADDRESS2]); anAddress.setAddress3((String) res[ADDRESS3]); anAddress.setCity((String) res[CITY]); String tempState = (String) res[STATE]; anAddress.setPostalCode((String) res[POSTAL_CODE]); String tempProvince = (String) res[PROVINCE]; anAddress.setVerifiedFlag((String) res[VERIFIED_FLAG]); anAddress.setStartDate(Utility.formatDateToISO8601((Date) res[START_DATE])); anAddress.setEndDate(Utility.formatDateToISO8601((Date) res[END_DATE])); anAddress.setLastUpdateBy((String) res[LAST_UPDATE_BY]); anAddress.setLastUpdateOn(Utility.formatDateToISO8601((Date) res[LAST_UPDATE_ON])); anAddress.setCreatedBy((String) res[CREATED_BY]); anAddress.setCreatedOn(Utility.formatDateToISO8601((Date) res[CREATED_ON])); anAddress.setCampusCode((String) res[CAMPUS_CODE]); anAddress.setCampusName((String) res[CAMPUS_NAME]); anAddress.setCountryCode((String) res[COUNTRY_CODE]); anAddress.setCountryName((String) res[COUNTRY_NAME]); if (tempState != null) { anAddress.setStateOrProvince(tempState); } else if (tempProvince != null) { anAddress.setStateOrProvince(tempProvince); } else { anAddress.setStateOrProvince(null); } results.add(anAddress); } return results.toArray(new AddressReturn[results.size()]); }
From source file:edu.psu.iam.cpr.core.database.tables.ConfidentialityTable.java
License:Apache License
/** * This routine is used to obtain the confidentiality hold status for a user. * @param db contains a reference to a database class that contains a open database connection. * @param personId contains the person identifier whose confidentiality is to be obtained * @return will return an array of confidentiality hold statuses. *///from www . j a v a 2 s. c om public ConfidentialityReturn[] getConfidentiality(final Database db, final long personId) { // Init some variables. final List<ConfidentialityReturn> results = new ArrayList<ConfidentialityReturn>(); final Session session = db.getSession(); final StringBuilder sb = new StringBuilder(BUFFER_SIZE); // Build the select statement as a string. sb.append("SELECT "); sb.append("data_type_key, "); sb.append("start_date, "); sb.append("end_date, "); sb.append("last_update_by, "); sb.append("last_update_on, "); sb.append("created_by, "); sb.append("created_on "); sb.append("FROM {h-schema}confidentiality "); sb.append("WHERE person_id = :person_id_in "); // If we are not returning all records, we need to just return the active ones. if (!isReturnHistoryFlag()) { sb.append("AND end_date IS NULL "); } sb.append("ORDER BY data_type_key ASC, start_date ASC "); // Create the hibernate select statement. final SQLQuery query = session.createSQLQuery(sb.toString()); query.setParameter("person_id_in", personId); query.addScalar(DATA_TYPE_KEY_STRING, StandardBasicTypes.LONG); query.addScalar("start_date", StandardBasicTypes.TIMESTAMP); query.addScalar("end_date", StandardBasicTypes.TIMESTAMP); query.addScalar("last_update_by", StandardBasicTypes.STRING); query.addScalar("last_update_on", StandardBasicTypes.TIMESTAMP); query.addScalar("created_by", StandardBasicTypes.STRING); query.addScalar("created_on", StandardBasicTypes.TIMESTAMP); for (final Iterator<?> it = query.list().iterator(); it.hasNext();) { // For each result, store its value in the return class. Object[] res = (Object[]) it.next(); ConfidentialityReturn c = new ConfidentialityReturn( ConfidentialityType.get((Long) res[CONFIDENTIALITY_TYPE]).toString(), Utility.formatDateToISO8601((Date) res[START_DATE]), Utility.formatDateToISO8601((Date) res[END_DATE]), (String) res[LAST_UPDATE_BY], Utility.formatDateToISO8601((Date) res[LAST_UPDATE_ON]), (String) res[CREATED_BY], Utility.formatDateToISO8601((Date) res[CREATED_ON])); results.add(c); } return results.toArray(new ConfidentialityReturn[results.size()]); }
From source file:edu.psu.iam.cpr.core.database.tables.CredentialTable.java
License:Apache License
/** * This routine is used to obtain credential information from the database. * @param db contains the database connection. * @param personId contains the person identifier to retrieve information for. * @return will return a CredentialReturn array. *//*from w ww . j a v a2 s. com*/ public CredentialReturn[] getCredentialForPersonId(final Database db, final long personId) { final List<CredentialReturn> results = new ArrayList<CredentialReturn>(); final Session session = db.getSession(); // Build the query string. final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append("SELECT credential_key, data_type_key, credential_data, "); sb.append("start_date, "); sb.append("end_date, "); sb.append("last_update_by, "); sb.append("last_update_on, "); sb.append("created_by, "); sb.append("created_on "); sb.append("FROM {h-schema}credential "); sb.append("WHERE person_id = :person_id_in "); // Check to see if we are doing a query for credential key. if (getCredentialKey() > 0L) { sb.append("AND credential_key = :credential_key_in "); } // If we are doing a query for a specific credential type, we need to specify this clause. if (getCredentialType() != null) { sb.append("AND data_type_key = :data_type_key_in "); } // If we are not returning all records, we need to just return the active ones. if (!isReturnHistoryFlag()) { sb.append("AND end_date IS NULL "); } sb.append("ORDER BY data_type_key ASC, start_date ASC "); // Set up hibernate for the query, bind parameters and determine return types. final SQLQuery query = session.createSQLQuery(sb.toString()); query.setParameter("person_id_in", personId); if (getCredentialType() != null) { query.setParameter("data_type_key_in", getCredentialType().index()); } if (getCredentialKey() > 0L) { query.setParameter("credential_key_in", getCredentialKey()); } query.addScalar("credential_key", StandardBasicTypes.LONG); query.addScalar(DATA_TYPE_KEY_STRING, StandardBasicTypes.LONG); query.addScalar("credential_data", StandardBasicTypes.STRING); query.addScalar("start_date", StandardBasicTypes.TIMESTAMP); query.addScalar("end_date", StandardBasicTypes.TIMESTAMP); query.addScalar("last_update_by", StandardBasicTypes.STRING); query.addScalar("last_update_on", StandardBasicTypes.TIMESTAMP); query.addScalar("created_by", StandardBasicTypes.STRING); query.addScalar("created_on", StandardBasicTypes.TIMESTAMP); // Perform the query. for (final Iterator<?> it = query.list().iterator(); it.hasNext();) { Object[] res = (Object[]) it.next(); CredentialReturn credentialReturn = new CredentialReturn(); credentialReturn.setCredentialKey(((Long) res[CREDENTIAL_KEY]).toString()); credentialReturn.setCredentialType(CredentialType.get((Long) res[CREDENTIAL_TYPE]).toString()); credentialReturn.setCredentialData((String) res[CREDENTIAL_DATA]); credentialReturn.setStartDate(Utility.formatDateToISO8601((Date) res[START_DATE])); credentialReturn.setEndDate(Utility.formatDateToISO8601((Date) res[END_DATE])); credentialReturn.setLastUpdateBy((String) res[LAST_UPDATE_BY]); credentialReturn.setLastUpdateOn(Utility.formatDateToISO8601((Date) res[LAST_UPDATE_ON])); credentialReturn.setCreatedBy((String) res[CREATED_BY]); credentialReturn.setCreatedOn(Utility.formatDateToISO8601((Date) res[CREATED_ON])); results.add(credentialReturn); } // Check on the results. return results.toArray(new CredentialReturn[results.size()]); }
From source file:edu.psu.iam.cpr.core.database.tables.DateOfBirthTable.java
License:Apache License
/** * This routine is used to obtain the date of birth for a user. * @param db contains the database connection. * @param personId contains the person identifier from the central person registry. * @return will return an array of DateOfBirthReturn objects if successful. */// www. jav a2s . co m public DateOfBirthReturn[] getDateOfBirthForPersonId(final Database db, long personId) { final List<DateOfBirthReturn> results = new ArrayList<DateOfBirthReturn>(); final Session session = db.getSession(); final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append("SELECT dob_char, "); sb.append("start_date, "); sb.append("end_date, "); sb.append("last_update_by, "); sb.append("last_update_on, "); sb.append("created_by, "); sb.append("created_on "); sb.append("FROM {h-schema}date_of_birth "); sb.append("WHERE person_id = :person_id_in "); // If we are not returning all records, we need to just return the active ones. if (!isReturnHistoryFlag()) { sb.append("AND end_date IS NULL "); } sb.append("ORDER BY start_date ASC "); final SQLQuery query = session.createSQLQuery(sb.toString()); query.setParameter("person_id_in", personId); query.addScalar("dob_char", StandardBasicTypes.STRING); query.addScalar("start_date", StandardBasicTypes.TIMESTAMP); query.addScalar("end_date", StandardBasicTypes.TIMESTAMP); query.addScalar("last_update_by", StandardBasicTypes.STRING); query.addScalar("last_update_on", StandardBasicTypes.TIMESTAMP); query.addScalar("created_by", StandardBasicTypes.STRING); query.addScalar("created_on", StandardBasicTypes.TIMESTAMP); for (final Iterator<?> it = query.list().iterator(); it.hasNext();) { Object[] res = (Object[]) it.next(); String dobChar = (String) res[DOB_CHAR]; if (dobChar != null && dobChar.length() == MMDDYYYY_SIZE) { final String month = dobChar.substring(MONTH_START_POSITION, MONTH_END_POSITION); final String day = dobChar.substring(DAY_START_POSITION, DAY_END_POSITION); final String year = dobChar.substring(YEAR_START_POSITION); // Only month and day of DOB was specified. if (year.equals(EMPTY_YEAR_STRING)) { results.add(new DateOfBirthReturn(month + "/" + day, Utility.formatDateToISO8601((Date) res[START_DATE]), Utility.formatDateToISO8601((Date) res[END_DATE]), (String) res[LAST_UPDATE_BY], Utility.formatDateToISO8601((Date) res[LAST_UPDATE_ON]), (String) res[CREATED_BY], Utility.formatDateToISO8601((Date) res[CREATED_ON]))); } // Full date was specified. else { results.add(new DateOfBirthReturn(month + "/" + day + "/" + year, Utility.formatDateToISO8601((Date) res[START_DATE]), Utility.formatDateToISO8601((Date) res[END_DATE]), (String) res[LAST_UPDATE_BY], Utility.formatDateToISO8601((Date) res[LAST_UPDATE_ON]), (String) res[CREATED_BY], Utility.formatDateToISO8601((Date) res[CREATED_ON]))); } } } return results.toArray(new DateOfBirthReturn[results.size()]); }