List of usage examples for org.hibernate.type BlobType INSTANCE
BlobType INSTANCE
To view the source code for org.hibernate.type BlobType INSTANCE.
Click Source Link
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
public boolean setHibernateType(@Nullable SimpleValue value, com.manydesigns.portofino.model.database.Column column, Class javaType, final int jdbcType) { String typeName;//from w ww .j av a 2s .co m Properties typeParams = null; if (javaType == null) { return false; } if (javaType == Long.class) { typeName = LongType.INSTANCE.getName(); } else if (javaType == Short.class) { typeName = ShortType.INSTANCE.getName(); } else if (javaType == Integer.class) { typeName = IntegerType.INSTANCE.getName(); } else if (javaType == Byte.class) { typeName = ByteType.INSTANCE.getName(); } else if (javaType == Float.class) { typeName = FloatType.INSTANCE.getName(); } else if (javaType == Double.class) { typeName = DoubleType.INSTANCE.getName(); } else if (javaType == Character.class) { typeName = CharacterType.INSTANCE.getName(); } else if (javaType == String.class) { typeName = StringType.INSTANCE.getName(); } else if (java.util.Date.class.isAssignableFrom(javaType)) { switch (jdbcType) { case Types.DATE: typeName = DateType.INSTANCE.getName(); break; case Types.TIME: typeName = TimeType.INSTANCE.getName(); break; case Types.TIMESTAMP: typeName = TimestampType.INSTANCE.getName(); break; default: typeName = null; } } else if (javaType == Boolean.class) { if (jdbcType == Types.BIT || jdbcType == Types.BOOLEAN) { typeName = BooleanType.INSTANCE.getName(); } else if (jdbcType == Types.NUMERIC || jdbcType == Types.DECIMAL || jdbcType == Types.INTEGER || jdbcType == Types.SMALLINT || jdbcType == Types.TINYINT || jdbcType == Types.BIGINT) { typeName = NumericBooleanType.INSTANCE.getName(); } else if (jdbcType == Types.CHAR || jdbcType == Types.VARCHAR) { typeName = StringBooleanType.class.getName(); typeParams = new Properties(); typeParams.setProperty("true", trueString != null ? trueString : StringBooleanType.NULL); typeParams.setProperty("false", falseString != null ? falseString : StringBooleanType.NULL); typeParams.setProperty("sqlType", String.valueOf(jdbcType)); } else { typeName = null; } } else if (javaType == BigDecimal.class) { typeName = BigDecimalType.INSTANCE.getName(); } else if (javaType == BigInteger.class) { typeName = BigIntegerType.INSTANCE.getName(); } else if (javaType == byte[].class) { typeName = BlobType.INSTANCE.getName(); } else { typeName = null; } if (typeName == null) { logger.error("Unsupported type (java type: {}, jdbc type: {}) " + "for column '{}'.", new Object[] { javaType, jdbcType, column.getColumnName() }); return false; } if (value != null) { value.setTypeName(typeName); if (typeParams != null) { value.setTypeParameters(typeParams); } } return true; }
From source file:com.mercatis.lighthouse3.persistence.commons.hibernate.ValueObjectUserType.java
License:Apache License
public Type[] getPropertyTypes() { return new Type[] { BooleanType.INSTANCE, IntegerType.INSTANCE, LongType.INSTANCE, FloatType.INSTANCE, DoubleType.INSTANCE, TimestampType.INSTANCE, BlobType.INSTANCE, StringType.INSTANCE, ClobType.INSTANCE };/* w w w . j av a 2 s . c om*/ }
From source file:com.mercatis.lighthouse3.persistence.events.hibernate.EventRegistryImplementation.java
License:Apache License
/** * This method generates criteria for a given event template that also * contain an ordering clause on the date of occurrence. * /*from w w w . java 2 s . c o m*/ * @param session * the Hibernate session to use for criteria generation * @param entityTemplate * the template for which to generate the criteria * @param descending * <code>true</code> if descending order is wanted (the default) * or <code>false</code> for ascending order. * @return */ public Criteria generateOrderingCriteria(Session session, Event entityTemplate, boolean descending) { Criteria criteria = super.entityToCriteria(session, entityTemplate); if (entityTemplate.getContext() != null) { if (!Ranger.isEnumerationRange(entityTemplate.getContext())) criteria.add(Restrictions.eq("context", entityTemplate.getContext())); else criteria.add(Restrictions.in("context", Ranger.castToEnumerationRange(entityTemplate.getContext()).getEnumeration())); } if (entityTemplate.getCode() != null) { if (!Ranger.isEnumerationRange(entityTemplate.getCode())) criteria.add(Restrictions.eq("code", entityTemplate.getCode())); else criteria.add(Restrictions.in("code", Ranger.castToEnumerationRange(entityTemplate.getCode()).getEnumeration())); } if (entityTemplate.getLevel() != null) { if (!Ranger.isEnumerationRange(entityTemplate.getLevel())) criteria.add(Restrictions.eq("level", entityTemplate.getLevel())); else criteria.add(Restrictions.in("level", Ranger.castToEnumerationRange(entityTemplate.getLevel()).getEnumeration())); } if (entityTemplate.getMachineOfOrigin() != null) criteria.add(Restrictions.eq("machineOfOrigin", entityTemplate.getMachineOfOrigin())); if (entityTemplate.getMessage() != null) { criteria.add(Restrictions.ilike("message", "%" + entityTemplate.getMessage() + "%")); } if (entityTemplate.getStackTrace() != null) { if (this.unitOfWork.getSqlDialect() instanceof org.hibernate.dialect.MySQL5InnoDBDialect) criteria.add(Restrictions.sqlRestriction("match ({alias}.STACK_TRACE) against (?)", entityTemplate.getStackTrace(), StringType.INSTANCE)); else criteria.add(Restrictions.ilike("stackTrace", "%" + entityTemplate.getStackTrace() + "%")); } if (entityTemplate.getDateOfOccurrence() != null) { if (!Ranger.isIntervalRange(entityTemplate.getDateOfOccurrence())) { criteria.add(Restrictions.eq("dateOfOccurrence", entityTemplate.getDateOfOccurrence())); } else { Date lowerBound = Ranger.castToIntervalRange(entityTemplate.getDateOfOccurrence()).getLowerBound(); Date upperBound = Ranger.castToIntervalRange(entityTemplate.getDateOfOccurrence()).getUpperBound(); if ((lowerBound == null) && (upperBound != null)) criteria.add(Restrictions.le("dateOfOccurrence", upperBound)); else if ((lowerBound != null) && (upperBound == null)) criteria.add(Restrictions.ge("dateOfOccurrence", lowerBound)); else if ((lowerBound != null) && (upperBound != null)) { criteria.add(Restrictions.le("dateOfOccurrence", upperBound)); criteria.add(Restrictions.ge("dateOfOccurrence", lowerBound)); } } } if (!entityTemplate.getTransactionIds().isEmpty()) { Set<Criterion> transactionRestrictions = new HashSet<Criterion>(); for (String transactionId : entityTemplate.getTransactionIds()) transactionRestrictions.add(Restrictions.sqlRestriction( "exists (select lti.* from EVENT_TRANSACTION_IDS lti where {alias}.EVT_ID = lti.EVT_ID and lti.TRANSACTION_ID = ?)", transactionId, StringType.INSTANCE)); if (transactionRestrictions.size() == 1) { criteria.add(transactionRestrictions.iterator().next()); } else { Iterator<Criterion> restrictions = transactionRestrictions.iterator(); Criterion orCriterion = restrictions.next(); while (restrictions.hasNext()) { orCriterion = Restrictions.or(orCriterion, restrictions.next()); } criteria.add(orCriterion); } } for (String tag : entityTemplate.getTags()) criteria.add(Restrictions.sqlRestriction( "exists (select lt.* from EVENT_TAGS lt where {alias}.EVT_ID = lt.EVT_ID and lt.TAG = ?)", tag, StringType.INSTANCE)); for (String udf : entityTemplate.getUdfs().keySet()) { Object value = entityTemplate.getUdf(udf); if (udf.equals("eventRESTResourceLimitRestriction")) { criteria.setMaxResults((Integer) value); break; } String columnName = ""; Type valueType = StringType.INSTANCE; if (value instanceof Boolean) { columnName = "BOOLEAN_VAL"; valueType = BooleanType.INSTANCE; } if (value instanceof Integer) { columnName = "INTEGER_VAL"; valueType = IntegerType.INSTANCE; } if (value instanceof Long) { columnName = "LONG_VAL"; valueType = LongType.INSTANCE; } if (value instanceof Float) { columnName = "FLOAT_VAL"; valueType = FloatType.INSTANCE; } if (value instanceof Double) { columnName = "DOUBLE_VAL"; valueType = DoubleType.INSTANCE; } if (value instanceof Date) { columnName = "DATE_VAL"; valueType = DateType.INSTANCE; } if (value instanceof byte[]) { columnName = "BINARY_VAL"; valueType = BlobType.INSTANCE; } if (value instanceof String) { columnName = "STRING_VAL"; valueType = StringType.INSTANCE; } criteria.add(Restrictions.sqlRestriction( "exists (select lu.* from EVENT_UDFS lu where {alias}.EVT_ID = lu.EVT_ID and lu.UDF = ? and lu." + columnName + " = ?)", new Object[] { udf, value }, new Type[] { StringType.INSTANCE, valueType })); } if (descending) criteria.addOrder(Order.desc("dateOfOccurrence")); else criteria.addOrder(Order.asc("dateOfOccurrence")); return criteria; }