Search in sources :

Example 21 with IPhonenumber

use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.

the class HsqldbCallerDatabaseHandler method buildCallerList.

protected ICallerList buildCallerList(IFilter[] filters) throws SQLException {
    ICallerList cl = this.getRuntime().getCallerFactory().createCallerList();
    if (!isConnected())
        return cl;
    StringBuffer sql = new StringBuffer();
    Statement stmt = m_con.createStatement();
    // build SQL statement
    sql.append("SELECT content FROM callers");
    if (hasAttributeFilter(filters))
        sql.append(", attributes");
    if (filters != null && filters.length > 0 && filters[0] != null) {
        IFilter f = null;
        sql.append(" WHERE ");
        for (int i = 0; i < filters.length; i++) {
            f = filters[i];
            if (i > 0)
                sql.append(" AND ");
            if (f.getType() == FilterType.PHONENUMBER) {
                IPhonenumber pn = (IPhonenumber) f.getFilterObject();
                sql.append("country='" + pn.getIntAreaCode() + "' AND areacode='" + pn.getAreaCode() + "'");
            }
            if (f.getType() == FilterType.ATTRIBUTE) {
                IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
                if (m != null && m.size() > 0) {
                    sql.append("(");
                    sql.append("callers.uuid=attributes.ref AND (");
                    Iterator iter = m.iterator();
                    IAttribute a = null;
                    while (iter.hasNext()) {
                        a = (IAttribute) iter.next();
                        sql.append("attributes.name='");
                        sql.append(a.getName());
                        sql.append("'");
                        sql.append(" AND ");
                        sql.append("attributes.value='");
                        sql.append(a.getValue());
                        sql.append("'");
                        if (iter.hasNext())
                            sql.append(" OR ");
                    }
                    sql.append("))");
                }
            }
            if (f.getType() == FilterType.CHARACTER) {
                sql.append("(");
                sql.append("callers.uuid=attributes.ref AND (");
                sql.append("attributes.name='");
                sql.append(((CharacterFilter) f).getAttributeName());
                sql.append("'");
                sql.append(" AND ");
                sql.append("(attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toUpperCase());
                sql.append("%'");
                sql.append(" OR attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toLowerCase());
                sql.append("%'");
                sql.append(")))");
            }
        }
    }
    sql.append(";");
    ResultSet rs = stmt.executeQuery(sql.toString());
    while (rs.next()) {
        try {
            cl.add(Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime()));
        } catch (SerializerException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    return cl;
}
Also used : CharacterFilter(de.janrufmonitor.repository.filter.CharacterFilter) Statement(java.sql.Statement) SerializerException(de.janrufmonitor.util.io.SerializerException) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) ResultSet(java.sql.ResultSet) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 22 with IPhonenumber

use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.

the class HsqldbMultiPhoneCallerDatabaseHandler method buildCallerList.

protected ICallerList buildCallerList(IFilter[] filters, ISearchTerm[] searchTerms) throws SQLException {
    ICallerList cl = this.getRuntime().getCallerFactory().createCallerList();
    if (!isConnected())
        return cl;
    StringBuffer sql = new StringBuffer();
    Statement stmt = m_con.createStatement();
    // build SQL statement
    sql.append("SELECT content FROM callers");
    if (hasAttributeFilter(filters))
        sql.append(", attributes");
    if (filters != null && filters.length > 0 && filters[0] != null) {
        IFilter f = null;
        sql.append(" WHERE ");
        for (int i = 0; i < filters.length; i++) {
            f = filters[i];
            if (i > 0)
                sql.append(" AND ");
            if (f.getType() == FilterType.PHONENUMBER) {
                IPhonenumber pn = (IPhonenumber) f.getFilterObject();
                // sql.append("country='"+pn.getIntAreaCode()+"' AND areacode='"+pn.getAreaCode()+"'");
                ResultSet rs = stmt.executeQuery("SELECT ref FROM phones WHERE country='" + pn.getIntAreaCode() + "' AND areacode='" + pn.getAreaCode() + "';");
                if (rs.next()) {
                    sql.append("uuid='");
                    sql.append(rs.getString(1));
                    sql.append("'");
                    while (rs.next()) {
                        sql.append(" OR uuid='");
                        sql.append(rs.getString(1));
                        sql.append("'");
                    }
                }
            }
            if (f.getType() == FilterType.ATTRIBUTE) {
                IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
                if (m != null && m.size() > 0) {
                    sql.append("(");
                    sql.append("callers.uuid=attributes.ref AND (");
                    Iterator iter = m.iterator();
                    IAttribute a = null;
                    while (iter.hasNext()) {
                        a = (IAttribute) iter.next();
                        sql.append("attributes.name='");
                        sql.append(a.getName());
                        sql.append("'");
                        sql.append(" AND ");
                        sql.append("attributes.value='");
                        sql.append(a.getValue());
                        sql.append("'");
                        if (iter.hasNext())
                            sql.append(" OR ");
                    }
                    sql.append("))");
                }
            }
            if (f.getType() == FilterType.CHARACTER) {
                sql.append("(");
                sql.append("callers.uuid=attributes.ref AND (");
                sql.append("attributes.name='");
                sql.append(((CharacterFilter) f).getAttributeName());
                sql.append("'");
                sql.append(" AND ");
                sql.append("(attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toUpperCase());
                sql.append("%'");
                sql.append(" OR attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toLowerCase());
                sql.append("%'");
                sql.append(")))");
            }
        }
        if (searchTerms != null && searchTerms.length > 0) {
            sql.append(" AND");
            sql.append(createSearchTerm(searchTerms));
        }
    } else {
        if (searchTerms != null && searchTerms.length > 0) {
            sql.append(" WHERE");
            sql.append(createSearchTerm(searchTerms));
        }
    }
    sql.append(";");
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info(sql.toString());
    ResultSet rs = stmt.executeQuery(sql.toString());
    while (rs.next()) {
        try {
            cl.add(Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime()));
        } catch (SerializerException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    return cl;
}
Also used : CharacterFilter(de.janrufmonitor.repository.filter.CharacterFilter) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SerializerException(de.janrufmonitor.util.io.SerializerException) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) ResultSet(java.sql.ResultSet) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 23 with IPhonenumber

use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.

the class AbstractFilterSerializer method getFilterFromString.

/**
 * Transforms a String representation of a filter into an IFilter object.
 * @param fstring string representation of the filter
 * @return a valid IFilter object or null, if string is invalid.
 */
public IFilter getFilterFromString(String fstring) {
    // IFilter filter = null;
    if (fstring.length() > 0) {
        StringTokenizer st = new StringTokenizer(fstring, ",");
        String token = null;
        if (st.countTokens() > 0) {
            token = st.nextToken().trim();
            FilterType ft = new FilterType(Integer.parseInt(token));
            if (ft.equals(FilterType.DATE)) {
                Date d1 = null;
                long dl1 = Long.parseLong(st.nextToken());
                if (dl1 > 0)
                    d1 = new Date(dl1);
                Date d2 = new Date(Long.parseLong(st.nextToken()));
                long frame = -1;
                if (st.hasMoreTokens())
                    frame = Long.parseLong(st.nextToken());
                // calculate today
                if (frame == -100) {
                    Calendar c = Calendar.getInstance();
                    c.set(Calendar.HOUR_OF_DAY, 0);
                    c.set(Calendar.MINUTE, 0);
                    c.set(Calendar.SECOND, 0);
                    d2 = c.getTime();
                    c.set(Calendar.HOUR_OF_DAY, 23);
                    c.set(Calendar.MINUTE, 59);
                    c.set(Calendar.SECOND, 0);
                    d1 = c.getTime();
                    return new DateFilter(d1, d2, frame);
                }
                if (frame == -101) {
                    Calendar c = Calendar.getInstance();
                    c.setFirstDayOfWeek(Calendar.MONDAY);
                    c.set(Calendar.DAY_OF_WEEK, c.get(Calendar.DAY_OF_WEEK) - 1);
                    // 2008/03/25: fixed sunday switch bug
                    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                        c.add(Calendar.WEEK_OF_MONTH, -1);
                        c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
                    }
                    c.set(Calendar.HOUR_OF_DAY, 0);
                    c.set(Calendar.MINUTE, 0);
                    c.set(Calendar.SECOND, 0);
                    d2 = c.getTime();
                    c.set(Calendar.HOUR_OF_DAY, 23);
                    c.set(Calendar.MINUTE, 59);
                    c.set(Calendar.SECOND, 0);
                    d1 = c.getTime();
                    return new DateFilter(d1, d2, frame);
                }
                if (frame == -107) {
                    Calendar c = Calendar.getInstance();
                    c.set(Calendar.HOUR_OF_DAY, 23);
                    c.set(Calendar.MINUTE, 59);
                    c.set(Calendar.SECOND, 0);
                    d1 = c.getTime();
                    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
                    c.set(Calendar.HOUR_OF_DAY, 0);
                    c.set(Calendar.MINUTE, 0);
                    c.set(Calendar.SECOND, 0);
                    d2 = c.getTime();
                    return new DateFilter(d1, d2, frame);
                }
                if (frame == -108) {
                    Calendar c = Calendar.getInstance();
                    c.add(Calendar.WEEK_OF_MONTH, -1);
                    c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
                    c.set(Calendar.HOUR_OF_DAY, 23);
                    c.set(Calendar.MINUTE, 59);
                    c.set(Calendar.SECOND, 0);
                    d1 = c.getTime();
                    c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                    c.set(Calendar.HOUR_OF_DAY, 0);
                    c.set(Calendar.MINUTE, 0);
                    c.set(Calendar.SECOND, 0);
                    d2 = c.getTime();
                    return new DateFilter(d1, d2, frame);
                }
                if (frame == -130) {
                    Calendar c = Calendar.getInstance();
                    c.set(Calendar.HOUR_OF_DAY, 23);
                    c.set(Calendar.MINUTE, 59);
                    c.set(Calendar.SECOND, 0);
                    d1 = c.getTime();
                    c.set(Calendar.DAY_OF_MONTH, 1);
                    c.set(Calendar.HOUR_OF_DAY, 0);
                    c.set(Calendar.MINUTE, 0);
                    c.set(Calendar.SECOND, 0);
                    d2 = c.getTime();
                    return new DateFilter(d1, d2, frame);
                }
                if (frame == -131) {
                    Calendar c = Calendar.getInstance();
                    c.add(Calendar.MONTH, -1);
                    c.set(Calendar.HOUR_OF_DAY, 23);
                    c.set(Calendar.MINUTE, 59);
                    c.set(Calendar.SECOND, 0);
                    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
                    d1 = c.getTime();
                    c.set(Calendar.DAY_OF_MONTH, 1);
                    c.set(Calendar.HOUR_OF_DAY, 0);
                    c.set(Calendar.MINUTE, 0);
                    c.set(Calendar.SECOND, 0);
                    d2 = c.getTime();
                    return new DateFilter(d1, d2, frame);
                }
                if (frame > -1)
                    return new DateFilter(frame);
                return new DateFilter(d1, d2);
            }
            if (ft.equals(FilterType.YEAR)) {
                String y = st.nextToken();
                return new YearFilter(Integer.parseInt(y));
            }
            if (ft.equals(FilterType.MONTH_YEAR)) {
                String y = st.nextToken();
                String m = st.nextToken();
                return new MonthYearFilter(Integer.parseInt(y), Integer.parseInt(m));
            }
            if (ft.equals(FilterType.MSN)) {
                IMsn[] msns = new IMsn[st.countTokens()];
                int i = 0;
                while (st.hasMoreTokens()) {
                    msns[i] = this.getRuntime().getCallFactory().createMsn(st.nextToken(), "");
                    i++;
                }
                return new MsnFilter(msns);
            }
            if (ft.equals(FilterType.CIP)) {
                String cip = st.nextToken();
                return new CipFilter(this.getRuntime().getCallFactory().createCip(cip, ""));
            }
            if (ft.equals(FilterType.CALLER)) {
                String caller = st.nextToken();
                if (caller.equalsIgnoreCase("clired")) {
                    IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(true);
                    ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn);
                    return new CallerFilter(c);
                }
                if (caller.equalsIgnoreCase(IJAMConst.INTERNAL_CALL)) {
                    IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(caller, "", st.nextToken());
                    ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn);
                    return new CallerFilter(c);
                } else {
                    IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(caller, st.nextToken(), st.nextToken());
                    ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn);
                    return new CallerFilter(c);
                }
            }
            if (ft.equals(FilterType.PHONENUMBER)) {
                String intarea = st.nextToken();
                String area = "";
                String number = "";
                if (st.hasMoreTokens())
                    area = st.nextToken().trim();
                if (area.equalsIgnoreCase("+"))
                    area = "";
                if (st.hasMoreTokens())
                    number = st.nextToken().trim();
                if (number.equalsIgnoreCase("+"))
                    number = "";
                IPhonenumber pn = this.getRuntime().getCallerFactory().createPhonenumber(intarea, area, number);
                return new PhonenumberFilter(pn);
            }
            if (ft.equals(FilterType.ITEMCOUNT)) {
                String limit = st.nextToken().trim();
                return new ItemCountFilter(Integer.parseInt(limit));
            }
            if (ft.equals(FilterType.ATTRIBUTE)) {
                IAttributeMap m = getRuntime().getCallFactory().createAttributeMap();
                // return new AttributeFilter(m);
                String[] t = null;
                while (st.hasMoreTokens()) {
                    t = st.nextToken().split("=");
                    m.add(getRuntime().getCallFactory().createAttribute(t[0], t[1]));
                }
                return new AttributeFilter(m);
            }
            if (ft.equals(FilterType.CHARACTER)) {
                String[] t = st.nextToken().split("=");
                return new CharacterFilter(t[1].trim(), t[0].trim());
            }
            if (ft.equals(FilterType.UUID)) {
                String[] uuids = st.nextToken().split(";");
                return new UUIDFilter(uuids);
            }
        // TODO: more filters to be added here
        }
    }
    return null;
}
Also used : Calendar(java.util.Calendar) Date(java.util.Date) ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMsn(de.janrufmonitor.framework.IMsn) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 24 with IPhonenumber

use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.

the class AbstractCallerDatabaseHandler method insertOrUpdateCallerList.

/**
 * Insert the callers in the list or update the callers if it already exists.
 *
 * @param cl
 * @throws SQLException
 */
public void insertOrUpdateCallerList(ICallerList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    PreparedStatement insert_caller = this.getStatement("INSERT_CALLER");
    PreparedStatement insert_attributes = this.getStatement("INSERT_ATTRIBUTE");
    PreparedStatement update_caller = this.getStatement("UPDATE_CALLER");
    PreparedStatement update_caller_phone = this.getStatement("UPDATE_CALLER_PHONE");
    PreparedStatement update_attributes = this.getStatement("UPDATE_ATTRIBUTE");
    insert_caller.clearBatch();
    insert_attributes.clearBatch();
    update_caller.clearBatch();
    update_caller_phone.clearBatch();
    update_attributes.clearBatch();
    List uuid_check = new ArrayList(cl.size());
    ICaller c = null;
    IPhonenumber pn = null;
    String uuid = null;
    for (int i = 0, j = cl.size(); i < j; i++) {
        c = cl.get(i);
        if (this.m_logger.isLoggable(Level.INFO) && c != null)
            this.m_logger.info("Adding to database: " + c.toString());
        // check if redundant uuid could occure
        uuid = c.getUUID();
        if (uuid_check.contains(uuid)) {
            this.m_logger.warning("Found duplicated UUID: " + c.toString());
            c.setUUID(new UUID().toString());
            uuid = c.getUUID();
        }
        uuid_check.add(uuid);
        pn = c.getPhoneNumber();
        if (this.existsCaller(c)) {
            // do an update
            try {
                this.updateCaller(update_caller, c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber(), Serializer.toByteArray(c));
                this.updateAttributes(update_attributes, c.getUUID(), c.getAttributes());
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else if (this.existsCaller(pn)) {
            try {
                this.updateCallerPhone(update_caller_phone, c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else {
            // do an insert
            try {
                this.createCaller(insert_caller, c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        if (i % this.commit_count == 0) {
            try {
                insert_caller.executeBatch();
                insert_caller.clearBatch();
                insert_attributes.executeBatch();
                insert_attributes.clearBatch();
                update_caller.executeBatch();
                update_caller.clearBatch();
                update_caller_phone.executeBatch();
                update_caller_phone.clearBatch();
                update_attributes.executeBatch();
                update_attributes.clearBatch();
                this.m_logger.info("-------------------> executed Batch");
            } catch (SQLException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage() + c.toString(), e);
            // throw new SQLException("Batch execution failed: ");
            }
        }
    }
    // execute the rest batch content
    insert_caller.executeBatch();
    insert_attributes.executeBatch();
    update_caller.executeBatch();
    update_caller_phone.executeBatch();
    update_attributes.executeBatch();
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) UUID(de.janrufmonitor.util.uuid.UUID) SerializerException(de.janrufmonitor.util.io.SerializerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 25 with IPhonenumber

use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.

the class AbstractMultiPhoneCallerDatabaseHandler method insertOrUpdateCallerList.

/**
 * Insert the callers in the list or update the callers if it already
 * exists.
 *
 * @param cl
 * @throws SQLException
 */
public void insertOrUpdateCallerList(ICallerList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    // check prepared statements
    PreparedStatement insert_caller = this.getStatement("INSERT_CALLER");
    PreparedStatement insert_attributes = this.getStatement("INSERT_ATTRIBUTE");
    PreparedStatement insert_phones = this.getStatement("INSERT_PHONE");
    PreparedStatement update_caller = this.getStatement("UPDATE_CALLER");
    PreparedStatement delete_phones = this.getStatement("DELETE_PHONE");
    PreparedStatement delete_phones2 = this.getStatement("DELETE_PHONE2");
    PreparedStatement delete_attributes = this.getStatement("DELETE_ATTRIBUTE");
    // clean up prpared statements
    insert_caller.clearBatch();
    insert_attributes.clearBatch();
    insert_phones.clearBatch();
    update_caller.clearBatch();
    delete_attributes.clearBatch();
    delete_phones.clearBatch();
    delete_phones2.clearBatch();
    // list for redundant UUIDs checks
    List uuid_check = new ArrayList(cl.size());
    ICaller c = null;
    String uuid = null;
    List phones = new ArrayList(1);
    for (int i = 0, j = cl.size(); i < j; i++) {
        c = cl.get(i);
        if (this.m_logger.isLoggable(Level.INFO) && c != null)
            this.m_logger.info("Adding to database: " + c.toString());
        // check if redundant uuid could occure
        uuid = c.getUUID();
        if (uuid_check.contains(uuid)) {
            this.m_logger.warning("Found duplicated UUID: " + c.toString());
            c.setUUID(new UUID().toString());
            uuid = c.getUUID();
        }
        uuid_check.add(uuid);
        // check which type of Interface the caller object implements
        if (!(c instanceof IMultiPhoneCaller)) {
            if (this.m_logger.isLoggable(Level.INFO) && c != null)
                this.m_logger.info("Caller is not type IMultiPhoneCaller. Transforming is triggered... : " + c.toString());
            c = this.getRuntime().getCallerFactory().toMultiPhoneCaller(c);
            // 2008/11/30: added to fix duplicated address book entries after category assignement
            c.setUUID(uuid);
        }
        phones.clear();
        phones.addAll(((IMultiPhoneCaller) c).getPhonenumbers());
        // check if single caller (uuid) is already in DB
        if (existsCaller(c)) {
            internalUpdate(c);
            if (this.m_logger.isLoggable(Level.INFO) && c != null)
                this.m_logger.info("Caller already exists in database. Update is triggered: " + c.toString());
            try {
                // update caller table
                this.updateCaller(update_caller, c.getUUID(), Serializer.toByteArray(c));
                // update attributes table
                this.deleteAttributes(delete_attributes, c.getUUID());
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
                // update phones table
                this.deletePhone(delete_phones, c.getUUID());
                IPhonenumber p = null;
                for (int a = 0, b = phones.size(); a < b; a++) {
                    p = (IPhonenumber) phones.get(a);
                    this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else if (this.existsPhones(phones).size() > 0) {
            internalInsert(c);
            // check if phone numnbers are already in DB and overwrite them
            List existingPhones = this.existsPhones(phones);
            IPhonenumber pn = null;
            for (int a = 0, b = existingPhones.size(); a < b; a++) {
                pn = (IPhonenumber) existingPhones.get(a);
                if (this.m_logger.isLoggable(Level.INFO) && c != null)
                    this.m_logger.info("Phone already exists in database. Update is triggered: " + pn.toString());
                this.deletePhone(delete_phones2, pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber());
            }
            try {
                this.createCaller(insert_caller, c.getUUID(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
                IPhonenumber p = null;
                for (int a = 0, b = phones.size(); a < b; a++) {
                    p = (IPhonenumber) phones.get(a);
                    this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else {
            internalInsert(c);
            // insert new caller
            try {
                this.createCaller(insert_caller, c.getUUID(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
                IPhonenumber p = null;
                for (int a = 0, b = phones.size(); a < b; a++) {
                    p = (IPhonenumber) phones.get(a);
                    this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        if (i % this.commit_count == 0) {
            try {
                delete_attributes.executeBatch();
                delete_attributes.clearBatch();
                this.m_logger.info("Batch DELETE_ATTRIBUTES executed...");
                delete_phones.executeBatch();
                delete_phones.clearBatch();
                this.m_logger.info("Batch DELETE_PHONES executed...");
                delete_phones2.executeBatch();
                delete_phones2.clearBatch();
                this.m_logger.info("Batch DELETE_PHONES2 executed...");
                insert_caller.executeBatch();
                insert_caller.clearBatch();
                this.m_logger.info("Batch INSERT_CALLER executed...");
                insert_attributes.executeBatch();
                insert_attributes.clearBatch();
                this.m_logger.info("Batch INSERT_ATTRIBUTES executed...");
                insert_phones.executeBatch();
                insert_phones.clearBatch();
                this.m_logger.info("Batch INSERT_PHONES executed...");
                update_caller.executeBatch();
                update_caller.clearBatch();
                this.m_logger.info("Batch UPDATE_CALLER executed...");
            } catch (SQLException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage() + c.toString(), e);
            // throw new SQLException("Batch execution failed: ");
            }
        }
    }
    // execute the rest batch content
    delete_attributes.executeBatch();
    delete_attributes.clearBatch();
    this.m_logger.info("Batch DELETE_ATTRIBUTES executed...");
    delete_phones.executeBatch();
    delete_phones.clearBatch();
    this.m_logger.info("Batch DELETE_PHONES executed...");
    delete_phones2.executeBatch();
    delete_phones2.clearBatch();
    this.m_logger.info("Batch DELETE_PHONES2 executed...");
    insert_caller.executeBatch();
    insert_caller.clearBatch();
    this.m_logger.info("Batch INSERT_CALLER executed...");
    insert_attributes.executeBatch();
    insert_attributes.clearBatch();
    this.m_logger.info("Batch INSERT_ATTRIBUTES executed...");
    insert_phones.executeBatch();
    insert_phones.clearBatch();
    this.m_logger.info("Batch INSERT_PHONES executed...");
    update_caller.executeBatch();
    update_caller.clearBatch();
    this.m_logger.info("Batch UPDATE_CALLER executed...");
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) UUID(de.janrufmonitor.util.uuid.UUID) SerializerException(de.janrufmonitor.util.io.SerializerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IPhonenumber (de.janrufmonitor.framework.IPhonenumber)99 ICaller (de.janrufmonitor.framework.ICaller)62 List (java.util.List)49 ArrayList (java.util.ArrayList)44 IAttribute (de.janrufmonitor.framework.IAttribute)38 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)37 ICallerList (de.janrufmonitor.framework.ICallerList)36 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)26 ICall (de.janrufmonitor.framework.ICall)19 SQLException (java.sql.SQLException)19 IMsn (de.janrufmonitor.framework.IMsn)17 Date (java.util.Date)17 IOException (java.io.IOException)16 ICip (de.janrufmonitor.framework.ICip)13 IName (de.janrufmonitor.framework.IName)13 File (java.io.File)13 Iterator (java.util.Iterator)13 ITreeItemCallerData (de.janrufmonitor.ui.jface.application.ITreeItemCallerData)9 UUID (de.janrufmonitor.util.uuid.UUID)9 FileInputStream (java.io.FileInputStream)9