Package org.jpox.store.mapped

Examples of org.jpox.store.mapped.StatementExpressionIndex


                        else
                        {
                            // Any fields out of range for the class, we default or null.
                            // This happens when we insert a base class object
                            // and the sub-class is persisted to the same table ("superclass-table").
                            StatementExpressionIndex stmtExprIndex = statementExpressionIndex[insertFieldNumbers[i]];
                            stmtExprIndex.getMapping().setDefault(om, ps, stmtExprIndex.getParameterIndex());
                        }
                    }
                    sm.provideFields(classFieldNumbers, new ParameterSetter(sm, ps, statementExpressionIndex, true));

                    if (table.getVersionMapping(false) != null)
                    {
                        // Surrogate version - set the new version for the object
                        Object currentVersion = sm.getObjectManager().getApiAdapter().getVersion(sm);
                        Object nextOptimisticVersion = VersionMapping.getNextVersion(table.getVersionMetaData(),
                            currentVersion);
                        table.getVersionMapping(false).setObject(om, ps, versionStatementExpressionIndex.getParameterIndex(), nextOptimisticVersion);
                        sm.setTransactionalVersion(nextOptimisticVersion);
                    }
                    else if (vermd != null && vermd.getFieldName() != null)
                    {
                        // Version field - set the new version for the object
                        Object currentVersion = sm.getObjectManager().getApiAdapter().getVersion(sm);
                        Object nextOptimisticVersion = VersionMapping.getNextVersion(table.getVersionMetaData(),
                            currentVersion);
                        sm.setTransactionalVersion(nextOptimisticVersion);
                    }

                    // Discriminator mapping (optional)
                    if (table.getDiscriminatorMapping(false) != null)
                    {
                        DiscriminatorMetaData dismd = table.getDiscriminatorMetaData();
                        if (dismd.getStrategy() == DiscriminatorStrategy.CLASS_NAME)
                        {
                            table.getDiscriminatorMapping(false).setObject(om, ps, discriminatorStatementExpressionIndex.getParameterIndex(),
                                sm.getObject().getClass().getName());
                        }
                        else if (dismd.getStrategy() == DiscriminatorStrategy.VALUE_MAP)
                        {
                            // Use Discriminator info for the actual class
                            dismd = sm.getClassMetaData().getInheritanceMetaData().getDiscriminatorMetaData();
                            table.getDiscriminatorMapping(false).setObject(om, ps, discriminatorStatementExpressionIndex.getParameterIndex(), dismd.getValue());
                        }
                    }

                    // External FK columns (optional)
                    if (externalFKStatementExpressionIndex != null)
                    {
                        for (int i=0;i<externalFKStatementExpressionIndex.length;i++)
                        {
                            Object fkValue = sm.getValueForExternalField(externalFKStatementExpressionIndex[i].getMapping());
                            if (fkValue != null)
                            {
                                // Need to provide the owner field number so PCMapping can work out if it is inserted yet
                                AbstractMemberMetaData ownerFmd =
                                    table.getMetaDataForExternalMapping(externalFKStatementExpressionIndex[i].getMapping(),
                                        MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
                                externalFKStatementExpressionIndex[i].getMapping().setObject(om, ps,
                                    externalFKStatementExpressionIndex[i].getParameterIndex(), fkValue, null, ownerFmd.getAbsoluteFieldNumber());
                            }
                            else
                            {
                                // We're inserting a null so dont need the owner field
                                externalFKStatementExpressionIndex[i].getMapping().setObject(om, ps,
                                    externalFKStatementExpressionIndex[i].getParameterIndex(), null);
                            }
                        }
                    }

                    // External FK discriminator columns (optional)
                    if (externalFKDiscrimStatementExpressionIndex != null)
                    {
                        for (int i=0;i<externalFKDiscrimStatementExpressionIndex.length;i++)
                        {
                            Object discrimValue = sm.getValueForExternalField(externalFKDiscrimStatementExpressionIndex[i].getMapping());
                            externalFKDiscrimStatementExpressionIndex[i].getMapping().setObject(om, ps,
                                externalFKDiscrimStatementExpressionIndex[i].getParameterIndex(), discrimValue);
                        }
                    }

                    // External order columns (optional)
                    if (externalOrderStatementExpressionIndex != null)
                    {
                        for (int i=0;i<externalOrderStatementExpressionIndex.length;i++)
                        {
                            Object orderValue = sm.getValueForExternalField(externalOrderStatementExpressionIndex[i].getMapping());
                            if (orderValue == null)
                            {
                                // No order value so use -1
                                orderValue = new Integer(-1);
                            }
                            externalOrderStatementExpressionIndex[i].getMapping().setObject(om, ps,
                                externalOrderStatementExpressionIndex[i].getParameterIndex(), orderValue);
                        }
                    }

                    sqlControl.executeStatementUpdate(mconn, insertStmt, ps, !batch);

                    if (hasAutoIncrementColumn)
                    {
                        // Identity was set in the datastore using auto-increment/identity/serial etc
                        Object newId = getInsertedDatastoreIdentity(om, sqlControl, sm, mconn, ps);
                        if (JPOXLogger.DATASTORE_PERSIST.isDebugEnabled())
                        {
                            JPOXLogger.DATASTORE_PERSIST.debug(LOCALISER.msg("052206",
                                StringUtils.toJVMIDString(sm.getObject()), newId));
                        }
                        sm.setPostStoreNewObjectId(newId);
                    }

                    // Update the insert status for this table
                    sm.changeActivityState(ActivityState.INSERTING_CALLBACKS, table);

                    // Make sure all relation fields (1-1, N-1 with FK) we processed in the INSERT are attached.
                    // This is necessary because with a bidir relation and the other end attached we can just
                    // do the INSERT above first and THEN attach the other end here
                    // (if we did it the other way around we would get a NotYetFlushedException thrown above).
                    for (int i=0;i<relationFieldNumbers.length;i++)
                    {
                        Object value = sm.provideField(relationFieldNumbers[i]);
                        if (value != null && om.getApiAdapter().isDetached(value))
                        {
                            Object valueAttached = om.persistObjectInternal(value, null, null, -1, StateManager.PC);
                            sm.replaceField(relationFieldNumbers[i], valueAttached, false);
                        }
                    }

                    // Perform reachability on all fields that have no datastore column (1-1 bi non-owner, N-1 bi join)
                    int numberOfReachableFields = 0;
                    for (int i = 0; i < reachableFieldNumbers.length; i++)
                    {
                        if (reachableFieldNumbers[i] < sm.getHighestFieldNumber())
                        {
                            numberOfReachableFields++;
                        }
                    }
                    classFieldNumbers = new int[numberOfReachableFields];
                    j = 0;
                    for (int i = 0; i < reachableFieldNumbers.length; i++)
                    {
                        if (reachableFieldNumbers[i] < sm.getHighestFieldNumber())
                        {
                            classFieldNumbers[j++] = reachableFieldNumbers[i];
                        }
                        else
                        {
                            // Any fields out of range for the class, we default or null.
                            // This happens when we insert a base class object
                            // and the sub-class is persisted to the same table ("superclass-table").
                            StatementExpressionIndex stmtExprIndex = retrievedStatementExpressionIndex[reachableFieldNumbers[i]];
                            stmtExprIndex.getMapping().setDefault(om, ps, stmtExprIndex.getParameterIndex());
                        }
                    }
                    sm.provideFields(classFieldNumbers, new ParameterSetter(sm, ps, retrievedStatementExpressionIndex, true));
                }
                finally
View Full Code Here


            {
                if (m.getNumberOfDatastoreFields() == 0 &&
                    (m instanceof PersistenceCapableMapping || m instanceof ReferenceMapping))
                {
                    // Reachable Fields (that relate to this object but have no column in the table)
                    retrievedStatementExpressionIndex[fmd.getAbsoluteFieldNumber()] = new StatementExpressionIndex();
                    retrievedStatementExpressionIndex[fmd.getAbsoluteFieldNumber()].setMapping(m);
                    int relationType = fmd.getRelationType(clr);
                    if (relationType == Relation.ONE_TO_ONE_BI)
                    {
                        if (fmd.getMappedBy() != null)
                        {
                            // 1-1 Non-owner bidirectional field (no datastore columns)
                            reachableFields.add(new Integer(fmd.getAbsoluteFieldNumber()));
                        }
                    }
                    else if (relationType == Relation.MANY_TO_ONE_BI)
                    {
                        AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);
                        if (fmd.getJoinMetaData() != null || relatedMmds[0].getJoinMetaData() != null)
                        {
                            // N-1 bidirectional field using join (no datastore columns)
                            reachableFields.add(new Integer(fmd.getAbsoluteFieldNumber()));
                        }
                    }
                    // TODO What about 1-N non-owner
                }
                else
                {
                    // Fields to be "inserted" (that have a datastore column)

                    // Check if the field is "insertable" (either using JPA column, or JDO extension)
                    if (fmd.hasExtension("insertable") && fmd.getValueForExtension("insertable").equalsIgnoreCase("false"))
                    {
                        return;
                    }
                    ColumnMetaData[] colmds = fmd.getColumnMetaData();
                    if (colmds != null && colmds.length > 0)
                    {
                        for (int i=0;i<colmds.length;i++)
                        {
                            if (!colmds[i].getInsertable())
                            {
                                // Not to be inserted
                                return;
                            }
                        }
                    }
                    int relationType = fmd.getRelationType(clr);
                    if (relationType == Relation.ONE_TO_ONE_BI)
                    {
                        if (fmd.getMappedBy() == null)
                        {
                            // 1-1 Owner bidirectional field using FK (in this table)
                        }
                    }
                    else if (relationType == Relation.MANY_TO_ONE_BI)
                    {
                        AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);
                        if (fmd.getJoinMetaData() == null && relatedMmds[0].getJoinMetaData() == null)
                        {
                            // N-1 bidirectional field using FK (in this table)
                            relationFields.add(new Integer(fmd.getAbsoluteFieldNumber()));
                        }
                    }

                    statementExpressionIndex[fmd.getAbsoluteFieldNumber()] = new StatementExpressionIndex();
                    statementExpressionIndex[fmd.getAbsoluteFieldNumber()].setMapping(m);

                    // create the expressions index (columns index)
                    int parametersIndex[] = new int[m.getNumberOfDatastoreFields()];
                    for (int j = 0; j < parametersIndex.length; j++)
View Full Code Here

                        columnValues.append(',');
                    }
                    columnNames.append(((Column)table.getVersionMapping(false).getDataStoreMapping(0).getDatastoreField()).getIdentifier());
                    columnValues.append(val);

                    versionStatementExpressionIndex = new StatementExpressionIndex();
                    versionStatementExpressionIndex.setMapping(table.getVersionMapping(false));
                    int[] param = { paramIndex++ };
                    versionStatementExpressionIndex.setParameterIndex(param);
                }
                else
                {
                    versionStatementExpressionIndex = null;
                }
            }
            else if (mappingType == MappingConsumer.MAPPING_TYPE_DISCRIMINATOR)
            {
                // Surrogate discriminator column
                if (table.getDiscriminatorMapping(false) != null)
                {
                    String val = ((RDBMSMapping)table.getDiscriminatorMapping(false).getDataStoreMapping(0)).getUpdateInputParameter();

                    if (columnNames.length() > 0)
                    {
                        columnNames.append(',');
                        columnValues.append(',');
                    }
                    columnNames.append(((Column)table.getDiscriminatorMapping(false).getDataStoreMapping(0).getDatastoreField()).getIdentifier());
                    columnValues.append(val);
                    discriminatorStatementExpressionIndex = new StatementExpressionIndex();
                    discriminatorStatementExpressionIndex.setMapping(table.getDiscriminatorMapping(false));
                    int[] param = { paramIndex++ };
                    discriminatorStatementExpressionIndex.setParameterIndex(param);
                }
                else
View Full Code Here

                {
                    stmtExprIndex[i] = tmpStmtExprIndex[i];
                }
                pos = tmpStmtExprIndex.length;
            }
            stmtExprIndex[pos] = new StatementExpressionIndex();
            stmtExprIndex[pos].setMapping(mapping);
            int[] param = new int[mapping.getNumberOfDatastoreFields()];
            for (int i=0;i<mapping.getNumberOfDatastoreFields();i++)
            {
                if (columnNames.length() > 0)
View Full Code Here

TOP

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

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.