@SideEffectFree @SupportsBatching @SeeAlso(value=PutSQL.class) @InputRequirement(value=INPUT_REQUIRED) @Tags(value={"json","sql","database","rdbms","insert","update","delete","relational","flat"}) @CapabilityDescription(value="Converts a JSON-formatted FlowFile into an UPDATE, INSERT, or DELETE SQL statement. The incoming FlowFile is expected to be \"flat\" JSON message, meaning that it consists of a single JSON element and each field maps to a simple type. If a field maps to a JSON object, that JSON object will be interpreted as Text. If the input is an array of JSON elements, each element in the array is output as a separate FlowFile to the \'sql\' relationship. Upon successful conversion, the original FlowFile is routed to the \'original\' relationship and the SQL is routed to the \'sql\' relationship.") @WritesAttribute(attribute="mime.type",description="Sets mime.type of FlowFile that is routed to \'sql\' to \'text/plain\'.") @WritesAttribute(attribute="sql.table",description="Sets the sql.table attribute of FlowFile that is routed to \'sql\' to the name of the table that is updated by the SQL statement.") @WritesAttribute(attribute="sql.catalog",description="If the Catalog name is set for this database, specifies the name of the catalog that the SQL statement will update. If no catalog is used, this attribute will not be added.") @WritesAttribute(attribute="fragment.identifier",description="All FlowFiles routed to the \'sql\' relationship for the same incoming FlowFile (multiple will be output for the same incoming FlowFile if the incoming FlowFile is a JSON Array) will have the same value for the fragment.identifier attribute. This can then be used to correlate the results.") @WritesAttribute(attribute="fragment.count",description="The number of SQL FlowFiles that were produced for same incoming FlowFile. This can be used in conjunction with the fragment.identifier attribute in order to know how many FlowFiles belonged to the same incoming FlowFile.") @WritesAttribute(attribute="fragment.index",description="The position of this FlowFile in the list of outgoing FlowFiles that were all derived from the same incoming FlowFile. This can be used in conjunction with the fragment.identifier and fragment.count attributes to know which FlowFiles originated from the same incoming FlowFile and in what order the SQL FlowFiles were produced") @WritesAttribute(attribute="sql.args.N.type",description="The output SQL statements are parametrized in order to avoid SQL Injection Attacks. The types of the Parameters to use are stored in attributes named sql.args.1.type, sql.args.2.type, sql.args.3.type, and so on. The type is a number representing a JDBC Type constant. Generally, this is useful only for software to read and interpret but is added so that a processor such as PutSQL can understand how to interpret the values.") @WritesAttribute(attribute="sql.args.N.value",description="The output SQL statements are parametrized in order to avoid SQL Injection Attacks. The values of the Parameters to use are stored in the attributes named sql.args.1.value, sql.args.2.value, sql.args.3.value, and so on. Each of these attributes has a corresponding sql.args.N.type attribute that indicates how the value should be interpreted when inserting it into the database.") public class ConvertJSONToSQL extends AbstractProcessor
Constructor and Description |
---|
ConvertJSONToSQL() |
Modifier and Type | Method and Description |
---|---|
protected static java.lang.String |
createSqlStringValue(org.codehaus.jackson.JsonNode fieldNode,
java.lang.Integer colSize,
int sqlType)
Try to create correct SQL String representation of value.
|
java.util.Set<Relationship> |
getRelationships() |
protected java.util.List<PropertyDescriptor> |
getSupportedPropertyDescriptors()
Allows subclasses to register which property descriptor objects are
supported.
|
void |
onScheduled(ProcessContext context) |
void |
onTrigger(ProcessContext context,
ProcessSession session) |
onTrigger
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, init, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrue
customValidate, equals, getPropertyDescriptor, getPropertyDescriptors, getSupportedDynamicPropertyDescriptor, hashCode, onPropertyModified, validate
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getPropertyDescriptor, getPropertyDescriptors, onPropertyModified, validate
protected java.util.List<PropertyDescriptor> getSupportedPropertyDescriptors()
AbstractConfigurableComponent
getSupportedPropertyDescriptors
in class AbstractConfigurableComponent
public java.util.Set<Relationship> getRelationships()
getRelationships
in interface Processor
getRelationships
in class AbstractSessionFactoryProcessor
@OnScheduled public void onScheduled(ProcessContext context)
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException
onTrigger
in class AbstractProcessor
ProcessException
protected static java.lang.String createSqlStringValue(org.codehaus.jackson.JsonNode fieldNode, java.lang.Integer colSize, int sqlType)