public Object convertDataValueToObjectValue(Object dataValue, Session session) { if ("".equals(dataValue)) { return Boolean.TRUE; } return session.getDatasourcePlatform().getConversionManager().convertObject(dataValue, Boolean.class); }
public void initialize(DatabaseMapping mapping, Session session) { this.conversionManager = (XMLConversionManager) session.getDatasourcePlatform().getConversionManager(); this.mapping = (XMLCompositeDirectCollectionMapping) mapping; try { if (getObjectClassName() != null) { ClassLoader loader = session.getDatasourcePlatform().getConversionManager().getLoader(); Class aClass = AccessController.doPrivileged(new PrivilegedClassForName(getObjectClassName(), true, loader)); setObjectClass(aClass); } } catch (PrivilegedActionException pae) { throw ValidationException.classNotFoundWhileConvertingClassNames(getObjectClassName(), pae.getException()); } }
public void initialize(DatabaseMapping mapping, Session session) { this.conversionManager = (XMLConversionManager) session.getDatasourcePlatform().getConversionManager(); this.mapping = (XMLCompositeDirectCollectionMapping) mapping; try { if (getObjectClassName() != null) { ClassLoader loader = session.getDatasourcePlatform().getConversionManager().getLoader(); Class aClass = (Class) AccessController.doPrivileged(new PrivilegedClassForName(getObjectClassName(), true, loader)); setObjectClass(aClass); } } catch (PrivilegedActionException pae) { throw ValidationException.classNotFoundWhileConvertingClassNames(getObjectClassName(), pae.getException()); } }
public void initialize(DatabaseMapping mapping, Session session) { this.conversionManager = (XMLConversionManager) session.getDatasourcePlatform().getConversionManager(); this.mapping = (XMLCompositeDirectCollectionMapping) mapping; try { if (getObjectClassName() != null) { ClassLoader loader = session.getDatasourcePlatform().getConversionManager().getLoader(); Class aClass = AccessController.doPrivileged(new PrivilegedClassForName(getObjectClassName(), true, loader)); setObjectClass(aClass); } } catch (PrivilegedActionException pae) { throw ValidationException.classNotFoundWhileConvertingClassNames(getObjectClassName(), pae.getException()); } }
/** * INTERNAL: * Allows for subclasses to convert the attribute value. */ public Object getAttributeValue(Object fieldValue, Session session) { // PERF: Direct variable access. Object attributeValue = fieldValue; if ((fieldValue == null) && (this.nullValue != null)) {// Translate default null value return this.nullValue; } // Allow for user defined conversion to the object value. if (this.converter != null) { attributeValue = this.converter.convertDataValueToObjectValue(attributeValue, session); } else { // PERF: Avoid conversion check when not required. if ((attributeValue == null) || (attributeValue.getClass() != this.attributeObjectClassification)) { try { attributeValue = session.getDatasourcePlatform().convertObject(attributeValue, this.attributeClassification); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } } } if (attributeValue == null) {// Translate default null value, conversion may have produced null. attributeValue = this.nullValue; } return attributeValue; }
/** * INTERNAL: * Allows for subclasses to convert the attribute value. */ public Object getObjectValue(Object fieldValue, Session session) { // PERF: Direct variable access. Object attributeValue = fieldValue; if ((fieldValue == null) && (this.nullValue != null)) {// Translate default null value return this.nullValue; } // Allow for user defined conversion to the object value. if (this.converter != null) { attributeValue = this.converter.convertDataValueToObjectValue(attributeValue, session); } else { // PERF: Avoid conversion check when not required. if ((attributeValue == null) || (attributeValue.getClass() != this.attributeObjectClassification)) { if ((attributeValue != null) || !this.bypassDefaultNullValueCheck) { try { attributeValue = session.getDatasourcePlatform().convertObject(attributeValue, this.attributeClassification); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } } } } if (attributeValue == null) {// Translate default null value, conversion may have produced null. attributeValue = this.nullValue; } return attributeValue; }
/** * INTERNAL: * Convert the SQL string into a DatabaseQuery. */ public DatabaseQuery processSQLQuery(Session session){ DatabaseQuery query = null; ClassLoader loader = session.getDatasourcePlatform().getConversionManager().getLoader(); if (resultClassName != null) { Class clazz = session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(resultClassName); query = EJBQueryImpl.buildSQLDatabaseQuery(clazz, sqlString, hints, loader, (AbstractSession)session); } else if (resultSetMappingNames != null) { query = EJBQueryImpl.buildSQLDatabaseQuery(resultSetMappingNames.get(0), sqlString, hints, loader, (AbstractSession)session); } else { // Neither a resultClass or resultSetMapping is specified so place in a temp query on the session query = EJBQueryImpl.buildSQLDatabaseQuery(sqlString, hints, loader, (AbstractSession)session); } query.setName(this.getName()); return query; }
/** * INTERNAL: * Allows for subclasses to convert the attribute value. */ public Object getObjectValue(Object fieldValue, Session session) { // PERF: Direct variable access. Object attributeValue = fieldValue; if ((fieldValue == null) && (this.nullValue != null)) {// Translate default null value return this.nullValue; } // Allow for user defined conversion to the object value. if (this.converter != null) { attributeValue = this.converter.convertDataValueToObjectValue(attributeValue, session); } else { // PERF: Avoid conversion check when not required. if ((attributeValue == null) || (attributeValue.getClass() != this.attributeObjectClassification)) { if ((attributeValue != null) || !this.bypassDefaultNullValueCheck) { try { attributeValue = session.getDatasourcePlatform().convertObject(attributeValue, this.attributeClassification); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } } } } if (attributeValue == null) {// Translate default null value, conversion may have produced null. attributeValue = this.nullValue; } return attributeValue; }
public Object convertDataValueToObjectValue(Object dataValue, Session session) { QName name = new QName(rootFragment.getNamespaceURI(), rootFragment.getLocalName()); if(mapping.isAbstractDirectMapping() && null == nestedConverter){ if ((dataValue == null) || (dataValue.getClass() != mapping.getAttributeClassification())) { try { dataValue = session.getDatasourcePlatform().convertObject(dataValue, mapping.getAttributeClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, mapping.getDescriptor(), e); } } } if(null != nestedConverter) { dataValue = nestedConverter.convertDataValueToObjectValue(dataValue, session); } if(dataValue instanceof JAXBElement) { return dataValue; } if(null == declaredType) { return new JAXBElement(name, Object.class, scope, dataValue); } else { return new JAXBElement(name, declaredType, scope, dataValue); } }
public Object convertDataValueToObjectValue(Object dataValue, Session session) { QName name = new QName(rootFragment.getNamespaceURI(), rootFragment.getLocalName()); if(mapping.isAbstractDirectMapping() && null == nestedConverter){ if ((dataValue == null) || (dataValue.getClass() != mapping.getAttributeClassification())) { try { dataValue = session.getDatasourcePlatform().convertObject(dataValue, mapping.getAttributeClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, mapping.getDescriptor(), e); } } } if(null != nestedConverter) { dataValue = nestedConverter.convertDataValueToObjectValue(dataValue, session); } if(dataValue instanceof JAXBElement) { return dataValue; } if(null == declaredType) { return new JAXBElement(name, Object.class, scope, dataValue); } else { return new JAXBElement(name, declaredType, scope, dataValue); } }
@Override public void customize(final Session session) throws Exception { if (JPAThreadContext.infos.containsKey("properties")) { final String prefix = ((Properties) JPAThreadContext.infos.get("properties")).getProperty("openejb.jpa.table_prefix"); final List<DatabaseTable> tables = new ArrayList<DatabaseTable>(); for (final ClassDescriptor cd : session.getDescriptors().values()) { for (final DatabaseTable table : cd.getTables()) { update(prefix, tables, table); } for (final DatabaseMapping mapping : cd.getMappings()) { if (mapping instanceof ManyToManyMapping) { update(prefix, tables, ((ManyToManyMapping) mapping).getRelationTable()); } else if (mapping instanceof DirectCollectionMapping) { update(prefix, tables, ((DirectCollectionMapping) mapping).getReferenceTable()); } // TODO: else check we need to update something } } final Sequence sequence = session.getDatasourcePlatform().getDefaultSequence(); if (sequence instanceof TableSequence) { final TableSequence ts = ((TableSequence) sequence); ts.setName(prefix + ts.getName()); } } }
/** * INTERNAL: * Set the enum class. */ public void initialize(DatabaseMapping mapping, Session session) { if (getEnumClass() == null) { if (getEnumClassName() == null) { throw XMLMarshalException.enumClassNotSpecified(); } else { try { enumClass = session.getDatasourcePlatform().getConversionManager().getLoader().loadClass(enumClassName); } catch (Exception e) { throw XMLMarshalException.invalidEnumClassSpecified(e, enumClassName); } } } try { fromStringMethod = PrivilegedAccessHelper.getMethod(enumClass, "fromString", new Class[] { String.class },true); } catch (Exception ex) { throw XMLMarshalException.errorInvokingFromStringMethod(ex, enumClass.getName()); } }
if (!this.bypassDefaultNullValueCheck) { try { attributeValue = session.getDatasourcePlatform().convertObject(null, this.attributeClassification); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e);
/** * INTERNAL: * Set the enum class. */ @Override public void initialize(DatabaseMapping mapping, Session session) { if (getEnumClass() == null) { if (getEnumClassName() == null) { throw XMLMarshalException.enumClassNotSpecified(); } else { try { enumClass = session.getDatasourcePlatform().getConversionManager().getLoader().loadClass(enumClassName); } catch (Exception e) { throw XMLMarshalException.invalidEnumClassSpecified(e, enumClassName); } } } try { fromStringMethod = PrivilegedAccessHelper.getMethod(enumClass, "fromString", new Class[] { String.class },true); } catch (Exception ex) { throw XMLMarshalException.errorInvokingFromStringMethod(ex, enumClass.getName()); } }
/** * INTERNAL: * Convert the JPA query into a DatabaseQuery. */ public DatabaseQuery processJPQLQuery(Session session){ ClassLoader classloader = session.getDatasourcePlatform().getConversionManager().getLoader(); LockModeType lockModeEnum = null; // Must handle errors if a JPA 2.0 option is used in JPA 1.0. try { lockModeEnum = LockModeType.valueOf(lockMode); } catch (Exception ignore) { // Ignore JPA 2.0 in JPA 1.0, reverts to no lock. } DatabaseQuery ejbquery = EJBQueryImpl.buildEJBQLDatabaseQuery(getName(), jpqlString, (AbstractSession) session, lockModeEnum, hints, classloader); ejbquery.setName(getName()); return ejbquery; }
public Object convertDataValueToObjectValue(Object dataValue, Session session) { XMLRoot root = new XMLRoot(); root.setLocalName(this.rootFragment.getLocalName()); root.setNamespaceURI(this.rootFragment.getNamespaceURI()); if(mapping.isAbstractDirectMapping()){ if ((dataValue == null) || (dataValue.getClass() != mapping.getAttributeClassification())) { try { dataValue = session.getDatasourcePlatform().convertObject(dataValue, mapping.getAttributeClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, mapping.getDescriptor(), e); } } } root.setObject(dataValue); return root; }
public Object convertDataValueToObjectValue(Object dataValue, Session session) { XMLRoot root = new XMLRoot(); root.setLocalName(this.rootFragment.getLocalName()); root.setNamespaceURI(this.rootFragment.getNamespaceURI()); if(mapping.isAbstractDirectMapping()){ if ((dataValue == null) || (dataValue.getClass() != mapping.getAttributeClassification())) { try { dataValue = session.getDatasourcePlatform().convertObject(dataValue, mapping.getAttributeClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, mapping.getDescriptor(), e); } } } root.setObject(dataValue); return root; }
public Object convertDataValueToObjectValue(Object dataValue, Session session) { XMLRoot root = new XMLRoot(); root.setLocalName(this.rootFragment.getLocalName()); root.setNamespaceURI(this.rootFragment.getNamespaceURI()); if(mapping.isAbstractDirectMapping()){ if ((dataValue == null) || (dataValue.getClass() != mapping.getAttributeClassification())) { try { dataValue = session.getDatasourcePlatform().convertObject(dataValue, mapping.getAttributeClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, mapping.getDescriptor(), e); } } } root.setObject(dataValue); return root; }
public void initialize(DatabaseMapping mapping, Session session) { try { ConversionManager cMgr = session.getDatasourcePlatform().getConversionManager(); Class<? extends DomHandler> domHandlerClass = PrivilegedAccessHelper.getClassForName(domHandlerClassName, true, cMgr.getLoader()); Constructor cons = PrivilegedAccessHelper.getDeclaredConstructorFor(domHandlerClass, new Class[]{}, true); this.domHandler = (DomHandler)PrivilegedAccessHelper.invokeConstructor(cons, new Object[]{}); Method createUnmarshallerMethod = PrivilegedAccessHelper.getDeclaredMethod(domHandlerClass, "createUnmarshaller", new Class[]{ValidationEventHandler.class}); resultType = PrivilegedAccessHelper.getMethodReturnType(createUnmarshallerMethod); Method getElementMethod = PrivilegedAccessHelper.getDeclaredMethod(domHandlerClass, "getElement", new Class[]{resultType}); elementClass = PrivilegedAccessHelper.getMethodReturnType(getElementMethod); xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform(); } catch(Exception ex) { throw JAXBException.couldNotInitializeDomHandlerConverter(ex, domHandlerClassName, mapping.getAttributeName()); } }
public void initialize(DatabaseMapping mapping, Session session) { try { ConversionManager cMgr = session.getDatasourcePlatform().getConversionManager(); Class<? extends DomHandler> domHandlerClass = PrivilegedAccessHelper.getClassForName(domHandlerClassName, true, cMgr.getLoader()); Constructor cons = PrivilegedAccessHelper.getDeclaredConstructorFor(domHandlerClass, new Class[]{}, true); this.domHandler = (DomHandler)PrivilegedAccessHelper.invokeConstructor(cons, new Object[]{}); Method createUnmarshallerMethod = PrivilegedAccessHelper.getDeclaredMethod(domHandlerClass, "createUnmarshaller", new Class[]{ValidationEventHandler.class}); resultType = PrivilegedAccessHelper.getMethodReturnType(createUnmarshallerMethod); Method getElementMethod = PrivilegedAccessHelper.getDeclaredMethod(domHandlerClass, "getElement", new Class[]{resultType}); elementClass = PrivilegedAccessHelper.getMethodReturnType(getElementMethod); xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform(); } catch(Exception ex) { throw JAXBException.couldNotInitializeDomHandlerConverter(ex, domHandlerClassName, mapping.getAttributeName()); } }