当前位置: 首页>>代码示例>>Java>>正文


Java ClassDescriptor.getMappings方法代码示例

本文整理汇总了Java中org.eclipse.persistence.descriptors.ClassDescriptor.getMappings方法的典型用法代码示例。如果您正苦于以下问题:Java ClassDescriptor.getMappings方法的具体用法?Java ClassDescriptor.getMappings怎么用?Java ClassDescriptor.getMappings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.persistence.descriptors.ClassDescriptor的用法示例。


在下文中一共展示了ClassDescriptor.getMappings方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractIdPropertyNames

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Override
public String[] extractIdPropertyNames(Object entity)
{
    final EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
    final ClassDescriptor desc = em.unwrap(JpaEntityManager.class).getServerSession().getClassDescriptor(entity);
    if (desc != null)
    {
   	    final Collection<DatabaseMapping> fieldNames = desc.getMappings();
   	    final List<DatabaseMapping> tmp = new LinkedList<>();
   	    for (DatabaseMapping m : fieldNames)
   	    {
   	        if (m.isPrimaryKeyMapping())
   	        {
   	            tmp.add(m);
   	        }
   	    }
   	    final String[] retVal = new String[tmp.size()];
   	    for (int i = 0; i < retVal.length; i++)
   	    {
   	        retVal[i] = tmp.get(i).getAttributeName();
   	    }
   	    return retVal;
    }
    
    return null;
}
 
开发者ID:ethlo,项目名称:dachs,代码行数:27,代码来源:EclipselinkLazyIdExtractor.java

示例2: customize

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Override
public void customize(Session session) throws Exception {
    for (ClassDescriptor descriptor : session.getDescriptors().values()) {
        if (!descriptor.getTables().isEmpty() && descriptor.getAlias().equalsIgnoreCase(descriptor.getTableName())) {
            String tableName = addUnderscores(descriptor.getAlias()).toUpperCase();
            System.out.println(descriptor.getAlias() + ":" + tableName);
            descriptor.setTableName(tableName);

            DatabaseTable databaseTable = descriptor.getTables().get(0);
            for (IndexDefinition indexDef : databaseTable.getIndexes()) {
                indexDef.setTargetTable(tableName);
            }
        }

        for (DatabaseMapping mapping : descriptor.getMappings()) {
            if (mapping.getField() != null
                    && !mapping.getAttributeName().isEmpty()
                    && mapping.getField().getName().equalsIgnoreCase(mapping.getAttributeName())) {
                mapping.getField().setName(
                        addUnderscores(mapping.getAttributeName()).toUpperCase()
                );
            }
        }
    }
}
 
开发者ID:kawasima,项目名称:occupy-pub,代码行数:26,代码来源:SnakeCaseNameMapping.java

示例3: customize

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Override
public void customize(final Session session) throws SQLException {
    for (ClassDescriptor descriptor : session.getDescriptors().values()) {
        if (!descriptor.getTables().isEmpty()) {
            // Take table name from @Table if exists
            String tableName = null;
            if (descriptor.getAlias().equalsIgnoreCase(descriptor.getTableName())) {
                tableName = unqualify(descriptor.getJavaClassName());
            } else {
                tableName = descriptor.getTableName();
            }
            tableName = camelCaseToUnderscore(tableName);
            descriptor.setTableName(tableName);

            for (IndexDefinition index : descriptor.getTables().get(0).getIndexes()) {
                index.setTargetTable(tableName);
            }
            Vector<DatabaseMapping> mappings = descriptor.getMappings();
            camelCaseToUnderscore(mappings);
        } else if (descriptor.isAggregateDescriptor() || descriptor.isChildDescriptor()) {
            camelCaseToUnderscore(descriptor.getMappings());
        }
    }
}
 
开发者ID:antoniomaria,项目名称:karaf4-eclipselink-jpa,代码行数:25,代码来源:CamelNamingStrategy.java

示例4: customize

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Override
public void customize(final Session session) throws SQLException {
    for (ClassDescriptor descriptor : session.getDescriptors().values()) {
        if (!descriptor.getTables().isEmpty()) {
            // Take table name from @Table if exists
            String tableName = null;
            if (descriptor.getAlias().equalsIgnoreCase(descriptor.getTableName())) {
                tableName = unqualify(descriptor.getJavaClassName());
            } else {
                tableName = descriptor.getTableName();
            }
            tableName = camelCaseToUnderscore(tableName);
            descriptor.setTableName(tableName);
            for (IndexDefinition index : descriptor.getTables().get(0).getIndexes()) {
                index.setTargetTable(tableName);
            }
            Vector<DatabaseMapping> mappings = descriptor.getMappings();
            camelCaseToUnderscore(mappings);
        } else if (descriptor.isAggregateDescriptor() || descriptor.isChildDescriptor()) {
            camelCaseToUnderscore(descriptor.getMappings());
        }
    }
}
 
开发者ID:StefanSchubert,项目名称:sabi,代码行数:24,代码来源:JPACamelCaseNamingStrategy.java

示例5: getManagedAttribute

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
private Attribute getManagedAttribute(ClassDescriptor refDescriptor, DatabaseField dbField, LinkedList<Attribute> intrinsicAttribute) {
    if (refDescriptor != null) {
        for (DatabaseMapping refMapping : refDescriptor.getMappings()) {
            if(!refMapping.getFields()
                    .stream()
                    .filter(field -> field == dbField)
                    .findAny()
                    .isPresent()){
                continue;
            }
            
            if (refMapping.getFields().size() > 1) {
                intrinsicAttribute.add((Attribute) refMapping.getProperty(Attribute.class));
                if(refMapping.getReferenceDescriptor() == refDescriptor){ //self-relationship with composite pk
                    return (Attribute) refMapping.getProperty(Attribute.class);
                } else {
                    return getManagedAttribute(refMapping.getReferenceDescriptor(), dbField, intrinsicAttribute);
                }
            } else if (!refMapping.getFields().isEmpty() && refMapping.getFields().get(0) == dbField) {
                intrinsicAttribute.add((Attribute) refMapping.getProperty(Attribute.class));
                return (Attribute) refMapping.getProperty(Attribute.class);
            }
        }
    }
    return null;
}
 
开发者ID:jeddict,项目名称:jeddict,代码行数:27,代码来源:JPAMDefaultTableGenerator.java

示例6: getDatabaseMapping

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
private DatabaseMapping getDatabaseMapping(ClassDescriptor descriptor, DatabaseField databaseField) {
    DatabaseMapping databaseMapping = mappings.get(databaseField);
    if (databaseMapping == null) {
        for (DatabaseMapping m : descriptor.getMappings()) {
            for (DatabaseField f : m.getFields()) {
                if (mappings.get(f) == null) {
                    mappings.put(f, m);
                }
                if (databaseField == f) {
                    databaseMapping = m;
                }
            }
        }
    }
    return databaseMapping;
}
 
开发者ID:jeddict,项目名称:jeddict,代码行数:17,代码来源:JPAMDefaultTableGenerator.java

示例7: customize

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Override
public void customize(final Session session) throws Exception {
    if (JPAThreadContext.infos.containsKey("properties")) {
        final String prefix = ((Properties) JPAThreadContext.infos.get("properties")).getProperty("openejb.jpa.table_prefix");
        final List<DatabaseTable> tables = new ArrayList<DatabaseTable>();
        for (final ClassDescriptor cd : session.getDescriptors().values()) {
            for (final DatabaseTable table : cd.getTables()) {
                update(prefix, tables, table);
            }
            for (final DatabaseMapping mapping : cd.getMappings()) {
                if (mapping instanceof ManyToManyMapping) {
                    update(prefix, tables, ((ManyToManyMapping) mapping).getRelationTable());
                } else if (mapping instanceof DirectCollectionMapping) {
                    update(prefix, tables, ((DirectCollectionMapping) mapping).getReferenceTable());
                } // TODO: else check we need to update something
            }
        }

        final Sequence sequence = session.getDatasourcePlatform().getDefaultSequence();
        if (sequence instanceof TableSequence) {
            final TableSequence ts = ((TableSequence) sequence);
            ts.setName(prefix + ts.getName());
        }
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:26,代码来源:PrefixSessionCustomizer.java

示例8: customize

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void customize(Session session) throws Exception {
    Map<Class, ClassDescriptor> descriptors = session.getDescriptors();
    // iterate all descriptors
    for (ClassDescriptor classDescriptor : descriptors.values()) {
        // iterate the mappings of each descriptor
        for (DatabaseMapping databaseMapping : classDescriptor.getMappings()) {
            // process embedded properties
            if (databaseMapping.isAggregateObjectMapping()) {
                AggregateObjectMapping m = (AggregateObjectMapping) databaseMapping;
                Map<String, DatabaseField> fieldMapping = m.getAggregateToSourceFields();

                // iterate the mappings of the embeddable class
                for (DatabaseMapping refMapping : descriptors.get(m.getReferenceClass()).getMappings()) {
                    if (refMapping.isDirectToFieldMapping()) {
                        DirectToFieldMapping refDirectMapping = (DirectToFieldMapping) refMapping;
                        String refFieldName = refDirectMapping.getField().getName();
                        if (!fieldMapping.containsKey(refFieldName)) {
                            DatabaseField mappedField = refDirectMapping.getField().clone();
                            mappedField.setName(m.getAttributeName() + "_" + mappedField.getName());
                            fieldMapping.put(refFieldName, mappedField);
                        }
                    }

                }
            }

        }
    }
}
 
开发者ID:ruediste,项目名称:rise,代码行数:32,代码来源:EmbeddedFieldNamesSessionCustomizer.java

示例9: customize

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Override
public void customize(ClassDescriptor descriptor) throws Exception {
    descriptor.setShouldOrderMappings(true);
    List<DatabaseMapping> mappings = descriptor.getMappings();
    addWeight(this.getClass(descriptor.getJavaClassName()), mappings);
}
 
开发者ID:viydaag,项目名称:dungeonstory-java,代码行数:7,代码来源:OrderCustomizer.java

示例10: preLogin

import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Override
public void preLogin( final SessionEvent event )
{
  final Session session = event.getSession();

  boolean isSqlServer = false;
  boolean isPostgreSQL = false;

  final String geomDriver = (String) session.getProperty( "geolatte.geom.driver" );
  if ( null != geomDriver )
  {
    isSqlServer = geomDriver.equals( "sqlserver" );
    isPostgreSQL = geomDriver.equals( "postgres" );
  }
  else
  {
    final String driver = (String) session.getProperty( "javax.persistence.jdbc.driver" );
    if ( null != driver )
    {
      isSqlServer = driver.contains( ".jtds." );
      isPostgreSQL = driver.contains( "org.postgresql." );
    }
  }

  if ( !isSqlServer && !isPostgreSQL )
  {
    final String message =
      "Unable to determine database type. Explicitly set jpa " +
      "property 'geolatte.geom.driver' to 'sqlserver' or 'postgres'" ;
    throw new IllegalStateException( message );
  }

  final Map<Class, ClassDescriptor> descriptorMap = session.getDescriptors();

  // Walk through all descriptors...
  for ( final Map.Entry<Class, ClassDescriptor> entry : descriptorMap.entrySet() )
  {
    final ClassDescriptor desc = entry.getValue();
    final Vector<DatabaseMapping> mappings = desc.getMappings();
    // walk through all mappings for some class...
    for ( final DatabaseMapping mapping : mappings )
    {
      if ( mapping instanceof DirectToFieldMapping )
      {
        final DirectToFieldMapping dfm = (DirectToFieldMapping) mapping;
        if ( isCandidateConverter( dfm ) )
        {
          final Class type = entry.getKey();
          final String attributeName = dfm.getAttributeName();
          final Field field = getField( type, attributeName );
          final Class<?> fieldType = field.getType();
          if ( Point.class == fieldType ||
               Polygon.class == fieldType ||
               LinearRing.class == fieldType ||
               LineString.class == fieldType ||
               MultiPoint.class == fieldType ||
               MultiPolygon.class == fieldType ||
               MultiLineString.class == fieldType ||
               Geometry.class == fieldType ||
               GeometryCollection.class == fieldType )
          {
            final Converter converter = isSqlServer ? new SqlServerConverter() : new PostgisConverter();
            converter.initialize( mapping, session );
            dfm.setConverter( converter );
          }
        }
      }
    }
  }
}
 
开发者ID:realityforge,项目名称:geolatte-geom-eclipselink,代码行数:71,代码来源:GeolatteExtension.java


注:本文中的org.eclipse.persistence.descriptors.ClassDescriptor.getMappings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。