Package org.apache.s4.schema.Schema

Examples of org.apache.s4.schema.Schema.Property


            if (debug) {
                System.out.println("Using fast path!");
            }
            fastPath = true;
            KeyInfo keyInfo = new KeyInfo();
            Property property = schema.getProperties().get(simpleKeyName);
            if (property == null) {
                return null;
            }

            Object value = null;
            try {
                value = property.getGetterMethod().invoke(event);
            } catch (Exception e) {
                if (debug) {
                    e.printStackTrace();
                }
            }
View Full Code Here


                                       List<String> keyNameElements,
                                       int elementIndex,
                                       List<KeyInfo> keyInfoList,
                                       KeyInfo keyInfo) {
        String keyElement = keyNameElements.get(elementIndex);
        Property property = schema.getProperties().get(keyElement);
        if (property == null) {
            return null;
        }

        keyInfo.addElementToPath(keyElement);

        Object value = null;
        try {
            value = property.getGetterMethod().invoke(record);
        } catch (Exception e) {
            if (debug) {
                System.out.println("key element is " + keyElement);
                e.printStackTrace();
            }
        }

        if (value == null) {
            return null; // return a null KeyInfo list if we hit a null value
        }
        if (property.isList()) {
            List list = (List) value;
            // TODO: handle case where key does not include property of
            // component type
            Schema componentSchema = property.getComponentProperty()
                                             .getSchema();
            int listLength = list.size();
            for (int i = 0; i < listLength; i++) {
                Object listEntry = list.get(i);
                KeyInfo keyInfoForListEntry = keyInfo.copy();
                keyInfoForListEntry.addElementToPath(i);
                Object partialList = getKeyValues(listEntry,
                                                  componentSchema,
                                                  keyNameElements,
                                                  elementIndex + 1,
                                                  keyInfoList,
                                                  keyInfoForListEntry);
                if (partialList == null) {
                    return null;
                }
            }
        } else if (property.getSchema() != null) {
            return getKeyValues(value,
                                property.getSchema(),
                                keyNameElements,
                                elementIndex + 1,
                                keyInfoList,
                                keyInfo);
        } else {
View Full Code Here

        }
    }

    private void copyField(String propertyName, Schema sourceSchema,
                           Schema targetSchema, Object source, Object target) {
        Property sourceProperty = sourceSchema.getProperties()
                                              .get(propertyName);
        Property targetProperty = targetSchema.getProperties()
                                              .get(propertyName);

        if (sourceProperty == null || targetProperty == null
                || !sourceProperty.getType().equals(targetProperty.getType())) {
            throw new RuntimeException("Specified property " + propertyName
                    + " doesn't exist or is not consistent");
        }

        try {
            Object sourceValue = sourceProperty.getGetterMethod()
                                               .invoke(source);
            if (sourceValue == null) {
                return;
            }
            if (sourceProperty.getType().isPrimitive()) {
                if (sourceValue instanceof Number) {
                    if (((Number) sourceValue).doubleValue() == 0.0) {
                        return;
                    }
                }
                if (sourceValue instanceof Boolean) {
                    if (((Boolean) sourceValue).equals(Boolean.FALSE)) {
                        return;
                    }
                }
            }
            targetProperty.getSetterMethod().invoke(target, sourceValue);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

        long maybeCurrentTime = -1;
        if (timestampFields != null) {
            Schema schema = schemaContainer.getSchema(event.getClass());
            String fieldName = timestampFields.get(getStreamName());
            if (fieldName != null) {
                Property property = schema.getProperties().get(fieldName);
                if (property != null
                        && (property.getType().equals(Long.TYPE) || property.getType()
                                                                            .equals(Long.class))) {
                    try {
                        maybeCurrentTime = (Long) property.getGetterMethod()
                                                          .invoke(event);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
View Full Code Here

        // get the value for each keyInfo
        for (KeyInfo keyInfo : compoundKeyInfo.getKeyInfoList()) {
            Object value = null;
            Object record = event;
            List<?> list = null;
            Property property = null;
            for (KeyPathElement keyPathElement : keyInfo.getKeyPath()) {
                if (keyPathElement instanceof KeyPathElementIndex) {
                    record = list.get(((KeyPathElementIndex) keyPathElement).getIndex());
                    schema = property.getComponentProperty().getSchema();
                } else {
                    String keyPathElementName = ((KeyPathElementName) keyPathElement).getKeyName();
                    property = schema.getProperties().get(keyPathElementName);
                    value = null;
                    try {
                        value = property.getGetterMethod().invoke(record);
                    } catch (Exception e) {
                        Logger.getLogger("s4").error(e);
                        return;
                    }

                    if (value == null) {
                        Logger.getLogger("s4").error("Value for "
                                + keyPathElementName + " is null!");
                        return;
                    }

                    if (property.getType().isPrimitive() || property.isNumber()
                            || property.getType().equals(String.class)) {
                        keyValue.add(value);
                        if (saveKeyRecord) {
                            if (keyRecord == null) {
                                keyRecord = new ArrayList<Object>();
                            }
                            keyRecord.add(record);
                        }
                        continue;
                    } else if (property.isList()) {
                        try {
                            list = (List) property.getGetterMethod()
                                                  .invoke(record);
                        } catch (Exception e) {
                            Logger.getLogger("s4").error(e);
                            return;
                        }
                    } else {
                        try {
                            record = property.getGetterMethod().invoke(record);
                        } catch (Exception e) {
                            Logger.getLogger("s4").error(e);
                            return;
                        }
                        schema = property.getSchema();
                    }
                }
            }
        }
    }
View Full Code Here

            event = schema.getType().newInstance();

            for (Iterator it = jsonRecord.keys(); it.hasNext();) {
                String propertyName = (String) it.next();

                Property property = schema.getProperties().get(propertyName);

                if (property == null) {
                    continue; // not in schema, just continue
                }

                Method setterMethod = property.getSetterMethod();
                Object value = jsonRecord.get(propertyName);
                if (value.equals(JSONObject.NULL)) {
                    continue;
                }
View Full Code Here

        return null;
    }

    public Object makeList(Property property, JSONArray jsonArray) {
        Property componentProperty = property.getComponentProperty();

        int size = jsonArray.length();

        List<Object> list = new ArrayList<Object>(size);
View Full Code Here

        return list;
    }

    @SuppressWarnings("unchecked")
    public Object makeArray(Property property, JSONArray jsonArray) {
        Property componentProperty = property.getComponentProperty();
        Class clazz = componentProperty.getType();

        int size = jsonArray.length();

        Object array = Array.newInstance(clazz, size);
View Full Code Here

        String streamName = eventWrapper.getStreamName();
        String fieldName = eventClockStreamsMap.get(streamName);
        if (fieldName != null) {
            Object event = eventWrapper.getEvent();
            Schema schema = schemaContainer.getSchema(event.getClass());
            Property property = schema.getProperties().get(fieldName);
            if (property != null
                    && (property.getType().equals(Long.TYPE) || property
                            .getType().equals(Long.class))) {
                try {
                    eventTime = (Long) property.getGetterMethod().invoke(event);
                    updateTime(eventTime);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
View Full Code Here

        String results = new String(zk.getData("/results", false, null));
        Assert.assertEquals("be=2;da=2;doobie=5;not=1;or=1;to=2;", results);
    }

    public void injectSentence(String sentence) throws IOException {
        Event event = new Event();
        event.put("sentence", String.class, sentence);
        emitter.send(0, new EventMessage("-1", "inputStream", injector.getInstance(SerializerDeserializer.class)
                .serialize(event)));
    }
View Full Code Here

TOP

Related Classes of org.apache.s4.schema.Schema.Property

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.