Examples of DatastoreField


Examples of org.datanucleus.store.mapped.DatastoreField

                // Name defined so just generate identifier
                id = idFactory.newDatastoreFieldIdentifier(colmd.getName());
            }
        }

        DatastoreField column = table.addDatastoreField(getType(), id, this, dismd.getColumnMetaData());
        table.getStoreManager().getMappingManager().createDatastoreMapping(delegate, column,
            getType());
    }
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreField

    // Verify if a duplicate column is valid. A duplicate column name is (currently) valid when :-
    // 1. subclasses defining the duplicated column are using "super class table" strategy
    //
    // Find the MetaData for the existing column
    DatastoreIdentifier name = col.getIdentifier();
    DatastoreField existingCol = getDatastoreField(name);
    MetaData md = existingCol.getColumnMetaData().getParent();
    while (!(md instanceof AbstractClassMetaData)) {
      if (md == null) {
        // ColumnMetaData for existing column has no parent class somehow!
        throw new NucleusUserException(MessageFormat.format(
            "The property \"{0}\" exists in entity \"{1}\" and has invalid metadata. The existing property is \"{2}\"",
            name, this.identifier, colmd.toString()));
      }
      md = md.getParent();
    }

    // Find the MetaData for the column to be added
    MetaData dupMd = colmd.getParent();
    while (!(dupMd instanceof AbstractClassMetaData)) {
      dupMd = dupMd.getParent();
      if (dupMd == null) {
        // ColumnMetaData for required column has no parent class somehow!
        throw new NucleusUserException(MessageFormat.format(
            "The column \"{0}\" exists in table \"{1}\" and cannot be validated because a duplicated column has been specified and the metadata is invalid. The column is \"{2}\"",
            name, this.identifier, colmd.toString()));
      }
    }
    if (((AbstractClassMetaData) md).getFullClassName().equals(
        ((AbstractClassMetaData) dupMd).getFullClassName())) {
      // compare the current column defining class and the duplicated column defining class. if the same class,
      // we raise an exception when within one class it is defined a column twice
      // in some cases it could still be possible to have these duplicated columns, but does not make too
      // much sense in most of the cases. (this whole block of duplicated column check, could be optional, like a pmf property)
      throw new DuplicateDatastoreFieldException(this.toString(), existingCol, col);
    }

    // Make sure the field JavaTypeMappings are compatible
    if (mapping != null &&
        !mapping.getClass().isAssignableFrom(existingCol.getJavaTypeMapping().getClass()) &&
        !existingCol.getJavaTypeMapping().getClass().isAssignableFrom(mapping.getClass())) {
      // the mapping class must be the same (not really required, but to avoid user mistakes)
      throw new DuplicateDatastoreFieldException(this.toString(), existingCol, col);
    }

    // Make sure the field java types are compatible
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreField

                FieldRole.ROLE_NONE).getIdentifierName());
      }
    }

    // Add the datastore identity column as the PK
    DatastoreField idColumn = addDatastoreField(OID.class.getName(),
        storeMgr.getIdentifierFactory().newIdentifier(IdentifierType.COLUMN, colmd.getName()),
        datastoreIDMapping, colmd);
    idColumn.setAsPrimaryKey();

    // Set the identity column type based on the IdentityStrategy
    String strategyName = cmd.getIdentityMetaData().getValueStrategy().toString();
    if (cmd.getIdentityMetaData().getValueStrategy().equals(IdentityStrategy.CUSTOM)) {
      strategyName = cmd.getIdentityMetaData().getValueStrategy().getCustomName();
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreField

      // Loop through each id column in the reference table and add the same here
      // applying the required names from the columnContainer
      for (int j = 0; j < mapping.getNumberOfDatastoreMappings(); j++) {
        JavaTypeMapping m = masterMapping;
        DatastoreField refColumn = mapping.getDatastoreMapping(j).getDatastoreField();
        if (mapping instanceof PersistableMapping) {
          m = storeMgr.getMappingManager()
              .getMapping(clr.classForName(refColumn.getJavaTypeMapping().getType()));
          ((PersistableMapping) masterMapping).addJavaTypeMapping(m);
        }

        ColumnMetaData userdefinedColumn = null;
        if (userdefinedCols != null) {
          for (ColumnMetaData userdefinedCol : userdefinedCols) {
            if (refColumn.getIdentifier().toString().equals(userdefinedCol.getTarget())) {
              userdefinedColumn = userdefinedCol;
              break;
            }
          }
          if (userdefinedColumn == null && nextUserdefinedCol < userdefinedCols.length) {
            userdefinedColumn = userdefinedCols[nextUserdefinedCol++];
          }
        }

        // Add this application identity column
        DatastoreField idColumn;
        if (userdefinedColumn != null) {
          // User has provided a name for this column
          // Currently we only use the column namings from the users definition but we could easily
          // take more of their details.
          idColumn = addDatastoreField(refColumn.getStoredJavaType(),
              storeMgr.getIdentifierFactory().newIdentifier(IdentifierType.COLUMN,
                  userdefinedColumn.getName()),
              m, refColumn.getColumnMetaData());
        } else {
          // No name provided so take same as superclass
          idColumn = addDatastoreField(refColumn.getStoredJavaType(), refColumn.getIdentifier(),
              m, refColumn.getColumnMetaData());
        }
        if (mapping != null
            && mapping.getDatastoreMapping(j).getDatastoreField().getColumnMetaData() != null) {
          refColumn.copyConfigurationTo(idColumn);
        }
        idColumn.setAsPrimaryKey();

        // Set the column type based on the field.getType()
        getStoreManager().getMappingManager()
            .createDatastoreMapping(m, idColumn, refColumn.getJavaTypeMapping().getType());
      }
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreField

    }

    // if the relationship is in a base class with multiple subclasses, each
    // subclass will try to add the index column.  We need to avoid adding
    // the same column twice.
    DatastoreField column = datastorePropertiesByName.get(indexColumnName.getIdentifierName());
    if (column == null) {
      column = addDatastoreField(indexType.getName(), indexColumnName, indexMapping, colmd);
    }
    if (colmd == null || (colmd.getAllowsNull() == null) ||
        (colmd.getAllowsNull() != null && colmd.isAllowsNull())) {
      // User either wants it nullable, or havent specified anything, so make it nullable
      column.setNullable();
    }

    DatastoreFKMapping fkMapping =
        (DatastoreFKMapping) storeMgr.getMappingManager().createDatastoreMapping(
            indexMapping, column, indexType.getName());
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreField

            MappingManager mapMgr = storeMgr.getMappingManager();
            JavaTypeMapping mapping = mapMgr.getMapping(String.class);
            mapping.setMemberMetaData(mmd);
            mapping.setDatastoreContainer(datastoreContainer);
            mapping.setRoleForMember(roleForMember);
            DatastoreField col = mapMgr.createDatastoreField(mapping, String.class.getName(), 0);
            mapMgr.createDatastoreMapping(mapping, mmd, 0, col);
            this.addJavaTypeMapping(mapping);
        }
    }
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreField

      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,
          colmd);
    }

//    setDatastoreFieldNullability(fmd, colmd, prop);
    if (fmd.getNullValue() == NullValue.DEFAULT) {
      // Users default should be applied if a null is to be inserted
      prop.setDefaultable();
      if (colmd.getDefaultValue() != null) {
        throw new UnsupportedOperationException("User-defined default not supported.");
      }
    }
    return prop;
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreField

    } else {
      // User has specified a name, so try to keep this unmodified
      identifier = idFactory
          .newDatastoreFieldIdentifier(colmd.getName(), false, FieldRole.ROLE_CUSTOM);
    }
    DatastoreField prop = datastoreContainer
        .addDatastoreField(fmd.getType().getName(), identifier, mapping, colmd);

    // Copy the characteristics of the reference column to this one
    reference.copyConfigurationTo(prop);

    if (fmd.isPrimaryKey()) {
      prop.setAsPrimaryKey();
    }

//    if (storeMgr.isStrategyDatastoreAttributed(fmd.getValueStrategy(), false)) {
//      if ((fmd.isPrimaryKey() && ((DatastoreClass) datastoreContainer).isBaseDatastoreClass())
//          || !fmd.isPrimaryKey()) {
//        // Increment any PK field if we are in base class, and increment any other field
//        prop.setAutoIncrement(true);
//      }
//    }

//    setDatastoreFieldNullability(fmd, colmd, prop);
    if (fmd.getNullValue() == NullValue.DEFAULT) {
      // Users default should be applied if a null is to be inserted
      prop.setDefaultable();
      if (colmd.getDefaultValue() != null) {
        throw new UnsupportedOperationException("User-defined default not supported.");
      }
    }
    return prop;
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreField

     * This creates the column in the table.
     */
    protected void prepareDatastoreMapping()
    {
        MappingManager mmgr = datastoreContainer.getStoreManager().getMappingManager();
        DatastoreField col = mmgr.createDatastoreField(this, getJavaTypeForDatastoreMapping(0), 0);
        mmgr.createDatastoreMapping(this, mmd, 0, col);
    }
View Full Code Here

Examples of org.datanucleus.store.mapped.DatastoreField

        if (mmd.getKeyMetaData() != null && mmd.getKeyMetaData().getColumnMetaData() != null &&
            mmd.getKeyMetaData().getColumnMetaData().length > 0)
        {
            colmd = mmd.getKeyMetaData().getColumnMetaData()[0];
        }
        DatastoreField col = mmgr.createDatastoreField(this, getType(), colmd);
        mmgr.createDatastoreMapping(this, mmd, 0, col);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.