Search in sources :

Example 1 with Qualifier

use of com.ramussoft.common.persistent.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class PersistentFactory method checkClass.

protected void checkClass(ClassLoader classLoader, Class<?> p, String pluginName, String typeName) {
    PersistentWrapper wrapper = new PersistentWrapper(p);
    Table table = p.getAnnotation(Table.class);
    String className = p.getName();
    PersistentRow row = getRow(className);
    if (row == null) {
        row = new PersistentRow(classLoader);
        rows.add(row);
    } else
        row.setClassLoader(classLoader);
    row.setClassName(className);
    row.setExists(true);
    row.setPluginName(pluginName);
    fillTable(table, row, p);
    if (table != null)
        row.setTableType(table.type().ordinal());
    row.setTypeName(typeName);
    String[] fields = wrapper.getFields();
    fields = Arrays.copyOf(fields, fields.length + 1);
    String valueBranchId = "valueBranchId";
    fields[fields.length - 1] = valueBranchId;
    for (String fieldName : fields) {
        String databaseField = wrapper.toDatabaseField(fieldName);
        PersistentField field = getField(row, databaseField);
        if (field == null) {
            field = new PersistentField();
            row.getFields().add(field);
        }
        int type = wrapper.getAnnotationType(fieldName);
        if (valueBranchId.equals(fieldName)) {
            field.setAutoset(true);
            field.setFieldId(-2);
            field.setPrimary(true);
            field.setDefaultValue("0");
        } else {
            Class<? extends Annotation> annotation = PersistentWrapper.ANNOTATIONS[type];
            if (Attribute.class.isAssignableFrom(annotation)) {
                Attribute attr = wrapper.getAnnotation(fieldName, Attribute.class);
                field.setAutoset(attr.autoset());
                field.setFieldId(attr.id());
                field.setPrimary(attr.primary());
            } else if (Element.class.isAssignableFrom(annotation)) {
                Element attr = wrapper.getAnnotation(fieldName, Element.class);
                field.setAutoset(attr.autoset());
                field.setFieldId(attr.id());
                field.setPrimary(attr.primary());
            } else if (com.ramussoft.common.persistent.Long.class.isAssignableFrom(annotation)) {
                com.ramussoft.common.persistent.Long attr = wrapper.getAnnotation(fieldName, com.ramussoft.common.persistent.Long.class);
                field.setFieldId(attr.id());
                field.setPrimary(attr.primary());
                if (attr.setDefaultValue()) {
                    field.setDefaultValue(Long.toString(attr.defaultValue()));
                }
            } else if (com.ramussoft.common.persistent.Double.class.isAssignableFrom(annotation)) {
                com.ramussoft.common.persistent.Double attr = wrapper.getAnnotation(fieldName, com.ramussoft.common.persistent.Double.class);
                field.setFieldId(attr.id());
                field.setPrimary(attr.primary());
            } else if (Date.class.isAssignableFrom(annotation)) {
                Date attr = wrapper.getAnnotation(fieldName, Date.class);
                field.setFieldId(attr.id());
                field.setPrimary(attr.primary());
            } else if (Text.class.isAssignableFrom(annotation)) {
                Text attr = wrapper.getAnnotation(fieldName, Text.class);
                field.setFieldId(attr.id());
                field.setPrimary(attr.primary());
            } else if (Id.class.isAssignableFrom(annotation)) {
                Id attr = wrapper.getAnnotation(fieldName, Id.class);
                field.setFieldId(attr.id());
                field.setPrimary(true);
                field.setAutoset(true);
            } else if (Qualifier.class.isAssignableFrom(annotation)) {
                Qualifier attr = wrapper.getAnnotation(fieldName, Qualifier.class);
                field.setFieldId(attr.id());
                field.setPrimary(attr.primary());
            } else if (Binary.class.isAssignableFrom(annotation)) {
                Binary binary = wrapper.getAnnotation(fieldName, Binary.class);
                field.setFieldId(binary.id());
            } else if (com.ramussoft.common.persistent.Integer.class.isAssignableFrom(annotation)) {
                com.ramussoft.common.persistent.Integer integer = wrapper.getAnnotation(fieldName, com.ramussoft.common.persistent.Integer.class);
                field.setFieldId(integer.id());
                field.setPrimary(integer.primary());
            } else {
                throw new RuntimeException("Unknown annotation class: " + annotation.getName());
            }
        }
        field.setDatabaseName(databaseField);
        field.setType(type);
        field.setName(fieldName);
    }
}
Also used : Table(com.ramussoft.common.persistent.Table) PersistentField(com.ramussoft.common.persistent.PersistentField) PersistentRow(com.ramussoft.common.persistent.PersistentRow) Attribute(com.ramussoft.common.attribute.Attribute) Element(com.ramussoft.common.persistent.Element) Text(com.ramussoft.common.persistent.Text) Date(com.ramussoft.common.persistent.Date) Qualifier(com.ramussoft.common.persistent.Qualifier) Id(com.ramussoft.common.persistent.Id) Binary(com.ramussoft.common.persistent.Binary) PersistentWrapper(com.ramussoft.common.persistent.PersistentWrapper)

Example 2 with Qualifier

use of com.ramussoft.common.persistent.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class UniversalPersistentFactory method checkClass.

@Override
protected void checkClass(ClassLoader classLoader, Class<?> p, String pluginName, String typeName) {
    PersistentWrapper wrapper = new PersistentWrapper(p);
    Table table = p.getAnnotation(Table.class);
    String className = p.getName();
    PersistentRow row = getRow(className);
    if (row == null) {
        row = new PersistentRow(classLoader);
        rows.add(row);
    } else
        row.setClassLoader(classLoader);
    row.setClassName(className);
    row.setExists(true);
    row.setPluginName(pluginName);
    fillTable(table, row, p);
    if (table != null)
        row.setTableType(table.type().ordinal());
    row.setTypeName(typeName);
    String[] fields = wrapper.getFields();
    for (String fieldName : fields) {
        String databaseField = wrapper.toDatabaseField(fieldName);
        PersistentField field = getField(row, databaseField);
        if (field == null) {
            field = new PersistentField();
            row.getFields().add(field);
        }
        int type = wrapper.getAnnotationType(fieldName);
        Class<? extends Annotation> annotation = PersistentWrapper.ANNOTATIONS[type];
        if (Attribute.class.isAssignableFrom(annotation)) {
            Attribute attr = wrapper.getAnnotation(fieldName, Attribute.class);
            field.setAutoset(attr.autoset());
            field.setFieldId(attr.id());
            field.setPrimary(attr.primary());
        } else if (Element.class.isAssignableFrom(annotation)) {
            Element attr = wrapper.getAnnotation(fieldName, Element.class);
            field.setAutoset(attr.autoset());
            field.setFieldId(attr.id());
            field.setPrimary(attr.primary());
        } else if (com.ramussoft.common.persistent.Long.class.isAssignableFrom(annotation)) {
            com.ramussoft.common.persistent.Long attr = wrapper.getAnnotation(fieldName, com.ramussoft.common.persistent.Long.class);
            field.setFieldId(attr.id());
            field.setPrimary(attr.primary());
            if (attr.setDefaultValue()) {
                field.setDefaultValue(Long.toString(attr.defaultValue()));
            }
        } else if (com.ramussoft.common.persistent.Double.class.isAssignableFrom(annotation)) {
            com.ramussoft.common.persistent.Double attr = wrapper.getAnnotation(fieldName, com.ramussoft.common.persistent.Double.class);
            field.setFieldId(attr.id());
            field.setPrimary(attr.primary());
        } else if (Date.class.isAssignableFrom(annotation)) {
            Date attr = wrapper.getAnnotation(fieldName, Date.class);
            field.setFieldId(attr.id());
            field.setPrimary(attr.primary());
        } else if (Text.class.isAssignableFrom(annotation)) {
            Text attr = wrapper.getAnnotation(fieldName, Text.class);
            field.setFieldId(attr.id());
            field.setPrimary(attr.primary());
        } else if (Id.class.isAssignableFrom(annotation)) {
            Id attr = wrapper.getAnnotation(fieldName, Id.class);
            field.setFieldId(attr.id());
            field.setPrimary(true);
            field.setAutoset(true);
        } else if (Qualifier.class.isAssignableFrom(annotation)) {
            Qualifier attr = wrapper.getAnnotation(fieldName, Qualifier.class);
            field.setFieldId(attr.id());
            field.setPrimary(attr.primary());
        } else if (Binary.class.isAssignableFrom(annotation)) {
            Binary binary = wrapper.getAnnotation(fieldName, Binary.class);
            field.setFieldId(binary.id());
        } else if (com.ramussoft.common.persistent.Integer.class.isAssignableFrom(annotation)) {
            com.ramussoft.common.persistent.Integer integer = wrapper.getAnnotation(fieldName, com.ramussoft.common.persistent.Integer.class);
            field.setFieldId(integer.id());
            field.setPrimary(integer.primary());
        } else {
            throw new RuntimeException("Unknown annotation class: " + annotation.getName());
        }
        field.setDatabaseName(databaseField);
        field.setType(type);
        field.setName(fieldName);
    }
}
Also used : Table(com.ramussoft.common.persistent.Table) PersistentField(com.ramussoft.common.persistent.PersistentField) PersistentRow(com.ramussoft.common.persistent.PersistentRow) Attribute(com.ramussoft.common.attribute.Attribute) Element(com.ramussoft.common.persistent.Element) Text(com.ramussoft.common.persistent.Text) Date(com.ramussoft.common.persistent.Date) Qualifier(com.ramussoft.common.persistent.Qualifier) Id(com.ramussoft.common.persistent.Id) Binary(com.ramussoft.common.persistent.Binary) PersistentWrapper(com.ramussoft.common.persistent.PersistentWrapper)

Aggregations

Attribute (com.ramussoft.common.attribute.Attribute)2 Binary (com.ramussoft.common.persistent.Binary)2 Date (com.ramussoft.common.persistent.Date)2 Element (com.ramussoft.common.persistent.Element)2 Id (com.ramussoft.common.persistent.Id)2 PersistentField (com.ramussoft.common.persistent.PersistentField)2 PersistentRow (com.ramussoft.common.persistent.PersistentRow)2 PersistentWrapper (com.ramussoft.common.persistent.PersistentWrapper)2 Qualifier (com.ramussoft.common.persistent.Qualifier)2 Table (com.ramussoft.common.persistent.Table)2 Text (com.ramussoft.common.persistent.Text)2