Search in sources :

Example 11 with Database

use of com.wplatform.ddal.engine.Database in project jdbc-shards by wplatform.

the class Command method executeUpdate.

@Override
public int executeUpdate() {
    Database database = session.getDatabase();
    Object sync = session;
    boolean callStop = true;
    synchronized (sync) {
        Session.Savepoint rollback = session.setSavepoint();
        session.setCurrentCommand(this);
        try {
            while (true) {
                try {
                    return update();
                } catch (DbException e) {
                    throw e;
                } catch (OutOfMemoryError e) {
                    callStop = false;
                    database.shutdownImmediately();
                    throw DbException.convert(e);
                } catch (Throwable e) {
                    throw DbException.convert(e);
                }
            }
        } catch (DbException e) {
            e = e.addSQL(sql);
            SQLException s = e.getSQLException();
            if (s.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
                callStop = false;
                database.shutdownImmediately();
                throw e;
            }
            if (s.getErrorCode() == ErrorCode.DEADLOCK_1) {
                session.rollback();
            } else {
                session.rollbackTo(rollback, false);
            }
            throw e;
        } finally {
            try {
                if (callStop) {
                    stop();
                }
            } finally {
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Database(com.wplatform.ddal.engine.Database) Session(com.wplatform.ddal.engine.Session) DbException(com.wplatform.ddal.message.DbException)

Example 12 with Database

use of com.wplatform.ddal.engine.Database in project jdbc-shards by wplatform.

the class JdbcDataSource method init.

public synchronized void init() {
    if (inited) {
        return;
    }
    if (StringUtils.isNullOrEmpty(this.configLocation)) {
        throw new IllegalArgumentException("Property configLocation must not be null");
    }
    InputStream source = Utils.getResourceAsStream(configLocation);
    if (source == null) {
        throw new IllegalArgumentException("Can't load the configLocation resource " + configLocation);
    }
    XmlConfigParser parser = new XmlConfigParser(source);
    Configuration configuration = parser.parse();
    configuration.setProperty(SetTypes.MODE, this.dbType);
    if (this.maxMemoryRows > -1) {
        configuration.setProperty(SetTypes.MAX_MEMORY_ROWS, this.maxMemoryRows);
    }
    if (this.maxOperationMemory > -1) {
        configuration.setProperty(SetTypes.MAX_OPERATION_MEMORY, this.maxOperationMemory);
    }
    if (this.dataSourceProvider != null) {
        configuration.setDataSourceProvider(this.dataSourceProvider);
    }
    this.database = new Database(configuration);
    inited = true;
}
Also used : XmlConfigParser(com.wplatform.ddal.config.parser.XmlConfigParser) Configuration(com.wplatform.ddal.config.Configuration) InputStream(java.io.InputStream) Database(com.wplatform.ddal.engine.Database)

Aggregations

Database (com.wplatform.ddal.engine.Database)12 Expression (com.wplatform.ddal.command.expression.Expression)3 Column (com.wplatform.ddal.dbobject.table.Column)3 SQLException (java.sql.SQLException)3 ExpressionColumn (com.wplatform.ddal.command.expression.ExpressionColumn)2 DbException (com.wplatform.ddal.message.DbException)2 LocalResult (com.wplatform.ddal.result.LocalResult)2 Wildcard (com.wplatform.ddal.command.expression.Wildcard)1 Configuration (com.wplatform.ddal.config.Configuration)1 XmlConfigParser (com.wplatform.ddal.config.parser.XmlConfigParser)1 Schema (com.wplatform.ddal.dbobject.schema.Schema)1 TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)1 Mode (com.wplatform.ddal.engine.Mode)1 Session (com.wplatform.ddal.engine.Session)1 ValueString (com.wplatform.ddal.value.ValueString)1 InputStream (java.io.InputStream)1 ResultSetMetaData (java.sql.ResultSetMetaData)1