Package org.datanucleus.store.mapped

Examples of org.datanucleus.store.mapped.DatastoreContainerObject


                if (coll == null || coll.isEmpty())
                {
                    return;
                }

                DatastoreContainerObject joinTbl = ((RDBMSStoreManager)ec.getStoreManager()).getDatastoreContainerObject(mmd);
                CollectionTable collTbl = (CollectionTable)joinTbl;
                JavaTypeMapping elemMapping = collTbl.getElementMapping();
                if (elemMapping instanceof InterfaceMapping)
                {
                    InterfaceMapping intfMapping = (InterfaceMapping)elemMapping;
View Full Code Here


            String elementType = ownerMmd.getArray().getElementType();
            RDBMSStoreManager storeMgr = stmt.getRDBMSManager();

            // TODO Allow for interface elements, etc
            JavaTypeMapping ownerMapping = null;
            DatastoreContainerObject arrayTbl = null;
            if (ownerMmd.getMappedBy() != null)
            {
                // Bidirectional
                AbstractMemberMetaData elementMmd = ownerMmd.getRelatedMemberMetaData(clr)[0];
                if (ownerMmd.getJoinMetaData() != null || elementMmd.getJoinMetaData() != null)
                {
                    // JoinTable
                    arrayTbl = storeMgr.getDatastoreContainerObject(ownerMmd);
                    ownerMapping = ((JoinTable)arrayTbl).getOwnerMapping();
                }
                else
                {
                    // ForeignKey
                    arrayTbl = storeMgr.getDatastoreClass(elementType, clr);
                    ownerMapping = arrayTbl.getMemberMapping(elementMmd);
                }
            }
            else
            {
                // Unidirectional
View Full Code Here

        ExecutionContext ec = sm.getExecutionContext();
        ArrayList results = new ArrayList();
        if (resultSet != null)
        {
            DatastoreContainerObject containerTable = als.getContainerTable();
            boolean elementsAreSerialised = als.isElementsAreSerialised();
            boolean elementsAreEmbedded = als.isElementsAreEmbedded();
            JavaTypeMapping elementMapping = als.getElementMapping();
            while (next(resultSet))
            {
View Full Code Here

            AbstractMemberMetaData ownerMmd = expr.getJavaTypeMapping().getMemberMetaData();
            RDBMSStoreManager storeMgr = stmt.getRDBMSManager();

            // TODO Allow for interface keys/values, etc
            JavaTypeMapping ownerMapping = null;
            DatastoreContainerObject mapTbl = null;
            if (ownerMmd.getMap().getMapType() == MapType.MAP_TYPE_JOIN)
            {
                // JoinTable
                mapTbl = storeMgr.getDatastoreContainerObject(ownerMmd);
                ownerMapping = ((JoinTable)mapTbl).getOwnerMapping();
            }
            else if (ownerMmd.getMap().getMapType() == MapType.MAP_TYPE_KEY_IN_VALUE)
            {
                // ForeignKey from value table to key
                AbstractClassMetaData valueCmd =
                    storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(ownerMmd.getMap().getValueType(), clr);
                mapTbl = storeMgr.getDatastoreClass(ownerMmd.getMap().getValueType(), clr);
                if (ownerMmd.getMappedBy() != null)
                {
                    ownerMapping = mapTbl.getMemberMapping(valueCmd.getMetaDataForMember(ownerMmd.getMappedBy()));
                }
                else
                {
                    ownerMapping = ((DatastoreClass)mapTbl).getExternalMapping(ownerMmd, MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
                }
            }
            else if (ownerMmd.getMap().getMapType() == MapType.MAP_TYPE_VALUE_IN_KEY)
            {
                // ForeignKey from key table to value
                AbstractClassMetaData keyCmd =
                    storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(ownerMmd.getMap().getKeyType(), clr);
                mapTbl = storeMgr.getDatastoreClass(ownerMmd.getMap().getKeyType(), clr);
                if (ownerMmd.getMappedBy() != null)
                {
                    ownerMapping = mapTbl.getMemberMapping(keyCmd.getMetaDataForMember(ownerMmd.getMappedBy()));
                }
                else
                {
                    ownerMapping = ((DatastoreClass)mapTbl).getExternalMapping(ownerMmd, MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
                }
View Full Code Here

            String elementType = mmd.getCollection().getElementType();
            RDBMSStoreManager storeMgr = stmt.getRDBMSManager();

            // TODO Allow for interface elements, etc
            JavaTypeMapping ownerMapping = null;
            DatastoreContainerObject collectionTbl = null;
            if (mmd.getMappedBy() != null)
            {
                // Bidirectional
                AbstractMemberMetaData elementMmd = mmd.getRelatedMemberMetaData(clr)[0];
                if (mmd.getJoinMetaData() != null || elementMmd.getJoinMetaData() != null)
                {
                    // JoinTable
                    collectionTbl = storeMgr.getDatastoreContainerObject(mmd);
                    ownerMapping = ((JoinTable)collectionTbl).getOwnerMapping();
                }
                else
                {
                    // ForeignKey
                    collectionTbl = storeMgr.getDatastoreClass(elementType, clr);
                    ownerMapping = collectionTbl.getMemberMapping(elementMmd);
                }
            }
            else
            {
                // Unidirectional
View Full Code Here

                    " does not represent an indexed list!");
            }

            JavaTypeMapping orderMapping = null;
            SQLTable orderTable = null;
            DatastoreContainerObject joinTbl = stmt.getRDBMSManager().getDatastoreContainerObject(mmd);
            if (joinTbl != null)
            {
                // 1-N via join table
                CollectionTable collTable = (CollectionTable)joinTbl;
                orderTable = stmt.getTable(collTable, collSqlExpr.getSQLTable().getGroupName());
View Full Code Here

  // Mostly copied from RDBMSMappingManager.createDatastoreField
  public DatastoreField createDatastoreField(JavaTypeMapping mapping, String javaType,
      int datastoreFieldIndex) {
    AbstractMemberMetaData fmd = mapping.getMemberMetaData();
    int roleForField = mapping.getRoleForMember();
    DatastoreContainerObject datastoreContainer = mapping.getDatastoreContainer();

    // Take the column MetaData from the component that this mappings role relates to
    ColumnMetaData colmd;
    ColumnMetaDataContainer columnContainer = fmd;
    if (roleForField == FieldRole.ROLE_COLLECTION_ELEMENT ||
        roleForField == FieldRole.ROLE_ARRAY_ELEMENT) {
      columnContainer = fmd.getElementMetaData();
    } else if (roleForField == FieldRole.ROLE_MAP_KEY) {
      columnContainer = fmd.getKeyMetaData();
    } else if (roleForField == FieldRole.ROLE_MAP_VALUE) {
      columnContainer = fmd.getValueMetaData();
    }

    DatastoreProperty prop;
    ColumnMetaData[] colmds;
    if (columnContainer != null
        && columnContainer.getColumnMetaData() != null
        && columnContainer.getColumnMetaData().length > datastoreFieldIndex) {
      colmd = columnContainer.getColumnMetaData()[datastoreFieldIndex];
      colmds = columnContainer.getColumnMetaData();
    } else {
      // If column specified add one (use any column name specified on field element)
      colmd = new ColumnMetaData();
      colmd.setName(fmd.getColumn());
      if (columnContainer != null) {
        columnContainer.addColumn(colmd);
        colmds = columnContainer.getColumnMetaData();
      } else {
        colmds = new ColumnMetaData[1];
        colmds[0] = colmd;
      }
    }

    // Generate the column identifier
    MappedStoreManager storeMgr = datastoreContainer.getStoreManager();
    IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
    DatastoreIdentifier identifier = null;
    if (colmd.getName() == null) {
      // No name specified, so generate the identifier from the field name
      if (roleForField == FieldRole.ROLE_FIELD) {
        identifier = idFactory.newIdentifier(IdentifierType.COLUMN, fmd.getName());
        int i = 0;
        while (datastoreContainer.hasDatastoreField(identifier)) {
          identifier = idFactory.newIdentifier(IdentifierType.COLUMN, fmd.getName() + "_" + i);
          i++;
        }
      } else if (roleForField == FieldRole.ROLE_COLLECTION_ELEMENT) {
        // Join table collection element
        identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null, true,
            FieldRole.ROLE_COLLECTION_ELEMENT);
      } else if (roleForField == FieldRole.ROLE_ARRAY_ELEMENT) {
        // Join table array element
        identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null, true,
            FieldRole.ROLE_ARRAY_ELEMENT);
      } else if (roleForField == FieldRole.ROLE_MAP_KEY) {
        // Join table map key
        identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null, true,
            FieldRole.ROLE_MAP_KEY);
      } else if (roleForField == FieldRole.ROLE_MAP_VALUE) {
        // Join table map value
        identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null, true,
            FieldRole.ROLE_MAP_VALUE);
      }

      colmd.setName(identifier.getIdentifierName());
    } else {
      // User has specified a name, so try to keep this unmodified
      identifier = idFactory.newDatastoreFieldIdentifier(colmds[datastoreFieldIndex].getName(),
          storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(fmd.getType()),
          FieldRole.ROLE_CUSTOM);
    }

    // Create the column
    prop = (DatastoreProperty) datastoreContainer.addDatastoreField(javaType, identifier, mapping, colmd);

    if (fmd.isPrimaryKey()) {
      prop.setAsPrimaryKey();
    }
View Full Code Here

  }

  public DatastoreField createDatastoreField(JavaTypeMapping mapping, String javaType,
      ColumnMetaData colmd) {
    AbstractMemberMetaData fmd = mapping.getMemberMetaData();
    DatastoreContainerObject datastoreContainer = mapping.getDatastoreContainer();
    MappedStoreManager storeMgr = datastoreContainer.getStoreManager();

    DatastoreField prop;
    if (colmd == null) {
      // If column specified add one (use any column name specified on field element)
      colmd = new ColumnMetaData();
      colmd.setName(fmd.getColumn());
      fmd.addColumn(colmd);
    }

    IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
    if (colmd.getName() == null) {
      // No name specified, so generate the identifier from the field name
      DatastoreIdentifier identifier = idFactory
          .newIdentifier(IdentifierType.COLUMN, fmd.getName());
      int i = 0;
      while (datastoreContainer.hasDatastoreField(identifier)) {
        identifier = idFactory.newIdentifier(IdentifierType.COLUMN, fmd.getName() + "_" + i);
        i++;
      }

      colmd.setName(identifier.getIdentifierName());
      prop = datastoreContainer.addDatastoreField(javaType, identifier, mapping, colmd);
    } else {
      // User has specified a name, so try to keep this unmodified
      prop = datastoreContainer.addDatastoreField(
          javaType,
          idFactory.newDatastoreFieldIdentifier(colmd.getName(),
          storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(fmd.getType()),
          FieldRole.ROLE_CUSTOM),
          mapping,
View Full Code Here

        stmt.andCondition(ownerExpr.eq(ownerMapExpr),true);       
        // This depends on whether we have a separate key table or not
        if (!storeMgr.getMappedTypeManager().isSupportedMappedType(filteredKeyType.getName()))
        {
            // Join the key table on the key ID column (if theres a key table)
            DatastoreContainerObject filteredKeyTable = storeMgr.getDatastoreClass(filteredKeyType.getName(), stmt.getClassLoaderResolver());
            JavaTypeMapping keyTableID = filteredKeyTable.getIDMapping();
            stmt.newTableExpression(filteredKeyTable, keyTableAlias);

            ScalarExpression keyMapExpr = keyMapping.newScalarExpression(stmt,stmt.getTableExpression(containerRangeVar));
            ScalarExpression keyExpr = keyTableID.newScalarExpression(stmt, stmt.getTableExpression(keyTableAlias));
            stmt.innerJoin(keyExpr,keyMapExpr,stmt.getTableExpression(keyTableAlias), true, true);
View Full Code Here

        {
            throw new IncompatibleQueryElementTypeException(valueType,filteredValueType.getName());
        }

        // Join the value table on the owner ID column.
        DatastoreContainerObject filteredValueTable = storeMgr.getDatastoreClass(filteredValueType.getName(), stmt.getClassLoaderResolver());
        stmt.newTableExpression(filteredValueTable, valueRangeVar);

        ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt,ownerTe);
        DatastoreIdentifier containerRangeVar = mapRangeVar;
        if( stmt.getTableExpression(containerRangeVar) == null )
        {
            containerRangeVar = valueRangeVar;
        }
        ScalarExpression ownerValueExpr = this.ownerMapping.newScalarExpression(stmt,stmt.getTableExpression(containerRangeVar));
        stmt.newTableExpression(valueTable, containerRangeVar);
       
        stmt.andCondition(ownerExpr.eq(ownerValueExpr),true);

        JavaTypeMapping valueTableID = filteredValueTable.getIDMapping();
        return valueTableID.newScalarExpression(stmt,stmt.getTableExpression(containerRangeVar));
    }
View Full Code Here

TOP

Related Classes of org.datanucleus.store.mapped.DatastoreContainerObject

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.