本文整理汇总了Java中org.apache.olingo.commons.api.edm.EdmKeyPropertyRef类的典型用法代码示例。如果您正苦于以下问题:Java EdmKeyPropertyRef类的具体用法?Java EdmKeyPropertyRef怎么用?Java EdmKeyPropertyRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EdmKeyPropertyRef类属于org.apache.olingo.commons.api.edm包,在下文中一共展示了EdmKeyPropertyRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findPropertyRefValue
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
private Object findPropertyRefValue(Entity entity, EdmKeyPropertyRef refType) {
final int INDEX_ERROR_CODE = -1;
final String propertyPath = refType.getName();
String tmpPropertyName;
int lastIndex;
int index = propertyPath.indexOf('/');
if (index == INDEX_ERROR_CODE) {
index = propertyPath.length();
}
tmpPropertyName = propertyPath.substring(0, index);
//get first property
Property prop = entity.getProperty(tmpPropertyName);
//get following properties
while (index < propertyPath.length()) {
lastIndex = ++index;
index = propertyPath.indexOf('/', index+1);
if (index == INDEX_ERROR_CODE) {
index = propertyPath.length();
}
tmpPropertyName = propertyPath.substring(lastIndex, index);
prop = findProperty(tmpPropertyName, prop.asComplex().getValue());
}
return prop.getValue();
}
示例2: checkBaseType
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
@Override
protected void checkBaseType() {
if (!baseTypeChecked) {
if (baseTypeName != null) {
baseType = buildBaseType(baseTypeName);
entityBaseType = (EdmEntityType) baseType;
}
if (baseType == null
|| (baseType.isAbstract() && ((EdmEntityType) baseType).getKeyPropertyRefs().isEmpty())) {
final List<CsdlPropertyRef> key = entityType.getKey();
if (key != null) {
final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>();
for (CsdlPropertyRef ref : key) {
edmKey.add(new EdmKeyPropertyRefImpl(this, ref));
}
setEdmKeyPropertyRef(edmKey);
}
}
baseTypeChecked = true;
}
}
示例3: keyBehaviour
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
@Test
public void keyBehaviour() {
List<String> keyPredicateNames = baseType.getKeyPredicateNames();
assertEquals(1, keyPredicateNames.size());
assertEquals("Id", keyPredicateNames.get(0));
EdmKeyPropertyRef keyPropertyRef = baseType.getKeyPropertyRef("Id");
assertNotNull(keyPropertyRef);
assertEquals("Id", keyPropertyRef.getName());
assertNull(keyPropertyRef.getAlias());
EdmProperty keyProperty = keyPropertyRef.getProperty();
assertNotNull(keyProperty);
assertEquals(baseType.getProperty("Id"), keyProperty);
List<EdmKeyPropertyRef> keyPropertyRefs = baseType.getKeyPropertyRefs();
assertNotNull(keyPropertyRefs);
assertEquals(1, keyPropertyRefs.size());
assertEquals("Id", keyPropertyRefs.get(0).getName());
}
示例4: keyBehaviourWithBasetype
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
@Test
public void keyBehaviourWithBasetype() {
List<String> keyPredicateNames = typeWithBaseType.getKeyPredicateNames();
assertEquals(1, keyPredicateNames.size());
assertEquals("Id", keyPredicateNames.get(0));
EdmKeyPropertyRef keyPropertyRef = typeWithBaseType.getKeyPropertyRef("Id");
assertNotNull(keyPropertyRef);
assertEquals("Id", keyPropertyRef.getName());
assertNull(keyPropertyRef.getAlias());
List<EdmKeyPropertyRef> keyPropertyRefs = typeWithBaseType.getKeyPropertyRefs();
assertNotNull(keyPropertyRefs);
assertEquals(1, keyPropertyRefs.size());
assertEquals("Id", keyPropertyRefs.get(0).getName());
for (int i = 0; i < keyPropertyRefs.size(); i++) {
assertEquals(keyPropertyRefs.get(i).getName(), typeWithBaseType.getKeyPropertyRefs().get(i).getName());
}
}
示例5: aliasForPropertyInComplexPropertyOneLevel
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
@Test
public void aliasForPropertyInComplexPropertyOneLevel() {
CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/Id").setAlias("alias");
EdmEntityType etMock = mock(EdmEntityType.class);
EdmProperty keyPropertyMock = mock(EdmProperty.class);
EdmProperty compMock = mock(EdmProperty.class);
EdmComplexType compTypeMock = mock(EdmComplexType.class);
when(compTypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock);
when(compMock.getType()).thenReturn(compTypeMock);
when(etMock.getStructuralProperty("comp")).thenReturn(compMock);
EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
assertEquals("alias", ref.getAlias());
EdmProperty property = ref.getProperty();
assertNotNull(property);
assertTrue(property == keyPropertyMock);
}
示例6: aliasForPropertyInComplexPropertyTwoLevels
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
@Test
public void aliasForPropertyInComplexPropertyTwoLevels() {
CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/comp2/Id").setAlias("alias");
EdmEntityType etMock = mock(EdmEntityType.class);
EdmProperty keyPropertyMock = mock(EdmProperty.class);
EdmProperty compMock = mock(EdmProperty.class);
EdmComplexType compTypeMock = mock(EdmComplexType.class);
EdmProperty comp2Mock = mock(EdmProperty.class);
EdmComplexType comp2TypeMock = mock(EdmComplexType.class);
when(comp2TypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock);
when(comp2Mock.getType()).thenReturn(comp2TypeMock);
when(compTypeMock.getStructuralProperty("comp2")).thenReturn(comp2Mock);
when(compMock.getType()).thenReturn(compTypeMock);
when(etMock.getStructuralProperty("comp")).thenReturn(compMock);
EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
EdmProperty property = ref.getProperty();
assertNotNull(property);
assertTrue(property == keyPropertyMock);
}
示例7: keyPropertyGuidStartsWithNumber
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
@Test
public void keyPropertyGuidStartsWithNumber() throws Exception {
final String entitySetName = "ESGuid";
final String keyPropertyName = "a";
EdmProperty keyProperty = Mockito.mock(EdmProperty.class);
Mockito.when(keyProperty.getType())
.thenReturn(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Guid));
EdmKeyPropertyRef keyPropertyRef = Mockito.mock(EdmKeyPropertyRef.class);
Mockito.when(keyPropertyRef.getName()).thenReturn(keyPropertyName);
Mockito.when(keyPropertyRef.getProperty()).thenReturn(keyProperty);
EdmEntityType entityType = Mockito.mock(EdmEntityType.class);
Mockito.when(entityType.getKeyPredicateNames()).thenReturn(Collections.singletonList(keyPropertyName));
Mockito.when(entityType.getKeyPropertyRefs()).thenReturn(Collections.singletonList(keyPropertyRef));
Mockito.when(entityType.getPropertyNames()).thenReturn(Collections.singletonList(keyPropertyName));
Mockito.when(entityType.getProperty(keyPropertyName)).thenReturn(keyProperty);
EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
Mockito.when(entitySet.getName()).thenReturn(entitySetName);
Mockito.when(entitySet.getEntityType()).thenReturn(entityType);
EdmEntityContainer container = Mockito.mock(EdmEntityContainer.class);
Mockito.when(container.getEntitySet(entitySetName)).thenReturn(entitySet);
Edm mockedEdm = Mockito.mock(Edm.class);
Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
new TestUriValidator().setEdm(mockedEdm)
.run("ESGuid", "$filter=a eq 889e3e73-af9f-4cd4-b330-db93c25ff3c7");
}
示例8: keyValuePair
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
private static UriParameter keyValuePair(UriTokenizer tokenizer,
final String keyPredicateName, final EdmEntityType edmEntityType,
final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases)
throws UriParserException, UriValidationException {
final EdmKeyPropertyRef keyPropertyRef = edmEntityType.getKeyPropertyRef(keyPredicateName);
final EdmProperty edmProperty = keyPropertyRef == null ? null : keyPropertyRef.getProperty();
if (edmProperty == null) {
throw new UriValidationException(keyPredicateName + " is not a valid key property name.",
UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, keyPredicateName);
}
ParserHelper.requireNext(tokenizer, TokenKind.EQ);
if (tokenizer.next(TokenKind.COMMA) || tokenizer.next(TokenKind.CLOSE) || tokenizer.next(TokenKind.EOF)) {
throw new UriParserSyntaxException("Key value expected.", UriParserSyntaxException.MessageKeys.SYNTAX);
}
if (nextPrimitiveTypeValue(tokenizer, (EdmPrimitiveType) edmProperty.getType(), edmProperty.isNullable())) {
return createUriParameter(edmProperty, keyPredicateName, tokenizer.getText(), edm, referringType, aliases);
} else {
throw new UriParserSemanticException(keyPredicateName + " has not a valid key value.",
UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE, keyPredicateName);
}
}
示例9: appendKey
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
private void appendKey(final JsonGenerator json,
final EdmEntityType entityType) throws SerializerException, IOException {
List<EdmKeyPropertyRef> keyPropertyRefs = entityType.getKeyPropertyRefs();
if (keyPropertyRefs != null && !keyPropertyRefs.isEmpty()) {
// Resolve Base Type key as it is shown in derived type
EdmEntityType baseType = entityType.getBaseType();
if (baseType != null && baseType.getKeyPropertyRefs() != null && !(baseType.getKeyPropertyRefs().isEmpty())) {
return;
}
json.writeArrayFieldStart(KEY);
for (EdmKeyPropertyRef keyRef : keyPropertyRefs) {
if (keyRef.getAlias() != null) {
json.writeStartObject();
json.writeStringField(keyRef.getAlias(), keyRef.getName());
json.writeEndObject();
} else {
json.writeString(keyRef.getName());
}
}
json.writeEndArray();
}
}
示例10: appendKey
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
private void appendKey(final XMLStreamWriter writer, final EdmEntityType entityType) throws XMLStreamException {
List<EdmKeyPropertyRef> keyPropertyRefs = entityType.getKeyPropertyRefs();
if (keyPropertyRefs != null && !keyPropertyRefs.isEmpty()) {
// Resolve Base Type key as it is shown in derived type
EdmEntityType baseType = entityType.getBaseType();
if (baseType != null && baseType.getKeyPropertyRefs() != null && !(baseType.getKeyPropertyRefs().isEmpty())) {
return;
}
writer.writeStartElement(XML_KEY);
for (EdmKeyPropertyRef keyRef : keyPropertyRefs) {
writer.writeEmptyElement(XML_PROPERTY_REF);
writer.writeAttribute(XML_NAME, keyRef.getName());
if (keyRef.getAlias() != null) {
writer.writeAttribute(XML_ALIAS, keyRef.getAlias());
}
}
writer.writeEndElement();
}
}
示例11: createId
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
private static URI createId(String name, ResultSet rs, EdmEntityType edmEntityType) throws SQLException {
try {
List<EdmKeyPropertyRef> key = edmEntityType.getKeyPropertyRefs();
StringBuilder builder = new StringBuilder(name).append("(");
for(int i = 0; i< key.size(); i++ ){
builder.append(key.get(i).getName());
builder.append("=");
builder.append(rs.getObject(key.get(i).getName()));
if( i < key.size() - 1 ){
builder.append(",");
}
}
return new URI(URLEncoder.encode(builder.append(")").toString(),"UTF-8"));
} catch (URISyntaxException | UnsupportedEncodingException e) {
throw new ODataRuntimeException("Unable to create id for entity: " + name, e);
}
}
示例12: read
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
public Entity read(final EdmEntityType edmEntityType, final EntityCollection entitySet,
final List<UriParameter> keys) throws DataProviderException {
try {
for (final Entity entity : entitySet.getEntities()) {
boolean found = true;
for (final UriParameter key : keys) {
EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(key.getName());
Object value = findPropertyRefValue(entity, refType);
final EdmProperty property = refType.getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
if (key.getExpression() != null && !(key.getExpression() instanceof Literal)) {
throw new DataProviderException("Expression in key value is not supported yet!",
HttpStatusCode.NOT_IMPLEMENTED);
}
final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
final Object keyValue = type.valueOfString(type.fromUriLiteral(text),
property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
property.isUnicode(),
Calendar.class.isAssignableFrom(value.getClass()) ? Calendar.class : value.getClass());
if (!value.equals(keyValue)) {
found = false;
break;
}
}
if (found) {
return entity;
}
}
return null;
} catch (final EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
}
}
示例13: readDataFromEntity
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
public Entity readDataFromEntity(final EdmEntityType edmEntityType,
final List<UriParameter> keys) throws DataProviderException {
EntityCollection coll = data.get(edmEntityType.getName());
List<Entity> entities = coll.getEntities();
try {
for (final Entity entity : entities) {
boolean found = true;
for (final UriParameter key : keys) {
EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(key.getName());
Object value = findPropertyRefValue(entity, refType);
final EdmProperty property = refType.getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
if (key.getExpression() != null && !(key.getExpression() instanceof Literal)) {
throw new DataProviderException("Expression in key value is not supported yet!",
HttpStatusCode.NOT_IMPLEMENTED);
}
final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
final Object keyValue = type.valueOfString(type.fromUriLiteral(text),
property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
property.isUnicode(),
Calendar.class.isAssignableFrom(value.getClass()) ? Calendar.class : value.getClass());
if (!value.equals(keyValue)) {
found = false;
break;
}
}
if (found) {
return entity;
}
}
return null;
} catch (final EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
}
}
示例14: setBindingPropertyKeyNameAndValue
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
/**
* @param keyList
* @param edmEntitySet
* @param values
* @param propertyNames
* @throws DataProviderException
*/
private static void setBindingPropertyKeyNameAndValue(List<UriParameter> keyList, EdmEntitySet edmEntitySet,
List<Object> values, List<String> propertyNames) throws DataProviderException {
for (final UriParameter key : keyList) {
EdmKeyPropertyRef refType = edmEntitySet.getEntityType().getKeyPropertyRef(key.getName());
final EdmProperty property = refType.getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
try {
values.add(type.fromUriLiteral(key.getText()));
} catch (EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
}
propertyNames.add(key.getName());
}
}
示例15: setEdmKeyPropertyRef
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; //导入依赖的package包/类
protected void setEdmKeyPropertyRef(final List<EdmKeyPropertyRef> edmKey) {
for (EdmKeyPropertyRef ref : edmKey) {
if (ref.getAlias() == null) {
keyPredicateNames.add(ref.getName());
keyPropertyRefs.put(ref.getName(), ref);
} else {
keyPredicateNames.add(ref.getAlias());
keyPropertyRefs.put(ref.getAlias(), ref);
}
}
}