本文整理汇总了Java中org.eclipse.persistence.internal.helper.DatabaseField类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseField类的具体用法?Java DatabaseField怎么用?Java DatabaseField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseField类属于org.eclipse.persistence.internal.helper包,在下文中一共展示了DatabaseField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrimaryKeys
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
public String[] getPrimaryKeys(ClassDescriptor cd) {
if (!cd.hasSimplePrimaryKey()) {
throw new RuntimeException("only simple primary key is currently supported.");
}
List<DatabaseField> primaryKeyFields = cd.getPrimaryKeyFields();
String[] res = new String[primaryKeyFields.size()];
int i = 0;
for (DatabaseField f : primaryKeyFields) {
try {
Field field = cd.getJavaClass().getDeclaredField(f.getName()); // f.getTypeName() is null :-(
res[i++] = field.getType().getSimpleName() + " " + f.getName();
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
return res;
}
示例2: getManagedAttribute
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的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;
}
示例3: addFieldsForMappedKeyMapContainerPolicy
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
/**
* The ContainerPolicy may contain some additional fields that should be
* added to the table
*
* @see MappedKeyMapContainerPolicy
*/
protected void addFieldsForMappedKeyMapContainerPolicy(ManagedClass managedClass, Attribute managedAttribute, LinkedList<Entity> intrinsicEntity, LinkedList<Attribute> intrinsicAttribute, boolean isInherited, ContainerPolicy cp, TableDefinition table) {
if (cp.isMappedKeyMapPolicy()) {
List<DatabaseField> keyFields = cp.getIdentityFieldsForMapKey();
Iterator<DatabaseField> i = keyFields.iterator();
while (i.hasNext()) {
DatabaseField foreignKey = i.next();
// to fetch managed embedded attribute
LinkedList<Attribute> intrinsicAttribute_Local = new LinkedList<>(intrinsicAttribute);
Attribute managedAttribute_Local = managedAttribute;
if (managedAttribute instanceof MapKeyHandler && ((MapKeyHandler) managedAttribute).getMapKeyEmbeddable() != null) {
managedAttribute_Local = getManagedAttribute(cp.getDescriptorForMapKey(), foreignKey, intrinsicAttribute_Local);
}
FieldDefinition fieldDef = getFieldDefFromDBField(intrinsicEntity.get(0), intrinsicAttribute_Local, managedAttribute_Local, false, false, false, isInherited, false, false, true, foreignKey);
if (!table.getFields().contains(fieldDef)) {
table.addField(fieldDef);
}
}
Map<DatabaseField, DatabaseField> foreignKeys = ((MappedKeyMapContainerPolicy) cp).getForeignKeyFieldsForMapKey();
if (foreignKeys != null) {
addForeignMappingFkConstraint(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, foreignKeys, false);
}
}
}
示例4: addForeignMappingFkConstraint
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
protected void addForeignMappingFkConstraint(ManagedClass managedClass, Attribute managedAttribute, LinkedList<Entity> intrinsicEntity, LinkedList<Attribute> intrinsicAttribute, boolean isInherited, final Map<DatabaseField, DatabaseField> srcFields, boolean cascadeOnDelete) {
// srcFields map from the foreign key field to the target key field
if (srcFields.isEmpty()) {
return;
}
List<DatabaseField> fkFields = new ArrayList<>();
List<DatabaseField> targetFields = new ArrayList<>();
for (DatabaseField fkField : srcFields.keySet()) {
fkFields.add(fkField);
targetFields.add(srcFields.get(fkField));
}
addJoinColumnsFkConstraint(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, null, fkFields, targetFields, cascadeOnDelete);
}
示例5: getFieldDefFromDBField
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
/**
* Build a field definition object from a database field.
*/
protected FieldDefinition getFieldDefFromDBField(Entity intrinsicEntity, LinkedList<Attribute> intrinsicAttribute, Attribute managedAttribute, boolean inverse, boolean foriegnKey, boolean relationTable, boolean inherited, boolean dtype, boolean primaryKeyJoinColumn, boolean mapKey, DatabaseField dbField) {
Supplier<JPAMFieldDefinition> fieldDefSupplier = () -> {
JPAMFieldDefinition fieldDef;
if (inherited) {
fieldDef = new JPAMFieldDefinition(intrinsicEntity, managedAttribute, inverse, foriegnKey, relationTable);
} else if (dtype) {
fieldDef = new JPAMFieldDefinition(intrinsicEntity);
} else if (primaryKeyJoinColumn) {
fieldDef = new JPAMFieldDefinition(intrinsicEntity, primaryKeyJoinColumn);
} else if (mapKey) {
fieldDef = new JPAMFieldDefinition(intrinsicAttribute, managedAttribute, mapKey);
} else {
fieldDef = new JPAMFieldDefinition(intrinsicAttribute, managedAttribute, inverse, foriegnKey, relationTable);
}
return fieldDef;
};
return getFieldDefFromDBField(fieldDefSupplier, dbField);
}
示例6: getDatabaseMapping
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的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: buildForeignKeyConstraint
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
/**
* Build a foreign key constraint using
* FieldDefinition.getForeignKeyFieldName().
*/
@Override
protected ForeignKeyConstraint buildForeignKeyConstraint(FieldDefinition field, DatabasePlatform platform) {
Vector sourceFields = new Vector();
Vector targetFields = new Vector();
ForeignKeyConstraint fkConstraint = new ForeignKeyConstraint();
DatabaseField tempTargetField = new DatabaseField(field.getForeignKeyFieldName());
DatabaseField tempSourceField = new DatabaseField(field.getName());
sourceFields.add(tempSourceField.getName());
targetFields.add(tempTargetField.getName());
fkConstraint.setSourceFields(sourceFields);
fkConstraint.setTargetFields(targetFields);
fkConstraint.setTargetTable(tempTargetField.getTable().getQualifiedNameDelimited(platform));
String tempName = buildForeignKeyConstraintName(this.getName(), tempSourceField.getName(), platform.getMaxForeignKeyNameSize(), platform);
fkConstraint.setName(tempName);
return fkConstraint;
}
示例8: initialize
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的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" );
}
示例9: initialize
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
@Override
public void initialize(DatabaseMapping mapping, Session session) {
final DatabaseField field;
if (mapping instanceof DirectCollectionMapping) {
// handle @ElementCollection...
field = ((DirectCollectionMapping) mapping).getDirectField();
} else {
field = mapping.getField();
}
field.setSqlType(java.sql.Types.VARCHAR);
field.setLength(40);
//field.setTypeName("uuid");
//field.setColumnDefinition("UUID");
}
示例10: setDatabaseFieldParameters
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
private void setDatabaseFieldParameters(Session session, DatabaseField field) {
if (session.getPlatform() instanceof PostgreSQLPlatform) {
field.setSqlType(Types.OTHER);
field.setType(UUID.class);
} else {
field.setSqlType(Types.VARCHAR);
field.setType(String.class);
}
field.setColumnDefinition("UUID");
}
示例11: getCall
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
private MappedInteraction getCall(DescriptorQueryManager queryManager, DemoOperation op) {
MappedInteraction call = new MappedInteraction();
call.setProperty(DemoPlatform.OPERATION, op);
call.setProperty(KEYS, getPrimaryKeys(queryManager.getDescriptor()));
call.setProperty(DemoPlatform.TABLE, ((EISDescriptor) queryManager.getDescriptor()).getDataTypeName());
if (op == DemoOperation.FIND || op == DemoOperation.REMOVE) {
for (DatabaseField field : queryManager.getDescriptor().getPrimaryKeyFields()) {
call.addArgument(field.getName());
}
}
return call;
}
示例12: testExtensionAttribute_eclipselink_data
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
@Test
public void testExtensionAttribute_eclipselink_data() {
ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
ClassDescriptor referenceDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObjectExtension.class);
assertNotNull("A classDescriptor should have been retrieved from JPA for TestDataObject", classDescriptor);
assertNotNull("A classDescriptor should have been retrieved from JPA for TestDataObjectExtension",
referenceDescriptor);
DatabaseMapping databaseMapping = classDescriptor.getMappingForAttributeName("extension");
assertNotNull("extension mapping missing from metamodel", databaseMapping);
assertTrue("Should be a OneToOne mapping", databaseMapping instanceof OneToOneMapping);
OneToOneMapping mapping = (OneToOneMapping)databaseMapping;
assertEquals("Should be mapped by primaryKeyProperty", "primaryKeyProperty", mapping.getMappedBy());
Map<DatabaseField, DatabaseField> databaseFields = mapping.getSourceToTargetKeyFields();
assertEquals(1, databaseFields.size());
for (DatabaseField sourceField : databaseFields.keySet()) {
DatabaseField targetField = databaseFields.get(sourceField);
assertEquals("PK_PROP", sourceField.getName());
assertEquals("PK_PROP", targetField.getName());
}
assertNotNull("Reference descriptor missing from relationship", mapping.getReferenceDescriptor());
assertEquals("Reference descriptor should be the one for TestDataObjectExtension", referenceDescriptor,
mapping.getReferenceDescriptor());
assertNotNull("selection query relationship missing", mapping.getSelectionQuery());
assertNotNull("selection query missing name", mapping.getSelectionQuery().getName());
assertEquals("selection query name incorrect", "extension", mapping.getSelectionQuery().getName());
assertNotNull("selection query reference class", mapping.getSelectionQuery().getReferenceClass());
assertEquals("selection query reference class incorrect", TestDataObjectExtension.class,
mapping.getSelectionQuery().getReferenceClass());
assertNotNull("selection query reference class name", mapping.getSelectionQuery().getReferenceClassName());
assertNotNull("selection query source mapping missing", mapping.getSelectionQuery().getSourceMapping());
assertEquals("selection query source mapping incorrect", mapping,
mapping.getSelectionQuery().getSourceMapping());
}
示例13: camelCaseToUnderscore
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
private void camelCaseToUnderscore(Vector<DatabaseMapping> mappings) {
for (DatabaseMapping mapping : mappings) {
DatabaseField field = mapping.getField();
if (mapping.isDirectToFieldMapping() && !mapping.isPrimaryKeyMapping()) {
String attributeName = mapping.getAttributeName();
String underScoredFieldName = camelCaseToUnderscore(attributeName);
field.setName(underScoredFieldName);
}
}
}
示例14: customize
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的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);
}
}
}
}
}
}
}
示例15: buildRelationTableDefinition
import org.eclipse.persistence.internal.helper.DatabaseField; //导入依赖的package包/类
/**
* Build relation table definitions for all many-to-many relationships in a
* EclipseLink descriptor.
*/
protected void buildRelationTableDefinition(ManagedClass managedClass, Attribute managedAttribute, LinkedList<Entity> intrinsicEntity, LinkedList<Attribute> intrinsicAttribute, boolean isInherited, ForeignReferenceMapping mapping, RelationTableMechanism relationTableMechanism, DatabaseField listOrderField, ContainerPolicy cp) {
//first create relation table
TableDefinition table = getTableDefFromDBTable(managedClass, managedAttribute, intrinsicEntity, relationTableMechanism.getRelationTable());
//add source foreign key fields into the relation table
List<DatabaseField> srcFkFields = relationTableMechanism.getSourceRelationKeyFields();//Relation Table
List<DatabaseField> srcKeyFields = relationTableMechanism.getSourceKeyFields();//Entity(Owner) Table
buildRelationTableFields(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, false, isInherited, mapping, table, srcFkFields, srcKeyFields);
//add target foreign key fields into the relation table
List<DatabaseField> targFkFields = relationTableMechanism.getTargetRelationKeyFields();//Relation Table
List<DatabaseField> targKeyFields = relationTableMechanism.getTargetKeyFields();//Entity(MappedBy) Table
// attribute.getConnectedAttribute()
buildRelationTableFields(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, true, isInherited, mapping, table, targFkFields, targKeyFields);
if (cp != null) {
addFieldsForMappedKeyMapContainerPolicy(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, cp, table);
}
if (listOrderField != null) {
FieldDefinition fieldDef = getFieldDefFromDBField(listOrderField);
if (!table.getFields().contains(fieldDef)) {
table.addField(fieldDef);
}
}
}