本文整理汇总了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;
}
示例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()
);
}
}
}
}
示例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());
}
}
}
示例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());
}
}
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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);
}
}
}
}
}
}
}
示例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);
}
示例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 );
}
}
}
}
}
}