Package com.nexirius.framework.jdbc

Examples of com.nexirius.framework.jdbc.DatabaseTableMapping


        String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/jnex/testDatabase.mdb;DriverID=22;READONLY=true}"; // add on to the end

        JdbcConnectionHandler.init(new JdbcConnectionHandler(database, null, null));

        //DatabaseTableMapping itemMapping = DatabaseTableMapping.createStandardMapping(new ItemModel());
        DatabaseTableMapping itemMapping = new DatabaseTableMapping(ItemModel.FIELD_NAME, "PK",
                new String[]{ItemModel.FIELD_booleanField,
                             ItemModel.FIELD_dateField,
                             ItemModel.FIELD_doubleField,
                             ItemModel.FIELD_intField,
                             ItemModel.FIELD_stringField,
                             ItemModel.FIELD_timeField,
                             ItemSubStructure.FIELD_NAME + DataModel.FIELD_NAME_SEPARATOR_CHAR + ItemSubStructure.FIELD_s1,
                             ItemSubStructure.FIELD_NAME + DataModel.FIELD_NAME_SEPARATOR_CHAR + ItemSubStructure.FIELD_s2,
                             ItemSubStructure.FIELD_NAME + DataModel.FIELD_NAME_SEPARATOR_CHAR + ItemSubStructure.FIELD_bool,
                             ItemSubStructure.FIELD_NAME + DataModel.FIELD_NAME_SEPARATOR_CHAR + ItemSubStructure.FIELD_combo,
                },

                new String[]{ItemModel.FIELD_booleanField,
                             ItemModel.FIELD_dateField,
                             ItemModel.FIELD_doubleField,
                             ItemModel.FIELD_intField,
                             ItemModel.FIELD_stringField,
                             ItemModel.FIELD_timeField,
                             ItemSubStructure.FIELD_s1,
                             ItemSubStructure.FIELD_s2,
                             ItemSubStructure.FIELD_bool,
                             ItemSubStructure.FIELD_combo,
                }
        );

        itemMapping.registerTranslator(new DatabaseFieldTranslator() {
            public StringVector getFieldList() {
                return new StringVector(new String[] {ItemModel.FIELD_comboBoxField});
            }

            public void setModelValues(DatabaseTableMapping mapping, JnexPreparedStatement statement, int indexOfFirstField, DataModel model) {
View Full Code Here


        JdbcConnectionHandler.instance().registerDatabaseTableMapping(ItemModel.class.getName(), itemMapping);
    }

    public static void save(ItemArrayModel array) throws Exception {
        DatabaseTableMapping m = JdbcConnectionHandler.instance().getDatabaseTableMapping(ItemModel.class.getName());
        DataModelEnumeration en = array.getEnumeration();
        DataModelVector remove = new DataModelVector();

        while (en.hasMore()) {
            ItemModel model = (ItemModel) en.next();

            if (model.getFlag(ModelFlag.DELETED)) {
                if (model.getInstanceName() == null) {
                    m.delete(model);
                }

                remove.append(model);
            } else {
                if (model.getInstanceName() == null) {
                    m.create(model);
                } else {
                    m.update(model);
                }
            }
        }

        for (DataModel model = remove.firstItem(); model != null; model = remove.nextItem()) {
View Full Code Here

            array.removeItem(model);
        }
    }

    public static void load(ItemArrayModel array) throws Exception {
        DatabaseTableMapping m = JdbcConnectionHandler.instance().getDatabaseTableMapping(ItemModel.class.getName());

        m.search(null, new ItemModel(), array);
    }
View Full Code Here

        m.search(null, new ItemModel(), array);
    }

    public static void saveItem(ItemModel model) throws Exception {
        DatabaseTableMapping m = JdbcConnectionHandler.instance().getDatabaseTableMapping(ItemModel.class.getName());

        if (model.getInstanceName() == null) {
            m.create(model);
        } else {
            m.update(model);
        }
    }
View Full Code Here

            m.update(model);
        }
    }

    public static void remove(DataModel model) throws Exception {
        DatabaseTableMapping m = JdbcConnectionHandler.instance().getDatabaseTableMapping(ItemModel.class.getName());

        m.delete(model);
    }
View Full Code Here

        String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + filename + ";DriverID=22;READONLY=true}";

        JdbcConnectionHandler.init(new JdbcConnectionHandler(database, null, null));

        DatabaseTableMapping memberMapping = new DatabaseTableMapping("MEMBER", "PK", new String[] {"personId", "type"}, new String[] {"PERSON_ID", "TYPE"});
        JdbcConnectionHandler.instance().registerDatabaseTableMapping(MemberModel.class.getName(), memberMapping);

        DatabaseTableMapping personMapping = new DatabaseTableMapping("PERSON", "PK", new String[] {"name", "firstname", "birthdate"}, new String[] {"NAME_", "FIRSTNAME", "BIRTHDATE"});
        JdbcConnectionHandler.instance().registerDatabaseTableMapping(PersonModel.class.getName(), personMapping);

        DatabaseTableMapping addressMapping = new DatabaseTableMapping("ADDRESS", "PK", new String[] {"street", "zip", "city", "state", AddressModel.FIELD_MAIN_ADDRESS}, new String[] {"STREET", "ZIP", "CITY", "STATE", "MAIN"});
        addressMapping.setForeignKeyField("FK_MEMBER");
        JdbcConnectionHandler.instance().registerDatabaseTableMapping(AddressModel.class.getName(), addressMapping);

        DatabaseTableMapping phoneMapping = new DatabaseTableMapping("PHONE", "PK", new String[] {"description", "number"}, new String[] {"DESCRIPTION", "NUMBER_"});
        phoneMapping.setForeignKeyField("FK_MEMBER");
        JdbcConnectionHandler.instance().registerDatabaseTableMapping(PhoneModel.class.getName(), phoneMapping);
    }
View Full Code Here

        phoneMapping.setForeignKeyField("FK_MEMBER");
        JdbcConnectionHandler.instance().registerDatabaseTableMapping(PhoneModel.class.getName(), phoneMapping);
    }

    public void getAllMembers(ArrayModel members) {
        DatabaseTableMapping mapping = JdbcConnectionHandler.instance().getDatabaseTableMapping(MemberModel.class.getName());
        DatabaseTableMapping personMapping = JdbcConnectionHandler.instance().getDatabaseTableMapping(PersonModel.class.getName());
        DatabaseTableMapping addressMapping = JdbcConnectionHandler.instance().getDatabaseTableMapping(AddressModel.class.getName());
        DatabaseTableMapping phoneMapping = JdbcConnectionHandler.instance().getDatabaseTableMapping(PhoneModel.class.getName());

        try {
            mapping.search(null, new MemberModel(), members);

            DataModelEnumeration en = members.getEnumeration();

            while (en.hasMore()) {
                MemberModel member = (MemberModel) en.next();
                PersonModel person = member.getPerson();

                person.setInstanceName(member.getPersonId());
                personMapping.read(person);

                addressMapping.readChildren(member.getAddresses());
                phoneMapping.readChildren(member.getPhones());
            }

        } catch (Exception e) {
            e.printStackTrace()//TODO
        }
View Full Code Here

            e.printStackTrace()//TODO
        }
    }

    public void update(DataModel model) {
        DatabaseTableMapping mapping = JdbcConnectionHandler.instance().getDatabaseTableMapping(model.getClass().getName());

        try {
            mapping.updateIfDirty(model);
        } catch (Exception e) {
            e.printStackTrace()//TODO
        }
    }
View Full Code Here

        }
    }

    public void updateChildren(DataModel parent, ArrayModel children) {
        if (children.getSize() > 0) {
            DatabaseTableMapping mapping = JdbcConnectionHandler.instance().getDatabaseTableMapping(children.getDataModel(0).getClass().getName());

            try {
                mapping.updateChildrenIfDirty(children);
            } catch (Exception e) {
                e.printStackTrace()//TODO
            }
        }
    }
View Full Code Here

            }
        }
    }

    public void create(DataModel model) {
        DatabaseTableMapping mapping = JdbcConnectionHandler.instance().getDatabaseTableMapping(model.getClass().getName());

        try {
            mapping.create(model);
        } catch (Exception e) {
            e.printStackTrace()//TODO
        }
    }
View Full Code Here

TOP

Related Classes of com.nexirius.framework.jdbc.DatabaseTableMapping

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.