Search in sources :

Example 6 with IEngineImpl

use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.

the class AnyToAnyPlugin method getElementsDeleteStatus.

@SuppressWarnings("unchecked")
@Override
public DeleteStatus getElementsDeleteStatus(long[] elementIds, final IEngine engine) {
    final HashMap<Long, Attribute> attributesCache = new HashMap<Long, Attribute>();
    final HashMap<Long, Qualifier> qualifiersCache = new HashMap<Long, Qualifier>();
    JDBCTemplate template = ((IEngineImpl) engine).getTemplate();
    String prefix = ((IEngineImpl) engine).getPrefix();
    StringBuffer sb = JDBCTemplate.toSqlArray(elementIds);
    String sql = "SELECT element_id FROM " + prefix + "attribute_any_to_any_elements WHERE other_element in(" + sb.toString() + ")";
    String gSQL;
    final List<String> functions = new ArrayList<String>();
    gSQL = "SELECT * FROM {0}elements WHERE element_id IN(" + "SELECT other_element FROM {0}attribute_other_elements WHERE element_id in(" + "SELECT element_id FROM {0}attribute_other_elements WHERE other_element in(" + sql + ")) " + "AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true)) ORDER BY element_name";
    template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
            if (elementName.trim().length() > 0 && !functions.contains(elementName))
                functions.add(elementName);
            return null;
        }
    }, new Object[] { IDEF0Plugin.F_SECTOR_FUNCTION }, true);
    gSQL = "SELECT * FROM {0}elements WHERE element_id IN(" + "SELECT other_element FROM {0}attribute_other_elements WHERE element_id in(" + "SELECT element_id FROM {0}attribute_other_elements WHERE other_element in(" + sb + ")) " + "AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true)) ORDER BY element_name";
    template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
            if (elementName.trim().length() > 0 && !functions.contains(elementName))
                functions.add(elementName);
            return null;
        }
    }, new Object[] { IDEF0Plugin.F_SECTOR_FUNCTION }, true);
    gSQL = "SELECT * FROM {0}elements WHERE element_id IN(SELECT parent_element_id FROM {0}attribute_hierarchicals WHERE element_id IN(" + "SELECT element_id FROM {0}attribute_longs WHERE value in(" + sql + ")AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true) " + ")) ORDER BY element_name";
    template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
            if (elementName.trim().length() > 0 && !functions.contains(elementName))
                functions.add(elementName);
            return null;
        }
    }, new Object[] { IDEF0Plugin.F_LINK }, true);
    if (functions.size() > 0) {
        Collections.sort(functions, new Comparator<String>() {

            @Override
            public int compare(String arg0, String arg1) {
                return StringCollator.compare(arg0, arg1);
            }
        });
        DeleteStatus deleteStatus = new DeleteStatus();
        deleteStatus.setPluginName(getName());
        StringBuffer buffer = new StringBuffer();
        for (String s : functions) if (!s.trim().equals("")) {
            buffer.append("<br>");
            buffer.append(s);
        }
        deleteStatus.setPluginAnswer("{Warning.ElementsUsedAtFunctions}" + buffer.toString());
        return deleteStatus;
    }
    return null;
}
Also used : Attribute(com.ramussoft.common.Attribute) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DeleteStatus(com.ramussoft.common.DeleteStatus) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) ResultSet(java.sql.ResultSet) Qualifier(com.ramussoft.common.Qualifier) RowMapper(com.ramussoft.jdbc.RowMapper)

Example 7 with IEngineImpl

use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.

the class HTTPParser method getReportHTMLText.

protected Source getReportHTMLText(Engine engine, Element report, Query query) {
    String page = null;
    try {
        HashMap<String, Object> map = new HashMap<String, Object>();
        ReportQuery impl;
        if (dataPlugin.getEngine().getDeligate() instanceof IEngineImpl)
            impl = new ReportQueryImpl(engine) {

                @Override
                protected Out createOut(OutputStream stream) {
                    try {
                        return new Out(stream) {

                            @Override
                            public void print(Object object) {
                                if (!printVersion) {
                                    if (object instanceof Qualifier) {
                                        Engine engine = dataPlugin.getEngine();
                                        Element element = StandardAttributesPlugin.getElement(engine, ((Qualifier) object).getId());
                                        if (element == null) {
                                            print(object.toString());
                                        } else {
                                            String href = "rows/index.html?id=" + element.getId();
                                            print(getStartATeg(href, false, true));
                                            print(object.toString());
                                            print(getEndATeg());
                                        }
                                    } else if (object instanceof Code) {
                                        String href = "rows/index.html?id=" + ((Code) object).getElement().getId();
                                        print(getStartATeg(href, false, true));
                                        print(object.toString());
                                        print(getEndATeg());
                                    } else if (object instanceof com.ramussoft.database.common.Row) {
                                        String href = "rows/index.html?id=" + ((com.ramussoft.database.common.Row) object).getElementId();
                                        print(getStartATeg(href, false, true));
                                        print(object.toString());
                                        print(getEndATeg());
                                    } else
                                        super.print(object);
                                } else
                                    super.print(object);
                            }
                        };
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                        throw new RuntimeException(e);
                    }
                }
            };
        else
            impl = (ReportQuery) dataPlugin.getEngine();
        if (query != null)
            map.put("query", query);
        page = impl.getHTMLReport(report, map);
    } catch (Exception e1) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        java.io.PrintStream s = null;
        try {
            s = new java.io.PrintStream(stream, true, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if (e1 instanceof DataException)
            s.println(((DataException) e1).getMessage(new MessageFormatter() {

                @Override
                public String getString(String key, Object[] arguments) {
                    return MessageFormat.format(ReportResourceManager.getString(key), arguments);
                }
            }));
        else {
            s.println("<pre>");
            e1.printStackTrace(s);
            s.println("</pre>");
        }
        s.flush();
        try {
            page = new String(stream.toByteArray(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        htmlStream.println(page);
        return null;
    }
    if (!printVersion) {
        htmlStream.println("<H4>" + report.getName() + "</H4>");
    }
    Source source = new Source(page);
    source.fullSequentialParse();
    htmlStream.println(source);
    return source;
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Element(com.ramussoft.common.Element) MessageFormatter(com.ramussoft.report.data.MessageFormatter) Source(net.htmlparser.jericho.Source) Qualifier(com.ramussoft.common.Qualifier) IEngine(com.ramussoft.common.IEngine) Engine(com.ramussoft.common.Engine) ReportQuery(com.ramussoft.report.ReportQuery) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Code(com.ramussoft.report.Code) DataException(com.ramussoft.report.data.DataException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ReportQueryImpl(com.ramussoft.report.ReportQueryImpl) Out(com.ramussoft.report.data.Out) DataException(com.ramussoft.report.data.DataException) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) Row(com.ramussoft.pb.Row) NRow(com.ramussoft.pb.data.negine.NRow)

Example 8 with IEngineImpl

use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.

the class InternetServer method run.

private void run(String[] args) throws IOException {
    new File(tmpPath).mkdirs();
    engineFactory = new EngineFactory() {
    };
    final ServerSocket ss = new ServerSocket();
    ss.bind(new InetSocketAddress("0.0.0.0", Metadata.INTERNET_PORT));
    userFactory = new UserFactoryImpl(engineFactory.getTemplate());
    serverAccessRules = new ServerAccessRules(engineFactory.getEngine(), userFactory) {

        @Override
        protected String getLogin() {
            return logins.get(Thread.currentThread());
        }
    };
    Thread acceptionThread = new Thread(new Runnable() {

        @Override
        public void run() {
            System.out.println("Ramus Interner Server ready");
            while (true) {
                try {
                    final Thread thread;
                    final Socket socket = ss.accept();
                    CheckableUserFactory userFactoryClient = new CheckableUserFactory(userFactory);
                    IntegrityAccessorSuit suit = new IntegrityAccessorSuit();
                    suit.addAccessRules(serverAccessRules);
                    suit.addAccessRules(((IEngineImpl) getEngine().getDeligate()).getAccessor());
                    final ClientServiceImpl service = new ClientServiceImpl(InternetServer.this, userFactory, userFactoryClient);
                    SuperInvoker invoker = new SuperInvoker(new Object[] { service, suit, userFactoryClient, service }, new Class[] { ClientService.class, AccessRules.class, UserFactory.class, UserProvider.class });
                    final TcpServerConnection connection = new TcpServerConnection(socket, new String[] { ClientService.class.getName(), AccessRules.class.getName(), UserFactory.class.getName(), UserProvider.class.getName() }, invoker.createProxy()) {

                        public void close() throws IOException {
                            synchronized (servicesLock) {
                                services.remove(service);
                            }
                            service.close();
                            super.close();
                        }
                    };
                    synchronized (servicesLock) {
                        services.add(service);
                    }
                    thread = new Thread(new Runnable() {

                        @Override
                        public void run() {
                            connection.run();
                        }
                    }, "server-client");
                    service.setConnection(connection);
                    thread.start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }, "inet-server-main");
    acceptionThread.start();
}
Also used : EngineFactory(com.ramussoft.server.EngineFactory) IntegrityAccessorSuit(com.ramussoft.core.impl.IntegrityAccessorSuit) ClientService(com.ramussoft.net.common.internet.ClientService) InetSocketAddress(java.net.InetSocketAddress) UserFactory(com.ramussoft.net.common.UserFactory) CheckableUserFactory(com.ramussoft.server.CheckableUserFactory) ServerSocket(java.net.ServerSocket) SuperInvoker(com.ramussoft.net.common.SuperInvoker) IOException(java.io.IOException) TcpServerConnection(com.ramussoft.server.TcpServerConnection) UserFactoryImpl(com.ramussoft.server.UserFactoryImpl) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) UserProvider(com.ramussoft.net.common.UserProvider) ServerAccessRules(com.ramussoft.server.ServerAccessRules) ServerAccessRules(com.ramussoft.server.ServerAccessRules) AccessRules(com.ramussoft.common.AccessRules) CheckableUserFactory(com.ramussoft.server.CheckableUserFactory) RedoObject(com.ramussoft.net.common.internet.RedoObject) UndoObject(com.ramussoft.net.common.internet.UndoObject) File(java.io.File) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Example 9 with IEngineImpl

use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.

the class InternetClient method load.

private void load(String dump, PluginFactory factory) throws Exception, FileNotFoundException, IOException, ZipException, InvalidPropertiesFormatException {
    new // to create all tables
    IEngineImpl(// to create all tables
    0, // to create all tables
    template, // to create all tables
    "ramus_", // to create all tables
    factory) {

        @Override
        protected void writeStream(String path, byte[] bytes) {
        }

        @Override
        public byte[] getStream(String path) {
            return null;
        }

        @Override
        protected boolean deleteStreamBytes(String path) {
            return false;
        }
    };
    template.execute("DELETE FROM {0}persistent_fields", "ramus_");
    template.execute("DELETE FROM {0}persistents", "ramus_");
    byte[] bs = (byte[]) connection.invoke("loadAllData", new Object[] {});
    File file = new File(dump);
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(bs);
    fos.close();
    bs = null;
    prefix = "ramus_";
    zFile = new ZipFile(file);
    ZipEntry entry = new ZipEntry(FileIEngineImpl.SEQUENCES);
    InputStream is = zFile.getInputStream(entry);
    Connection c = template.getConnection();
    try {
        if (is != null) {
            Properties ps = new Properties();
            ps.loadFromXML(is);
            Statement st = c.createStatement();
            Enumeration<Object> keys = ps.keys();
            while (keys.hasMoreElements()) {
                String key = (String) keys.nextElement();
                try {
                    st.execute("DROP SEQUENCE " + prefix + key + ";");
                } catch (SQLException e) {
                }
                st.execute("CREATE SEQUENCE " + prefix + key + " START " + ps.getProperty(key) + ";");
            }
            st.close();
            is.close();
        }
        c.commit();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    loadTable("", "qualifiers");
    loadTable("", "attributes");
    loadTable("", "qualifiers_attributes");
    loadTable("", "elements");
    loadTable("", "persistents");
    loadTable("", "persistent_fields");
    loadTable("", "application_preferencies");
    loadTable("", "streams");
    loadTable("", "formulas");
    loadTable("", "formula_dependences");
    openPersistentTables();
    zFile.close();
    zFile = null;
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) Statement(java.sql.Statement) ZipEntry(java.util.zip.ZipEntry) Connection(java.sql.Connection) Properties(java.util.Properties) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) ZipFile(java.util.zip.ZipFile) FileOutputStream(java.io.FileOutputStream) RedoObject(com.ramussoft.net.common.internet.RedoObject) UndoObject(com.ramussoft.net.common.internet.UndoObject) ZipFile(java.util.zip.ZipFile) BinaryAccessFile(com.ramussoft.common.journal.BinaryAccessFile) File(java.io.File)

Example 10 with IEngineImpl

use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.

the class DemoChecker method elementCreated.

@Override
public void elementCreated(ElementEvent event) {
    IEngineImpl impl = (IEngineImpl) event.getEngine().getDeligate();
    String prefix = impl.getPrefix();
    long elementCount = getElementCount(impl, prefix);
    if (elementCount > 100) {
        framework.propertyChanged("DisableSaveActions");
    }
    if ((elementCount == 101) && (framework.get("FilePlugin") != null)) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                JOptionPane.showMessageDialog(framework.getMainFrame(), MessageFormat.format(GlobalResourcesManager.getString("DemoVersionElementCountLimit"), 100));
            }
        });
    }
}
Also used : IEngineImpl(com.ramussoft.core.impl.IEngineImpl)

Aggregations

IEngineImpl (com.ramussoft.core.impl.IEngineImpl)14 SQLException (java.sql.SQLException)11 JDBCTemplate (com.ramussoft.jdbc.JDBCTemplate)8 ResultSet (java.sql.ResultSet)7 Qualifier (com.ramussoft.common.Qualifier)6 RowMapper (com.ramussoft.jdbc.RowMapper)6 Attribute (com.ramussoft.common.Attribute)5 Element (com.ramussoft.common.Element)5 IEngine (com.ramussoft.common.IEngine)5 ArrayList (java.util.ArrayList)5 Engine (com.ramussoft.common.Engine)4 IOException (java.io.IOException)4 DeleteStatus (com.ramussoft.common.DeleteStatus)3 AttributeType (com.ramussoft.common.AttributeType)2 AttributeEvent (com.ramussoft.common.event.AttributeEvent)2 ElementAdapter (com.ramussoft.common.event.ElementAdapter)2 ElementAttributeListener (com.ramussoft.common.event.ElementAttributeListener)2 ElementEvent (com.ramussoft.common.event.ElementEvent)2 QualifierAdapter (com.ramussoft.common.event.QualifierAdapter)2 QualifierEvent (com.ramussoft.common.event.QualifierEvent)2