Example #1
0
  public Type getType() throws MappingException {
    if (type != null) {
      return type;
    }

    if (typeName == null) {
      throw new MappingException("No type name");
    }

    if (typeParameters != null
        && Boolean.valueOf(typeParameters.getProperty(DynamicParameterizedType.IS_DYNAMIC))
        && typeParameters.get(DynamicParameterizedType.PARAMETER_TYPE) == null) {
      createParameterImpl();
    }

    Type result = metadata.getTypeResolver().heuristicType(typeName, typeParameters);
    if (result == null) {
      String msg = "Could not determine type for: " + typeName;
      if (table != null) {
        msg += ", at table: " + table.getName();
      }
      if (columns != null && columns.size() > 0) {
        msg += ", for columns: " + columns;
      }
      throw new MappingException(msg);
    }

    return result;
  }
  private SchemaExport createSchemaExport(Class[] annotatedClasses) {
    final MetadataSources metadataSources = new MetadataSources(ssr);

    for (Class c : annotatedClasses) {
      metadataSources.addAnnotatedClass(c);
    }
    metadata = (MetadataImplementor) metadataSources.buildMetadata();
    metadata.validate();
    SchemaExport schemaExport = new SchemaExport(metadata);
    schemaExport.setHaltOnError(false).setFormat(false);

    return schemaExport;
  }
Example #3
0
  public void setTypeUsingReflection(String className, String propertyName)
      throws MappingException {
    // NOTE : this is called as the last piece in setting SimpleValue type information, and
    // implementations
    // rely on that fact, using it as a signal that all information it is going to get is defined at
    // this point...

    if (typeName != null) {
      // assume either (a) explicit type was specified or (b) determine was already performed
      return;
    }

    if (type != null) {
      return;
    }

    if (attributeConverterDefinition == null) {
      // this is here to work like legacy.  This should change when we integrate with metamodel to
      // look for SqlTypeDescriptor and JavaTypeDescriptor individually and create the BasicType
      // (well, really
      // keep a registry of [SqlTypeDescriptor,JavaTypeDescriptor] -> BasicType...)
      if (className == null) {
        throw new MappingException(
            "Attribute types for a dynamic entity must be explicitly specified: " + propertyName);
      }
      typeName =
          ReflectHelper.reflectedPropertyClass(
                  className,
                  propertyName,
                  metadata
                      .getMetadataBuildingOptions()
                      .getServiceRegistry()
                      .getService(ClassLoaderService.class))
              .getName();
      // todo : to fully support isNationalized here we need do the process hinted at above
      // 		essentially, much of the logic from #buildAttributeConverterTypeAdapter wrt resolving
      //		a (1) SqlTypeDescriptor, a (2) JavaTypeDescriptor and dynamically building a BasicType
      // 		combining them.
      return;
    }

    // we had an AttributeConverter...
    type = buildAttributeConverterTypeAdapter();
  }
Example #4
0
 private EntityType getEntityType() {
   return metadata
       .getTypeResolver()
       .getTypeFactory()
       .manyToOne(getReferencedEntityName(), true, null, false, false, isIgnoreNotFound(), false);
 }
Example #5
0
 @Override
 public ServiceRegistry getServiceRegistry() {
   return metadata.getMetadataBuildingOptions().getServiceRegistry();
 }
Example #6
0
  @Override
  public IdentifierGenerator createIdentifierGenerator(
      IdentifierGeneratorFactory identifierGeneratorFactory,
      Dialect dialect,
      String defaultCatalog,
      String defaultSchema,
      RootClass rootClass)
      throws MappingException {

    if (identifierGenerator != null) {
      return identifierGenerator;
    }

    Properties params = new Properties();

    // if the hibernate-mapping did not specify a schema/catalog, use the defaults
    // specified by properties - but note that if the schema/catalog were specified
    // in hibernate-mapping, or as params, they will already be initialized and
    // will override the values set here (they are in identifierGeneratorProperties)
    if (defaultSchema != null) {
      params.setProperty(PersistentIdentifierGenerator.SCHEMA, defaultSchema);
    }
    if (defaultCatalog != null) {
      params.setProperty(PersistentIdentifierGenerator.CATALOG, defaultCatalog);
    }

    // pass the entity-name, if not a collection-id
    if (rootClass != null) {
      params.setProperty(IdentifierGenerator.ENTITY_NAME, rootClass.getEntityName());
      params.setProperty(IdentifierGenerator.JPA_ENTITY_NAME, rootClass.getJpaEntityName());
    }

    // init the table here instead of earlier, so that we can get a quoted table name
    // TODO: would it be better to simply pass the qualified table name, instead of
    //      splitting it up into schema/catalog/table names
    String tableName = getTable().getQuotedName(dialect);
    params.setProperty(PersistentIdentifierGenerator.TABLE, tableName);

    // pass the column name (a generated id almost always has a single column)
    String columnName = ((Column) getColumnIterator().next()).getQuotedName(dialect);
    params.setProperty(PersistentIdentifierGenerator.PK, columnName);

    if (rootClass != null) {
      StringBuilder tables = new StringBuilder();
      Iterator iter = rootClass.getIdentityTables().iterator();
      while (iter.hasNext()) {
        Table table = (Table) iter.next();
        tables.append(table.getQuotedName(dialect));
        if (iter.hasNext()) {
          tables.append(", ");
        }
      }
      params.setProperty(PersistentIdentifierGenerator.TABLES, tables.toString());
    } else {
      params.setProperty(PersistentIdentifierGenerator.TABLES, tableName);
    }

    if (identifierGeneratorProperties != null) {
      params.putAll(identifierGeneratorProperties);
    }

    // TODO : we should pass along all settings once "config lifecycle" is hashed out...
    final ConfigurationService cs =
        metadata
            .getMetadataBuildingOptions()
            .getServiceRegistry()
            .getService(ConfigurationService.class);

    params.put(
        AvailableSettings.PREFER_POOLED_VALUES_LO,
        cs.getSetting(
            AvailableSettings.PREFER_POOLED_VALUES_LO, StandardConverters.BOOLEAN, false));
    if (cs.getSettings().get(AvailableSettings.PREFERRED_POOLED_OPTIMIZER) != null) {
      params.put(
          AvailableSettings.PREFERRED_POOLED_OPTIMIZER,
          cs.getSettings().get(AvailableSettings.PREFERRED_POOLED_OPTIMIZER));
    }

    identifierGeneratorFactory.setDialect(dialect);
    identifierGenerator =
        identifierGeneratorFactory.createIdentifierGenerator(
            identifierGeneratorStrategy, getType(), params);

    return identifierGenerator;
  }