Package org.jpox

Examples of org.jpox.ObjectManager


        }

        String addStmt = getAddStmt();
        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                // Shift any existing elements so that we can insert the new element(s) at their position
View Full Code Here


        Object o = get(sm, index);

        String setStmt = getSetStmt();
        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, setStmt, false);
View Full Code Here

            }
        }
        else
        {
            // Ordered List - just remove the list item since no indexing present
            ObjectManager om = ownerSM.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            try
            {
                int[] rcs = internalRemove(ownerSM, mconn, false, element, true);
                if (rcs != null)
View Full Code Here

        // Remove the specified elements from the join table
        String removeAllStmt = getRemoveAllStmt(elements);
        SQLController sqlControl = storeMgr.getSQLController();
        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            try
            {
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, removeAllStmt, false);
                try
                {
                    int jdbcPosition = 1;
                    Iterator iter = elements.iterator();
                    while (iter.hasNext())
                    {
                        Object element = iter.next();
                        jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                        jdbcPosition = populateElementInStatement(om, ps, element, jdbcPosition);
                        if (relationDiscriminatorMapping != null)
                        {
                            jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
                        }
                    }

                    int[] number = sqlControl.executeStatementUpdate(mconn, removeAllStmt, ps, true);
                    if (number[0] > 0)
                    {
                        modified = true;
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
            }
        }
        catch (SQLException e)
        {
            JPOXLogger.DATASTORE.error(e);
            throw new JPOXDataStoreException(LOCALISER.msg("056012", removeAllStmt), e);
        }

        try
        {
            // Shift the remaining indices to remove the holes in ordering
            boolean batched = allowsBatching();

            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            try
            {
                for (int i=0;i<currentListSize;i++)
                {
View Full Code Here

        String compiledSQL = ((AbstractSQLQuery)query).getInputSQL();

        if (candidateClass != null && query.getType() == Query.SELECT)
        {
            // Perform any sanity checking of input for SELECT queries
            ObjectManager om = query.getObjectManager();
            MappedStoreManager storeMgr = (MappedStoreManager)om.getStoreManager();
            ClassLoaderResolver clr = om.getClassLoaderResolver();
            AbstractClassMetaData cmd = om.getMetaDataManager().getMetaDataForClass(candidateClass, clr);
            if (cmd == null)
            {
                throw new ClassNotPersistenceCapableException(candidateClass.getName());
            }
            if (cmd.getPersistenceCapableSuperclass() != null)
            {
               // throw new PersistentSuperclassNotAllowedException(candidateClass.getName());
            }

            if (query.getResultClass() == null)
            {
                // Check the presence of the required columns (id, version, discriminator) in the candidate class
                String selections = compiledSQL.trim().substring(7); // Skip "SELECT "
                int fromStart = selections.indexOf("FROM");
                if (fromStart == -1)
                {
                    fromStart = selections.indexOf("from");
                }
                selections = selections.substring(0, fromStart).trim();
                String[] selectedColumns = StringUtils.split(selections, ",");

                if (selectedColumns == null || selectedColumns.length == 0)
                {
                    throw new JPOXUserException(LOCALISER_RDBMS.msg("059003", compiledSQL));
                }
                if (selectedColumns.length == 1 && selectedColumns[0].trim().equals("*"))
                {
                    // SQL Query using * so just return since all possible columns will be selected
                    return compiledSQL;
                }

                // Generate id column field information for later checking the id is present
                DatastoreClass table = storeMgr.getDatastoreClass(candidateClass.getName(), clr);
                PersistenceCapableMapping idMapping = (PersistenceCapableMapping)table.getIDMapping();
                String[] idColNames = new String[idMapping.getNumberOfDatastoreFields()];
                boolean[] idColMissing = new boolean[idMapping.getNumberOfDatastoreFields()];
                for (int i=0;i<idMapping.getNumberOfDatastoreFields();i++)
                {
                    DatastoreMapping m = idMapping.getDataStoreMapping(i);
                    idColNames[i] = m.getDatastoreField().getIdentifier().toString();
                    idColMissing[i] = true;
                }

                // Generate discriminator/version information for later checking they are present
                String discriminatorColName = table.getDiscriminatorMapping(false) != null ?
                        table.getDiscriminatorMapping(false).getDataStoreMapping(0).getDatastoreField().getIdentifier().toString() : null;
                String versionColName = table.getVersionMapping(false) != null ?
                        table.getVersionMapping(false).getDataStoreMapping(0).getDatastoreField().getIdentifier().toString() : null;
                boolean discrimMissing = (discriminatorColName != null);
                boolean versionMissing = true;
                if (versionColName == null)
                {
                    versionMissing = false;
                }

                // Go through the selected fields and check the existence of id, version, discriminator cols
                DatastoreAdapter dba = storeMgr.getDatastoreAdapter();
                final AbstractClassMetaData candidateCmd = om.getMetaDataManager().getMetaDataForClass(candidateClass, clr);
                for (int i = 0; i < selectedColumns.length; i++)
                {
                    String colName = selectedColumns[i].trim();
                    if (colName.indexOf(" AS ") > 0)
                    {
View Full Code Here

     * @param table Join table where the objects are stored
     * @return The state manager
     */
    protected StateManager getStateManagerForEmbeddedPCObject(StateManager sm, Object obj, JoinTable table)
    {
        ObjectManager om = sm.getObjectManager();
        StateManager objSM = om.findStateManager(obj);
        if (objSM == null)
        {
            objSM = StateManagerFactory.newStateManagerForEmbedded(om, obj, false);

            AbstractMemberMetaData ownerFmd = table.getOwnerFieldMetaData();
View Full Code Here

     */
    public void execute(StateManager sm)
    {
        // Choose the statement based on whether optimistic or not
        String stmt = null;
        ObjectManager om = sm.getObjectManager();
        boolean optimisticChecks = (versionMetaData != null && om.getTransaction().getOptimistic() && versionChecks);
        if (optimisticChecks)
        {
            stmt = updateStmtOptimistic;
        }
        else
        {
            stmt = updateStmt;
        }

        if (stmt != null)
        {
            if (JPOXLogger.PERSISTENCE.isDebugEnabled())
            {
                // Debug info about fields being updated
                StringBuffer fieldStr = new StringBuffer();
                for (int i=0;i<updateFieldNumbers.length;i++)
                {
                    if (fieldStr.length() > 0)
                    {
                        fieldStr.append(",");
                    }
                    fieldStr.append(cmd.getMetaDataForManagedMemberAtAbsolutePosition(updateFieldNumbers[i]).getName());
                }

                if (versionMetaData != null && versionMetaData.getFieldName() == null)
                {
                    if (fieldStr.length() > 0)
                    {
                        fieldStr.append(",");
                    }
                    fieldStr.append("[VERSION]");
                }

                // Debug information about what we are updating
                JPOXLogger.PERSISTENCE.debug(LOCALISER.msg("052214",
                    StringUtils.toJVMIDString(sm.getObject()), fieldStr.toString(), table));
            }

            RDBMSManager storeMgr = (RDBMSManager)om.getStoreManager();

            boolean batch = false;
            // TODO Set the batch flag based on whether we have no other SQL being invoked in here just our UPDATE
            try
            {
View Full Code Here

        switch (type)
        {
            case COMPILE_EXPLICIT_PARAMETERS :
            {
                compileExplicitParameters();
                ObjectManager om = query.getObjectManager();
                if (query.getExplicitParameters() != null && query.getExplicitParameters().length() > 0)
                {
                    // Using explicit parameters
                    explicitParameters = true;
                    if (parameters != null)
                    {
                        ApiAdapter api = om.getApiAdapter();
                        if (parameters.size() != parameterTypesByName.size())
                        {
                            // Number of explicit parameters doesn't match the number of parameter values
                            throw new JPOXQueryInvalidParametersException(LOCALISER.msg("021025",
                                "" + parameterTypesByName.size(), "" + parameters.size()));
                        }

                        for (Iterator it = parameterTypesByName.entrySet().iterator(); it.hasNext(); )
                        {
                            Map.Entry entry = (Entry) it.next();
                            Object key = entry.getKey();
                            Object value = parameters.get(key);
                            if (value == null)
                            {
                                // primitive parameter can't be null
                                if (((Class)entry.getValue()).isPrimitive())
                                {
                                    throw new JPOXQueryInvalidParametersException(LOCALISER.msg("021026",
                                        entry.getKey(), ((Class)entry.getValue()).getName()));
                                }
                            }
                            else
                            {
                                if (api.isPersistable(value))
                                {
                                    // parameters bound to a different PM can't be used with this PM
                                    ObjectManager valueOM = ObjectManagerHelper.getObjectManager(value);
                                    if (valueOM != null && om != valueOM)
                                    {
                                        throw new JPOXUserException(LOCALISER.msg("021068", key));
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Using implicit parameters
                    // TODO Need to check the number of implicit params in the query (only do-able after compiling)
                    if (parameters != null)
                    {
                        ApiAdapter api = om.getApiAdapter();
                        Iterator parameterEntryIter = parameters.entrySet().iterator();
                        while (parameterEntryIter.hasNext())
                        {
                            Map.Entry entry = (Map.Entry)parameterEntryIter.next();
                            Object value = entry.getValue();
                            if (api.isPersistable(value))
                            {
                                // parameters bound to a different PM can't be used with this PM
                                ObjectManager valueOM = ObjectManagerHelper.getObjectManager(value);
                                if (valueOM != null && om != valueOM)
                                {
                                    // TODO Really should put the param name in here, but we don't know it
                                    throw new JPOXUserException(LOCALISER.msg("021068", value));
                                }
View Full Code Here

     * Convenience method to process the candidates for this query.
     * Processes the "candidateClassName" and "candidateClass" and sets up "candidates".
     */
    protected void compileCandidates()
    {
        ObjectManager om = query.getObjectManager();

        if (parentExpr != null)
        {
            // Subquery, so cater for different ways of specifying the candidate class
            if (subqueryCandidateExpr != null)
            {
                // Query being treated as a subquery for this compilation
                if (query.getCandidateClassName() == null)
                {
                    // No candidate class specified for subquery somehow, so derive from candidate-expression
                    Class candCls = getClassForSubqueryCandidateExpression();
                    query.setCandidateClassName(candCls.getName());
                }
            }
            else
            {
                // Single-string subquery
                String from = query.getFrom();
                if (from != null)
                {
                    if (from.indexOf(' ') > 0)
                    {
                        // "<candidate-expression> alias"
                        String candidateExpr = from.substring(0, from.indexOf(' ')).trim();
                        if (candidateExpr.startsWith("this"))
                        {
                            // <candidate-expression> is an expression for joining to the parent query
                            subqueryCandidateExpr = candidateExpr.trim();
                            Class cls = getClassForSubqueryCandidateExpression();
                            query.setCandidateClassName(cls.getName());
                        }
                        else
                        {
                            // <candidate-expression> is a class
                            query.setCandidateClassName(candidateExpr);
                        }
                        this.candidateAlias = from.substring(from.indexOf(' ')+1).trim();
                        this.subqueryAliasSet = true;
                    }
                    else
                    {
                        if (from.startsWith("this"))
                        {
                            // <candidate-expression> is an expression for joining to the parent query
                            subqueryCandidateExpr = from.trim();
                            Class cls = getClassForSubqueryCandidateExpression();
                            query.setCandidateClassName(cls.getName());
                        }
                        else
                        {
                            // <candidate-expression> is a class
                            query.setCandidateClassName(from);
                        }
                    }
                }
            }
            if (this.candidateAlias.equals("this"))
            {
                // Cant use "this" in subquery so replace with something else
                this.candidateAlias = "SUB"; // TODO Parameterise this as a config option
            }
        }

        // Check the candidate class existence
        String candidateClassName = query.getCandidateClassName();
        if (candidateClass == null && candidateClassName != null)
        {
            try
            {
                candidateClass = om.getClassLoaderResolver().classForName(candidateClassName, true);
            }
            catch (JPOXException jpe)
            {
                candidateClass = query.resolveClassDeclaration(candidateClassName);
            }
        }

        // Set the "candidates"
        Extent candidateExtent = ((AbstractJavaQuery)query).getCandidateExtent();
        Collection candidateCollection = ((AbstractJavaQuery)query).getCandidateCollection();
        if (candidateExtent != null)
        {
            candidates = (Queryable)candidateExtent;
        }
        else if (candidateCollection != null)
        {
            candidates = new CollectionCandidates(om, candidateClass, candidateCollection);
        }
        else
        {
            if (candidateClass == null)
            {
                throw new JPOXUserException(LOCALISER.msg("042001"));
            }
            candidates = (Queryable)om.getExtent(candidateClass, query.isSubclasses());
        }

        String result = query.getResult();
        if (result != null)
        {
View Full Code Here

            stmt = expr.toStatementText(false).toString();
        }

        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, stmt);
View Full Code Here

TOP

Related Classes of org.jpox.ObjectManager

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.