本文整理汇总了Java中org.eclipse.persistence.mappings.DatabaseMapping类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseMapping类的具体用法?Java DatabaseMapping怎么用?Java DatabaseMapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseMapping类属于org.eclipse.persistence.mappings包,在下文中一共展示了DatabaseMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMappingOnChildren
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的package包/类
private DatabaseMapping findMappingOnChildren(InheritancePolicy policy, String name) {
ArrayList<DatabaseMapping> found = new ArrayList<>();
for (ClassDescriptor child : policy.getChildDescriptors()) {
DatabaseMapping childMapping = child.getObjectBuilder().getMappingForAttributeName(name);
if (childMapping != null) {
found.add(childMapping);
}
}
switch (found.size()) {
case 0:
return null;
case 1:
return found.get(0);
default:
throw new JoinerException("Multiple mappings found for name " + name);
}
}
示例2: extractIdPropertyNames
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的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;
}
示例3: customize
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的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()
);
}
}
}
}
示例4: populateInverseRelationship
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的package包/类
/**
* Populates the inverse relationship for a given relationship.
*
* @param mapping the {@link DatabaseMapping} that defines the relationship.
* @param relationship the relationship of which to populate the other side.
*/
protected void populateInverseRelationship(DatabaseMapping mapping, MetadataChildBase relationship) {
DatabaseMapping relationshipPartner = findRelationshipPartner(mapping);
if (relationshipPartner != null) {
Class<?> partnerType = relationshipPartner.getDescriptor().getJavaClass();
DataObjectMetadata partnerMetadata = masterMetadataMap.get(partnerType);
// if the target metadata is not null, it means that entity has already been processed,
// so we can go ahead and establish the inverse relationship
if (partnerMetadata != null) {
// first check if it's a relationship
MetadataChildBase relationshipPartnerMetadata =
(MetadataChildBase)partnerMetadata.getRelationship(relationshipPartner.getAttributeName());
if (relationshipPartnerMetadata == null) {
relationshipPartnerMetadata =
(MetadataChildBase)partnerMetadata.getCollection(relationshipPartner.getAttributeName());
}
if (relationshipPartnerMetadata != null) {
relationshipPartnerMetadata.setInverseRelationship(relationship);
relationship.setInverseRelationship(relationshipPartnerMetadata);
}
}
}
}
示例5: findExtensionInverse
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的package包/类
/**
* Gets the inverse extension of the given {@link ClassDescriptor}.
*
* @param extensionEntityDescriptor the {@link ClassDescriptor} of which to get the inverse.
* @param entityType the type of the entity.
* @return the inverse extension of the given {@link ClassDescriptor}.
*/
protected OneToOneMapping findExtensionInverse(ClassDescriptor extensionEntityDescriptor, Class<?> entityType) {
Collection<DatabaseMapping> derivedIdMappings = extensionEntityDescriptor.getDerivesIdMappinps();
String extensionInfo = "(" + extensionEntityDescriptor.getJavaClass().getName() + " -> " + entityType.getName()
+ ")";
if (derivedIdMappings == null || derivedIdMappings.isEmpty()) {
throw new MetadataConfigurationException("Attempting to use extension framework, but extension "
+ extensionInfo + " does not have a valid inverse OneToOne Id mapping back to the extended data "
+ "object. Please ensure it is annotated property for use of the extension framework with JPA.");
} else if (derivedIdMappings.size() > 1) {
throw new MetadataConfigurationException("When attempting to determine the inverse relationship for use "
+ "with extension framework " + extensionInfo + " encountered more than one 'derived id' mapping, "
+ "there should be only one!");
}
DatabaseMapping inverseMapping = derivedIdMappings.iterator().next();
if (!(inverseMapping instanceof OneToOneMapping)) {
throw new MetadataConfigurationException("Identified an inverse derived id mapping for extension "
+ "relationship " + extensionInfo + " but it was not a one-to-one mapping: " + inverseMapping);
}
return (OneToOneMapping)inverseMapping;
}
示例6: testConvertersEstabished_directAssignment
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的package包/类
@Test
public void testConvertersEstabished_directAssignment() throws Exception {
ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("nonStandardDataType");
assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass());
Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter();
assertNotNull("converter not assigned", converter);
assertEquals("Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class,
converter.getClass());
Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
f.setAccessible(true);
String attributeConverterClassName = (String) f.get(converter);
assertNotNull("attributeConverterClassName missing", attributeConverterClassName);
assertEquals("Converter class incorrect", "org.kuali.rice.krad.data.jpa.testbo.NonStandardDataTypeConverter",
attributeConverterClassName);
}
示例7: testConvertersEstabished_autoApply
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的package包/类
@Test
public void testConvertersEstabished_autoApply() throws Exception {
ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("currencyProperty");
assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass());
Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter();
assertNotNull("converter not assigned", converter);
assertEquals("Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class,
converter.getClass());
Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
f.setAccessible(true);
String attributeConverterClassName = (String) f.get(converter);
assertNotNull("attributeConverterClassName missing", attributeConverterClassName);
assertEquals("Converter class incorrect", "org.kuali.rice.krad.data.jpa.converters.KualiDecimalConverter",
attributeConverterClassName);
}
示例8: testConvertersEstabished_autoApply_Boolean
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的package包/类
@Test
public void testConvertersEstabished_autoApply_Boolean() throws Exception {
ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("booleanProperty");
assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass());
Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter();
assertNotNull("converter not assigned", converter);
assertEquals("Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class,
converter.getClass());
Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
f.setAccessible(true);
String attributeConverterClassName = (String) f.get(converter);
assertNotNull("attributeConverterClassName missing", attributeConverterClassName);
assertEquals("Converter class incorrect", "org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter",
attributeConverterClassName);
}
示例9: customize
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的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());
}
}
}
示例10: customize
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的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());
}
}
}
示例11: getManagedAttribute
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的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;
}
示例12: getDatabaseMapping
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的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;
}
示例13: initialize
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的package包/类
@Override
public void initialize( final DatabaseMapping mapping, final Session session )
{
final DatabaseField field;
if ( mapping instanceof DirectCollectionMapping )
{
field = ( (DirectCollectionMapping) mapping ).getDirectField();
}
else
{
field = mapping.getField();
}
field.setSqlType( java.sql.Types.OTHER );
field.setTypeName( "geometry" );
field.setColumnDefinition( "geometry" );
}
示例14: customize
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的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());
}
}
}
示例15: getMappingForAttributeName
import org.eclipse.persistence.mappings.DatabaseMapping; //导入依赖的package包/类
@Override
public DatabaseMapping getMappingForAttributeName(String name) {
DatabaseMapping mapping = super.getMappingForAttributeName(name);
// name contains spaces for "treat as ..." entries, just skip it
if (mapping == null && !name.contains(SPACE)) {
InheritancePolicy policy = this.descriptor.getInheritancePolicyOrNull();
if (policy != null) {
mapping = findMappingOnChildren(policy, name);
}
}
return mapping;
}