use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class TransformationMappingErrorTestCases method testNoClassForFieldTransformation.
public void testNoClassForFieldTransformation() {
ClassDescriptor descriptor = context.getSession(0).getDescriptor(Employee.class);
XMLTransformationMapping mapping = new XMLTransformationMapping();
mapping.setDescriptor(descriptor);
// mapping.addFieldTransformerClassName("/normal-hours/start-time", "this.is.a.DummyClass");
DescriptorException expected = DescriptorException.fieldTransformerClassNotFound("dummy_class_name", mapping, new Exception());
try {
mapping.initialize((AbstractSession) context.getSession(0));
} catch (DescriptorException ex) {
assertTrue("The incorrect exception was thrown. [Expected] " + expected + " [Found] " + ex, ex.getErrorCode() == expected.getErrorCode());
}
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class TransformationMappingErrorTestCases method testInvalidClassForFieldTransformation.
public void testInvalidClassForFieldTransformation() {
ClassDescriptor descriptor = context.getSession(0).getDescriptor(Employee.class);
XMLTransformationMapping mapping = new XMLTransformationMapping();
mapping.setDescriptor(descriptor);
mapping.addFieldTransformerClassName("/normal-hours/start-time", "org.eclipse.persistence.testing.oxm.mappings.transformation.Employee");
DescriptorException expected = DescriptorException.fieldTransformerClassInvalid("dummy_class_name", mapping, new Exception());
try {
mapping.initialize((AbstractSession) context.getSession(0));
} catch (DescriptorException ex) {
assertTrue("The incorrect exception was thrown. [Expected] " + expected + " [Found] " + ex, ex.getErrorCode() == expected.getErrorCode());
}
}
use of org.eclipse.persistence.exceptions.DescriptorException in project VaadinUtils by rlsutton1.
the class ViolationConstraintHandler method handleConstraintViolationException.
/**
* digs down looking for a useful exception, it will throw a runtime
* exception if it finds an useful exception
*
* @param e
* @param nestLimit
*/
private static void handleConstraintViolationException(Throwable e, int nestLimit) {
if (nestLimit > 0 && e != null) {
nestLimit--;
if (e instanceof DescriptorException) {
DescriptorException desc = (DescriptorException) e;
throw new RuntimeException(desc.getMessage());
}
if (e instanceof ConstraintViolationException) {
String groupedViolationMessage = e.getClass().getSimpleName() + " ";
for (ConstraintViolation<?> violation : ((ConstraintViolationException) e).getConstraintViolations()) {
logger.error("{}", violation.getLeafBean().getClass().getCanonicalName());
String violationMessage = violation.getLeafBean().getClass().getSimpleName() + " " + violation.getPropertyPath() + " " + violation.getMessage() + ", the value was " + violation.getInvalidValue();
logger.error(violationMessage);
groupedViolationMessage += violationMessage + "\n";
}
throw new RuntimeException(groupedViolationMessage);
}
handleConstraintViolationException(e.getCause(), nestLimit);
}
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class QueryOperation method initialize.
@Override
public void initialize(XRServiceAdapter xrService) {
super.initialize(xrService);
if (queryHandler == null) {
// session query instead of named query
DatabaseQuery dq = xrService.getORSession().getQuery(name);
if (dq != null) {
queryHandler = new QueryHandler() {
@Override
public void initializeDatabaseQuery(XRServiceAdapter xrService, QueryOperation queryOperation) {
// do nothing
}
@Override
public void initializeArguments(XRServiceAdapter xrService, QueryOperation queryOperation, DatabaseQuery databaseQuery) {
// do nothing
}
@Override
public void initializeCall(XRServiceAdapter xrService, QueryOperation queryOperation, DatabaseQuery databaseQuery) {
// do nothing
}
};
queryHandler.setDatabaseQuery(dq);
}
}
if (queryHandler == null) {
throw DBWSException.couldNotLocateQueryForSession(name, xrService.getORSession().getName());
}
queryHandler.initialize(xrService, this);
Session oxSession = xrService.getOXSession();
QName resultType = result == null ? null : result.getType();
addSimpleXMLFormatModelDescriptor(xrService);
addValueObjectDescriptor(xrService);
if (resultType == null) {
if (isAttachment()) {
Attachment attachment = result.getAttachment();
XMLDescriptor descriptor = (XMLDescriptor) oxSession.getProject().getClassDescriptor(DataHandler.class);
if (descriptor == null) {
descriptor = new XMLDescriptor();
descriptor.setAlias(DATAHANDLER_STR);
descriptor.setJavaClass(DataHandler.class);
descriptor.setInstantiationPolicy(new DataHandlerInstantiationPolicy(attachment.getMimeType()));
XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName(RESULTS_STR);
mapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) throws DescriptorException {
Object result = null;
DataHandler dataHandler = (DataHandler) object;
try {
result = dataHandler.getContent();
if (result instanceof InputStream) {
try (InputStream is = (InputStream) result) {
byte[] buf = new byte[2048];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int bytesRead = is.read(buf);
while (bytesRead >= 0) {
baos.write(buf, 0, bytesRead);
bytesRead = is.read(buf);
}
result = baos.toByteArray();
}
}
} catch (IOException e) {
// ignore
}
return result;
}
@Override
public void setAttributeValueInObject(Object object, Object value) throws DescriptorException {
}
});
mapping.setXPath(DEFAULT_SIMPLE_XML_FORMAT_TAG + SLASH_CHAR + DEFAULT_SIMPLE_XML_TAG + ATTACHMENT_STR);
mapping.setSwaRef(true);
mapping.setShouldInlineBinaryData(false);
mapping.setMimeType(attachment.getMimeType());
descriptor.addMapping(mapping);
NamespaceResolver nr = new NamespaceResolver();
descriptor.setNamespaceResolver(nr);
oxSession.getProject().addDescriptor(descriptor);
((DatabaseSessionImpl) oxSession).initializeDescriptorIfSessionAlive(descriptor);
xrService.getXMLContext().storeXMLDescriptorByQName(descriptor);
}
}
}
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class EntityTypeFromDescriptor method invalidDescriptorWithoutEntityType.
/**
* Verify that the descriptor for a dynamic type fails without the
* additional configuration which is applied to the descriptor during the
* EntityType creation.
*/
@Test
public void invalidDescriptorWithoutEntityType() throws Exception {
RelationalDescriptor descriptor = buildMyEntityDescriptor();
DatabaseSession session = createSession();
session.addDescriptor(descriptor);
try {
session.login();
} catch (IntegrityException ie) {
assertEquals(descriptor.getMappings().size(), ie.getIntegrityChecker().getCaughtExceptions().size());
// Verify NoSuchField errors for each mapping
for (int index = 0; index < descriptor.getMappings().size(); index++) {
DescriptorException ex = (DescriptorException) ie.getIntegrityChecker().getCaughtExceptions().get(index);
assertEquals(DescriptorException.NO_SUCH_FIELD_WHILE_INITIALIZING_ATTRIBUTES_IN_INSTANCE_VARIABLE_ACCESSOR, ex.getErrorCode());
}
return;
}
fail("Expected IntegrityException not thrown");
}
Aggregations