Package org.jpox.store.mapped

Examples of org.jpox.store.mapped.DatastoreAdapter


            {
                return new NullLiteral(qs);
            }
            else
            {
                DatastoreAdapter dba = qs.getStoreManager().getDatastoreAdapter();                 
                JavaTypeMapping m = dba.getMapping(id.getClass(), qs.getStoreManager(), qs.getClassLoaderResolver());
                return new ObjectLiteral(qs,m,id);
            }
        }
        else if (ObjectExpression.class.isAssignableFrom(expr.getClass()))
        {
View Full Code Here


    {
        super(qs);
        this.mapping = mapping;
        this.value = new BigDecimal(value.toString());

        DatastoreAdapter dba = qs.getStoreManager().getDatastoreAdapter();
        st.appendParameter(dba.getMapping(Float.class, qs.getStoreManager(), qs.getClassLoaderResolver()), value);
    }
View Full Code Here

    {
        super(qs);
        this.mapping = mapping;
        this.value = new BigDecimal(value.toString());

        DatastoreAdapter dba = qs.getStoreManager().getDatastoreAdapter();
        st.appendParameter(dba.getMapping(Double.class, qs.getStoreManager(), qs.getClassLoaderResolver()), value);
    }
View Full Code Here

        super(qs);
        this.mapping = mapping;

        this.value = value;

        DatastoreAdapter dba = qs.getStoreManager().getDatastoreAdapter();
        mapping = dba.getMapping(Byte.class, qs.getStoreManager(), qs.getClassLoaderResolver());       
        st.appendParameter(mapping, value);
       
    }
View Full Code Here

            bExpr = expr.eq(new NullLiteral(qs));
        }
        else
        {
            MappedStoreManager storeMgr = qs.getStoreManager();
            DatastoreAdapter dba = storeMgr.getDatastoreAdapter();
            ClassLoaderResolver clr = qs.getClassLoaderResolver();
            if (value instanceof OID)
            {
                // Object is an OID
                JavaTypeMapping m = dba.getMapping(((OID)value).getKeyValue().getClass(), storeMgr, clr);
                ScalarExpression oidExpr =  m.newLiteral(qs,((OID)value).getKeyValue());
                bExpr = expr.expressionList.getExpression(0).eq(oidExpr);
            }
            else
            {
                ApiAdapter api = qs.getStoreManager().getApiAdapter();
                AbstractClassMetaData cmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(value.getClass(), clr);
                if (cmd == null)
                {
                    // if there is no metadata, we either have an SingleFieldIdentity, application identity, or any object
                    if (storeMgr.getApiAdapter().isSingleFieldIdentityClass(value.getClass().getName()))
                    {
                        // Object is SingleFieldIdentity
                        JavaTypeMapping m = dba.getMapping(api.getTargetClassForSingleFieldIdentity(value), storeMgr, clr);
                        ScalarExpression oidExpr =  m.newLiteral(qs, api.getTargetKeyForSingleFieldIdentity(value));
                        bExpr = expr.expressionList.getExpression(0).eq(oidExpr);
                    }
                    else
                    {
                        String pcClassName = storeMgr.getClassNameForObjectID(value, clr, null);
                        if (pcClassName != null)
                        {
                            // Object is an application identity
                            cmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(pcClassName, clr);
                            bExpr = eqApplicationIdentity(value, null, expr, null, storeMgr, clr);
                        }
                        else
                        {
                            // Value not PersistenceCapable nor an identity, so return nothing "(1 = 0)"
                            bExpr = new BooleanLiteral(qs, mapping, false).eq(new BooleanLiteral(qs, mapping, true));
                        }
                    }
                }
                else
                {
                    // Value is a PersistenceCapable
                    if (cmd.getIdentityType() == IdentityType.APPLICATION)
                    {
                        // Application identity
                        if (api.getIdForObject(value) != null)
                        {
                            // Persistent PC object (FCO)
                            // Cater for composite PKs and parts of PK being PC mappings, and recursion
                            JavaTypeMapping[] pkMappingsApp = new JavaTypeMapping[expr.expressionList.size()];
                            Object[] pkFieldValues = new Object[expr.expressionList.size()];
                            int position = 0;
                            for (int i=0;i<cmd.getNoOfPrimaryKeyMembers();i++)
                            {
                                AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(cmd.getPKMemberPositions()[i]);
                                Object fieldValue = getFieldValue(mmd, value);
                                JavaTypeMapping mapping = dba.getMapping(fieldValue.getClass(), storeMgr, clr);
                                if (mapping instanceof PersistenceCapableMapping)
                                {
                                    position = populatePrimaryKeyMappingsValuesForPCMapping(pkMappingsApp,
                                        pkFieldValues, position, (PersistenceCapableMapping)mapping,
                                        cmd, mmd, fieldValue, storeMgr, clr);
                                }
                                else
                                {
                                    pkMappingsApp[position] = mapping;
                                    pkFieldValues[position] = fieldValue;
                                    position++;
                                }
                            }

                            for (int i=0; i<expr.expressionList.size(); i++)
                            {
                                ScalarExpression source = expr.expressionList.getExpression(i);
                                ScalarExpression target = pkMappingsApp[i].newLiteral(qs, pkFieldValues[i]);
                                if (bExpr == null)
                                {
                                    bExpr = source.eq(target);
                                }
                                else
                                {
                                    bExpr = bExpr.and(source.eq(target));
                                }
                            }
                        }
                        else
                        {
                            // PC object with no id (embedded, or transient maybe)
                            for (int i=0; i<expr.expressionList.size(); i++)
                            {
                                // Query should return nothing (so just do "(1 = 0)")
                                JPOXLogger.QUERY.warn(LOCALISER.msg("037003", value));
                                bExpr = new BooleanLiteral(qs, mapping, false).eq(new BooleanLiteral(qs, mapping, true));
                                // It is arguable that we should compare the id with null (as below)
                                /*bExpr = expr.eq(new NullLiteral(qs));*/
                            }
                        }
                    }
                    else
                    {
                        // Datastore identity
                        for (int i=0; i<expr.expressionList.size(); i++)
                        {
                            ScalarExpression source = expr.expressionList.getExpression(i);
                            OID objectId = (OID)api.getIdForObject(value);
                            if (objectId == null)
                            {
                                // PC object with no id (embedded, or transient maybe)
                                // Query should return nothing (so just do "(1 = 0)")
                                JPOXLogger.QUERY.warn(LOCALISER.msg("037003", value));
                                bExpr = new BooleanLiteral(qs, mapping, false).eq(new BooleanLiteral(qs, mapping, true));
                                // It is arguable that we should compare the id with null (as below)
                                /*bExpr = expr.eq(new NullLiteral(qs));*/
                            }
                            else
                            {
                                JavaTypeMapping m = dba.getMapping(objectId.getKeyValue().getClass(), storeMgr, clr);
                                ScalarExpression oidExpr = m.newLiteral(qs, objectId.getKeyValue());
                                bExpr = source.eq(oidExpr);
                            }
                        }
                    }
View Full Code Here

        {
            if (fieldValue == null)
            {
                return new NullLiteral(this.qs);
            }
            DatastoreAdapter dba = qs.getStoreManager().getDatastoreAdapter();
            JavaTypeMapping mapping;
            if (mappingClass != null && subfieldName == null)
            {
                mapping = dba.getMapping(qs.getClassLoaderResolver().classForName(mappingClass), qs.getStoreManager(),
                    qs.getClassLoaderResolver());
            }
            else
            {
                mapping = dba.getMapping(fieldValue.getClass(), qs.getStoreManager(), qs.getClassLoaderResolver());               
            }
            return mapping.newLiteral(qs,fieldValue);
        }
        catch (SecurityException e)
        {
View Full Code Here

        // Escape any single-quotes
        st.append('\'').append(StringUtils.replaceAll(value, "'", "''")).append('\'');

        if (mapping==null)
        {
            DatastoreAdapter dba = qs.getStoreManager().getDatastoreAdapter();
            stUsingParameter.appendParameter(dba.getMapping(String.class, qs.getStoreManager(), qs.getClassLoaderResolver()), value);
        }
        else
        {
            stUsingParameter.appendParameter(mapping,value);
        }
View Full Code Here

    public BinaryLiteral(QueryExpression qs, JavaTypeMapping mapping, byte[] value)
    {
        super(qs);
        this.mapping = mapping;
        this.value = value;
        DatastoreAdapter dba = qs.getStoreManager().getDatastoreAdapter();
        st.appendParameter(dba.getMapping(byte[].class, qs.getStoreManager(), qs.getClassLoaderResolver()), value);
    }
View Full Code Here

        this.value = literal;
        if (value == null || !value.getClass().isArray())
        {
            throw new JPOXUserException("Invalid argument literal : " + value);
        }
        DatastoreAdapter dba = qs.getStoreManager().getDatastoreAdapter();
        this.exprs = new ScalarExpression[Array.getLength(value)];
        for( int i=0; i<Array.getLength(value); i++ )
        {
            JavaTypeMapping m = dba.getMapping(Array.get(value, i).getClass(), qs.getStoreManager(), qs.getClassLoaderResolver());
            this.exprs[i] = m.newLiteral(qs, Array.get(value, i));
        }
    }   
View Full Code Here

     * @throws SQLException Thrown if a DB error occurs.
     **/
    public DatastoreAdapter getDatastoreAdapter(ClassLoaderResolver clr, Connection conn, String adapterClassName, PluginManager pluginMgr)
        throws SQLException
    {
        DatastoreAdapter adapter = null;
        DatabaseMetaData metadata = conn.getMetaData();

        // Get a new adapter
        adapter = getNewDatastoreAdapter(clr, metadata, adapterClassName, pluginMgr);
        if (adapter == null)
View Full Code Here

TOP

Related Classes of org.jpox.store.mapped.DatastoreAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.