Search in sources :

Example 11 with Engine

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

the class SelectRowDialog method showModal.

public List<com.ramussoft.pb.Row> showModal() {
    final Qualifier q1 = qualifier;
    selectedRows.clear();
    createComponents();
    if (q1 != null) {
        Options.saveOptions(this);
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                qualifierView.setSelectedQualifier(q1);
                Options.loadOptions(SelectRowDialog.this);
                addQualifier = false;
            }
        });
    }
    ok = false;
    setVisible(true);
    deleteComponents();
    List<com.ramussoft.pb.Row> result = new ArrayList<com.ramussoft.pb.Row>();
    if (ok) {
        for (List<Row> list : selectedRows.values()) {
            for (Row row : list) {
                com.ramussoft.pb.Row r = dataPlugin.findRowByGlobalId(row.getElementId());
                if (r != null)
                    result.add(r);
            }
        }
        if ((addQualifier) && (qualifier != null)) {
            Engine engine = dataPlugin.getEngine();
            Qualifier q = StandardAttributesPlugin.getQualifiersQualifier(engine);
            List<Element> list = engine.getElements(q.getId());
            for (Element element : list) {
                if (qualifier.equals(StandardAttributesPlugin.getQualifier(engine, element))) {
                    com.ramussoft.pb.Row r = dataPlugin.findRowByGlobalId(element.getId());
                    if (r != null) {
                        result.add(r);
                    } else {
                        System.err.println("WARNING: Can not find element for qualifier (" + qualifier.getName() + ")");
                    }
                }
            }
        }
    }
    Options.saveOptions(this);
    return result;
}
Also used : Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier) Row(com.ramussoft.database.common.Row) Engine(com.ramussoft.common.Engine)

Example 12 with Engine

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

the class FileNavigator method tryLoadFile.

private void tryLoadFile() {
    File file = new File(fileName);
    if (file.lastModified() > lastModified) {
        closeModel();
        try {
            tmpFile = File.createTempFile("navigator-file-copy", null);
            FileInputStream fis = new FileInputStream(file);
            FileOutputStream fos = new FileOutputStream(tmpFile);
            copyStream(fis, fos);
            fis.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        MemoryDatabase database = new MemoryDatabase() {

            @Override
            protected File getFile() {
                return tmpFile;
            }
        };
        Engine engine = database.getEngine(null);
        AccessRules rules = database.getAccessRules(null);
        dataPlugin = NDataPluginFactory.getDataPlugin(null, engine, rules);
        lastModified = file.lastModified();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) MemoryDatabase(com.ramussoft.database.MemoryDatabase) AccessRules(com.ramussoft.common.AccessRules) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Engine(com.ramussoft.common.Engine)

Example 13 with Engine

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

the class Runner method recoverySession.

public boolean recoverySession(final String sessionPath, final File sourceFile) {
    Window rFrame = new Window(null);
    String recovering = GlobalResourcesManager.getString("File.Recovering");
    rFrame.add(new Label(MessageFormat.format(recovering, ((sourceFile == null) ? GlobalResourcesManager.getString("Session.NoName") : sourceFile.getName()))));
    rFrame.pack();
    rFrame.setLocationRelativeTo(null);
    rFrame.setVisible(true);
    final String s = sessionPath + File.separator + "source.rms";
    MemoryDatabase database = new MemoryDatabase() {

        @Override
        protected Collection<? extends PluginProvider> getAdditionalSuits() {
            ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
            initAdditionalPluginSuits(ps);
            return ps;
        }

        @Override
        protected File getFile() {
            File file = new File(s);
            if (file.exists())
                return file;
            return null;
        }

        protected FileIEngineImpl createFileIEngine(PluginFactory factory) throws ClassNotFoundException, ZipException, IOException {
            return new FileIEngineImpl(0, template, factory, sessionPath);
        }
    };
    final Engine engine = database.getEngine(null);
    DirectoryJournalFactory factory = database.getJournalFactory();
    Journal[] journals = factory.loadJournals(database.getJournaledEngine());
    if (journals.length == 0)
        return false;
    boolean exist = false;
    Journal.RedoCallback redoCallback = new Journal.RedoCallback() {

        boolean hadStartUserTransaction;

        @Override
        public boolean execute(Command command) {
            if (command instanceof StartUserTransactionCommand) {
                hadStartUserTransaction = true;
            }
            return hadStartUserTransaction;
        }
    };
    for (Journal journal : journals) {
        try {
            Command command = null;
            while (journal.canRedo()) {
                command = journal.redo(redoCallback);
            }
            if ((journal.getPointer() == 0l) || (command instanceof StopUndoPointCommand)) {
                rFrame.setVisible(false);
                continue;
            } else
                exist = true;
            if (!(command instanceof EndUserTransactionCommand))
                throw new Exception();
        } catch (Exception e) {
            e.printStackTrace();
            while (journal.canUndo()) {
                if (journal.undo() instanceof StartUserTransactionCommand)
                    break;
            }
        }
    }
    if (!exist) {
        try {
            ((FileIEngineImpl) engine.getDeligate()).close();
            for (Journal journal : journals) journal.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
    ((FileIEngineImpl) engine.getDeligate()).recoveryStreams();
    engine.setPluginProperty(CORE, "Changed", Boolean.TRUE);
    engine.setActiveBranch(-1l);
    final AccessRules accessor = database.getAccessRules(null);
    rFrame.setVisible(false);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            SplashScreen screen = new SplashScreen() {

                /**
                 */
                private static final long serialVersionUID = -2727237354089088151L;

                @Override
                protected String getImageName() {
                    return Runner.this.getSplashImageName();
                }
            };
            screen.setLocationRelativeTo(null);
            screen.setVisible(true);
            final JFrame frame = openInNewWindows(engine, accessor, sourceFile, true);
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    String recovered = GlobalResourcesManager.getString("File.Recovered");
                    frame.setTitle(frame.getTitle() + " " + recovered);
                }
            });
            screen.setVisible(false);
        }
    };
    recoveredCount++;
    Thread thread = new Thread(runnable);
    thread.start();
    return true;
}
Also used : Label(java.awt.Label) ArrayList(java.util.ArrayList) Journal(com.ramussoft.common.journal.Journal) JFrame(javax.swing.JFrame) SplashScreen(com.ramussoft.gui.common.SplashScreen) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) GUIPluginFactory(com.ramussoft.gui.core.GUIPluginFactory) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) Window(java.awt.Window) DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) StopUndoPointCommand(com.ramussoft.common.journal.StopUndoPointCommand) PluginProvider(com.ramussoft.common.PluginProvider) IOException(java.io.IOException) ZipException(java.util.zip.ZipException) FileMinimumVersionException(com.ramussoft.core.impl.FileMinimumVersionException) IOException(java.io.IOException) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) Command(com.ramussoft.common.journal.command.Command) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) StopUndoPointCommand(com.ramussoft.common.journal.StopUndoPointCommand) MemoryDatabase(com.ramussoft.database.MemoryDatabase) AccessRules(com.ramussoft.common.AccessRules) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 14 with Engine

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

the class Runner method openFile.

private void openFile(File file) {
    saveFileToHistory(file);
    MemoryDatabase database = createDatabase(file);
    Engine engine = database.getEngine(null);
    AccessRules accessor = database.getAccessRules(null);
    openInNewWindows(engine, accessor, file, false);
}
Also used : MemoryDatabase(com.ramussoft.database.MemoryDatabase) AccessRules(com.ramussoft.common.AccessRules) Engine(com.ramussoft.common.Engine)

Example 15 with Engine

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

the class OwnersConnection method getConnected.

@Override
public Rows getConnected(final Data data, Row row) {
    Integer type = (Integer) row.getAttribute(IDEF0Plugin.getFunctionTypeAttribute(row.getEngine()));
    if (type != null && type.intValue() == 1003) {
        Long id = (Long) row.getAttribute(IDEF0Plugin.getLinkAttribute(row.getEngine()));
        Rows rows = new Rows(row.getRowSet(), data, false);
        if (id != null) {
            Row row2 = data.findRow(id);
            if (row2 != null) {
                List<AnyToAnyPersistent> list = (List) row2.getAttribute(IDEF0Plugin.getStreamAddedAttribute(row2.getEngine()));
                for (AnyToAnyPersistent anyPersistent : list) {
                    Row row3 = data.findRow(anyPersistent.getOtherElement());
                    row3.setElementStatus(anyPersistent.getElementStatus());
                    rows.add(row3);
                }
            }
        }
        return rows;
    }
    OwnersConnection connection = (OwnersConnection) data.get("OunersConnection");
    if (connection != null)
        return connection.getOuners(data, row);
    final Engine engine = data.getEngine();
    ArrayList<Long> ounerQualifierIds = loadOunerIDs(engine);
    owners = new Hashtable<Row, List<Row>>();
    final Attribute ounerAttribute = IDEF0Plugin.getFunctionOunerAttribute(engine);
    final Hashtable<Row, List<Row>> mech = new Hashtable<Row, List<Row>>();
    RowMapper mapper = new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            RowSet rowSet = data.getRowSet(rs.getLong(1));
            Row row = (Row) rowSet.findRow(rs.getLong(2));
            if (row == null)
                return null;
            Long o = (Long) row.getAttribute(ounerAttribute);
            if (o != null) {
                Element element = engine.getElement(o);
                if (element != null) {
                    RowSet ounerRowSet = data.getRowSet(element.getQualifierId());
                    Row owner = (Row) ounerRowSet.findRow(o);
                    if (row == null || owner == null)
                        return null;
                    mech.put(row, Arrays.asList(owner));
                }
                return null;
            }
            RowSet ounerRowSet = data.getRowSet(rs.getLong(3));
            Row ouner = (Row) ounerRowSet.findRow(rs.getLong(4));
            if (row == null || ouner == null)
                return null;
            List<Row> l = mech.get(row);
            if (l == null) {
                l = new ArrayList<Row>(2);
                mech.put(row, l);
            }
            if (!l.contains(ouner))
                l.add(ouner);
            return null;
        }
    };
    if (ounerQualifierIds.size() > 0) {
        data.getTemplate().queryWithoutResults("SELECT b.qualifier_id, function, ramus_elements.qualifier_id, ramus_elements.element_id FROM\n" + "ramus_attribute_sector_borders, ramus_attribute_other_elements, ramus_attribute_any_to_any_elements, ramus_elements, ramus_elements b\n" + "WHERE ramus_attribute_any_to_any_elements.element_id=ramus_attribute_other_elements.other_element\n" + "AND ramus_elements.element_id=ramus_attribute_any_to_any_elements.other_element\n" + "AND ramus_attribute_sector_borders.element_id = ramus_attribute_other_elements.element_id\n" + "AND function_type=1 AND ramus_attribute_sector_borders.attribute_id in\n" + "(SELECT attribute_id FROM ramus_attributes WHERE attribute_system=true AND attribute_name='F_SECTOR_BORDER_END')\n" + "AND b.element_id=function\n" + "AND ramus_elements.qualifier_id in " + toIns(ounerQualifierIds), mapper, true);
    }
    try {
        data.getTemplate().queryWithoutResults("SELECT (SELECT qualifier_id FROM ramus_elements WHERE element_id=ouner_id) as function_qualifier_id, " + "ouner_id AS function,  " + "(SELECT qualifier_id FROM ramus_elements WHERE element_id=other_element) as ouner_qualifier_id, " + "other_element as ouner_id FROM ramus_attribute_any_to_any_elements, ramus_attribute_function_ouners " + "WHERE ramus_attribute_any_to_any_elements.element_id IN " + "(SELECT value FROM ramus_attribute_longs WHERE ramus_attribute_longs.element_id=ramus_attribute_function_ouners.element_id)", mapper, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    data.getTemplate().queryWithoutResults("SELECT ramus_attribute_function_ouners.element_id,\n" + "(SELECT MAX(ramus_elements.qualifier_id) FROM ramus_elements WHERE ramus_elements.element_id=ramus_attribute_function_ouners.element_id),\n" + "ramus_elements.qualifier_id,\n" + " ouner_id FROM ramus_elements, ramus_attribute_function_ouners WHERE ramus_elements.element_id=ouner_id " + "AND ramus_attribute_function_ouners.ouner_id IN (SELECT element_id FROM ramus_attribute_function_types WHERE type<1001)", new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            RowSet rowSet = data.getRowSet(rs.getLong(2));
            Row row = (Row) rowSet.findRow(rs.getLong(1));
            RowSet ounerRowSet = data.getRowSet(rs.getLong(3));
            Row ouner = (Row) ounerRowSet.findRow(rs.getLong(4));
            if (ouner != null && row != null) {
                List<Row> l = mech.get(row);
                if (l == null) {
                    l = new ArrayList<Row>(2);
                    mech.put(row, l);
                }
                if (!l.contains(ouner))
                    l.add(ouner);
            }
            return null;
        }
    }, true);
    RowSet rowSet = data.getRowSet(row.getQualifier());
    setRecOuners(rowSet.getRoot(), mech, null);
    data.put("OunersConnection", this);
    return getOuners(data, row);
}
Also used : Attribute(com.ramussoft.common.Attribute) SQLException(java.sql.SQLException) Element(com.ramussoft.common.Element) RowSet(com.ramussoft.report.data.RowSet) ArrayList(java.util.ArrayList) AnyToAnyPersistent(com.ramussoft.idef0.attribute.AnyToAnyPersistent) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Engine(com.ramussoft.common.Engine) Rows(com.ramussoft.report.data.Rows) RowMapper(com.ramussoft.jdbc.RowMapper) Hashtable(java.util.Hashtable) IOException(java.io.IOException) InvalidPropertiesFormatException(java.util.InvalidPropertiesFormatException) SQLException(java.sql.SQLException) DataException(com.ramussoft.report.data.DataException) Row(com.ramussoft.report.data.Row)

Aggregations

Engine (com.ramussoft.common.Engine)85 Attribute (com.ramussoft.common.Attribute)32 ArrayList (java.util.ArrayList)30 Element (com.ramussoft.common.Element)27 Qualifier (com.ramussoft.common.Qualifier)22 AccessRules (com.ramussoft.common.AccessRules)21 List (java.util.List)19 IEngine (com.ramussoft.common.IEngine)15 Row (com.ramussoft.database.common.Row)13 IOException (java.io.IOException)11 SQLException (java.sql.SQLException)11 PluginFactory (com.ramussoft.common.PluginFactory)8 PluginProvider (com.ramussoft.common.PluginProvider)8 Journaled (com.ramussoft.common.journal.Journaled)8 CachedEngine (com.ramussoft.common.cached.CachedEngine)7 Hashtable (java.util.Hashtable)7 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)6 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)5 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)5 MemoryDatabase (com.ramussoft.database.MemoryDatabase)5