public static EISException createException(Object[] args, int errorCode) { EISException exception = new EISException( ExceptionMessageGenerator.buildMessage(EISException.class, errorCode, args)); exception.setErrorCode(errorCode); return exception; }
public static EISException incorrectLoginInstanceProvided(Class loginClass) { Object[] args = {loginClass}; EISException exception = new EISException( ExceptionMessageGenerator.buildMessage( EISException.class, INCORRECT_LOGIN_INSTANCE_PROVIDED, args)); exception.setErrorCode(INCORRECT_LOGIN_INSTANCE_PROVIDED); return exception; }
public static EISException resourceException( Exception resourceException, EISAccessor accessor, AbstractSession session) { EISException exception = new EISException(resourceException); exception.setErrorCode(RESOURCE_EXCEPTION); exception.setInternalException(resourceException); exception.setAccessor(accessor); exception.setSession(session); return exception; }
public static EISException createResourceException(Object[] args, int errorCode) { ResourceException resourceException = new ResourceException( ExceptionMessageGenerator.buildMessage(EISException.class, errorCode, args)); EISException exception = new EISException(resourceException); exception.setErrorCode(RESOURCE_EXCEPTION); exception.setInternalException(resourceException); return exception; }
public static EISException resourceException( ResourceException resourceException, Call call, EISAccessor accessor, AbstractSession session) { EISException exception = resourceException(resourceException, accessor, session); exception.setCall(call); return exception; }
/** * Return the provider version * * @return the JMS provider version * @throws EISException */ public String getEISProductVersion() throws EISException { try { return connection.getConnection().getMetaData().getProviderVersion(); } catch (Exception exception) { throw EISException.createException(exception); } }
/** Output records are not supported/required. */ public boolean execute(InteractionSpec spec, Record input, Record output) throws ResourceException { if (!(spec instanceof MongoInteractionSpec)) { throw EISException.invalidInteractionSpecType(); } if (!(input instanceof MongoRecord) || !(output instanceof MongoRecord)) { throw EISException.invalidRecordType(); } MongoInteractionSpec mongoSpec = (MongoInteractionSpec) spec; MongoRecord record = (MongoRecord) input; MongoRecord translationRecord = (MongoRecord) output; MongoOperation operation = mongoSpec.getOperation(); String collectionName = mongoSpec.getCollection(); if (operation == null) { throw new ResourceException("Mongo operation must be set"); } if (collectionName == null) { throw new ResourceException("DB Collection name must be set"); } try { DBCollection collection = this.connection.getDB().getCollection(collectionName); DBObject object = buildDBObject(record); DBObject translation = buildDBObject(translationRecord); if (operation == MongoOperation.UPDATE) { WriteResult result = collection.update(translation, object, mongoSpec.isUpsert(), mongoSpec.isMulti()); return result.getN() > 0; } else { throw new ResourceException("Invalid operation: " + operation); } } catch (Exception exception) { ResourceException resourceException = new ResourceException(exception.toString()); resourceException.initCause(exception); throw resourceException; } }
/** INTERNAL: Initialize the mapping. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); if (!this.hasCustomSelectionQuery()) { throw DescriptorException.operationNotSupported("customSelectionQueryRequired"); } if ((this.getForeignKeyGroupingElement() == null) && (this.getSourceForeignKeysToTargetKeys().size() > 1)) { throw EISException.groupingElementRequired(); } if (this.getForeignKeyGroupingElement() != null) { DatabaseField field = this.getDescriptor().buildField(this.getForeignKeyGroupingElement()); setForeignKeyGroupingElement((XMLField) field); } this.initializeSourceForeignKeysToTargetKeys(); this.initializeDeleteAllQuery(); }
public static EISException propertyNotSet(String property) { return EISException.createException(new Object[] {property}, PROP_NOT_SET); }
public static EISException couldNotDeleteFile(Object[] args) { return EISException.createResourceException(args, COULD_NOT_DELETE_FILE); }
public static EISException groupingElementRequired() { return EISException.createException(new Object[] {}, GROUPING_ELEMENT_REQUIRED); }
public static EISException transactedSessionTestError() { return EISException.createException(new Object[] {}, TX_SESSION_TEST_ERROR); }
public static EISException invalidMethodInvocation() { return EISException.createException(new Object[] {}, INVALID_METHOD_INVOCATION); }
public static EISException timeoutOccurred() { return EISException.createException(new Object[] {}, TIMEOUT); }
public static EISException unsupportedMessageInInputRecord() { return EISException.createException(new Object[] {}, INPUT_UNSUPPORTED_MSG_TYPE); }
public static EISException invalidInput() { return EISException.createException(new Object[] {}, INVALID_INPUT); }
/** * Execute the interaction and return output record. The spec is either GET, PUT or DELETE * interaction. */ public Record execute(InteractionSpec spec, Record record) throws ResourceException { if (!(spec instanceof MongoInteractionSpec)) { throw EISException.invalidInteractionSpecType(); } if (!(record instanceof MongoRecord)) { throw EISException.invalidRecordType(); } MongoInteractionSpec mongoSpec = (MongoInteractionSpec) spec; MongoRecord input = (MongoRecord) record; MongoOperation operation = mongoSpec.getOperation(); String collectionName = mongoSpec.getCollection(); if (operation == null) { ResourceException resourceException = new ResourceException("Mongo operation must be set"); throw resourceException; } if (operation == MongoOperation.EVAL) { Object result = this.connection.getDB().eval(mongoSpec.getCode()); return buildRecordFromDBObject((DBObject) result); } if (collectionName == null) { ResourceException resourceException = new ResourceException("DB Collection name must be set"); throw resourceException; } try { DBCollection collection = this.connection.getDB().getCollection(collectionName); if (mongoSpec.getOptions() > 0) { collection.setOptions(mongoSpec.getOptions()); } if (mongoSpec.getReadPreference() != null) { collection.setReadPreference(mongoSpec.getReadPreference()); } if (mongoSpec.getWriteConcern() != null) { collection.setWriteConcern(mongoSpec.getWriteConcern()); } if (operation == MongoOperation.INSERT) { DBObject object = buildDBObject(input); collection.insert(object); } else if (operation == MongoOperation.REMOVE) { DBObject object = buildDBObject(input); collection.remove(object); } else if (operation == MongoOperation.FIND) { DBObject sort = null; if (input.containsKey(MongoRecord.SORT)) { sort = buildDBObject((MongoRecord) input.get(MongoRecord.SORT)); input.remove(MongoRecord.SORT); } DBObject select = null; if (input.containsKey("$select")) { select = buildDBObject((MongoRecord) input.get("$select")); input.remove("$select"); } DBObject object = buildDBObject(input); DBCursor cursor = collection.find(object, select); if (sort != null) { cursor.sort(sort); } try { if (mongoSpec.getSkip() > 0) { cursor.skip(mongoSpec.getSkip()); } if (mongoSpec.getLimit() != 0) { cursor.limit(mongoSpec.getLimit()); } if (mongoSpec.getBatchSize() != 0) { cursor.batchSize(mongoSpec.getBatchSize()); } if (!cursor.hasNext()) { return null; } MongoListRecord results = new MongoListRecord(); while (cursor.hasNext()) { DBObject result = cursor.next(); results.add(buildRecordFromDBObject(result)); } return results; } finally { cursor.close(); } } else { throw new ResourceException("Invalid operation: " + operation); } } catch (Exception exception) { ResourceException resourceException = new ResourceException(exception.toString()); resourceException.initCause(exception); throw resourceException; } return null; }
public static EISException propertiesNotSet(String property1, String property2) { return EISException.createException(new Object[] {property1, property2}, PROPS_NOT_SET); }
public static EISException invalidAQRecordType() { return EISException.createResourceException(new Object[] {}, INVALID_AQ_RECORD_TYPE); }
public static EISException invalidAQInteractionSpecType() { return EISException.createResourceException(new Object[] {}, INVALID_AQ_INTERACTION_SPEC_TYPE); }
public static EISException noConnectionFactorySpecified() { return EISException.createException(new Object[] {}, NO_CONN_FACTORY); }
public static EISException invalidAQInput() { return EISException.createResourceException(new Object[] {}, INVALID_AQ_INPUT); }
public static EISException unknownInteractionSpecType() { return EISException.createException(new Object[] {}, UNKNOWN_INTERACTION_SPEC_TYPE); }
public static EISException invalidProperty(String property) { return EISException.createException(new Object[] {property}, INVALID_PROP); }
public static EISException createException(Exception ex) { EISException exception = new EISException(ex); exception.setErrorCode(EIS_EXCEPTION); return exception; }
public static EISException invalidConnectionFactoryAttributes() { return EISException.createResourceException(new Object[] {}, INVALID_FACTORY_ATTRIBUTES); }