
com.caucho.v5.ramp.store.StoreRootRamp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of baratine Show documentation
Show all versions of baratine Show documentation
A reactive Java web server.
/*
* Copyright (c) 1998-2015 Caucho Technology -- all rights reserved
*
* This file is part of Resin(R)
*
* Each copy or derived work must preserve the copyright notice and this
* notice unmodified.
*
* Resin Open Source is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Resin Open Source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
* of NON-INFRINGEMENT. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with Resin Open Source; if not, write to the
*
* Free Software Foundation, Inc.
* 59 Temple Place, Suite 330
* Boston, MA 02111-1307 USA
*
* @author Scott Ferguson
*/
package com.caucho.v5.ramp.store;
import io.baratine.db.Cursor;
import io.baratine.db.DatabaseService;
import io.baratine.service.OnInit;
import io.baratine.service.OnLoad;
import io.baratine.service.OnLookup;
import io.baratine.service.Result;
import io.baratine.service.Service;
import io.baratine.service.ServiceRef;
import io.baratine.stream.ResultStream;
import com.caucho.v5.bartender.BartenderSystem;
import com.caucho.v5.bartender.pod.PodBartender;
import com.caucho.v5.kraken.KrakenSystem;
import com.caucho.v5.kraken.query.QueryKraken;
import com.caucho.v5.kraken.table.PodHashGenerator;
import com.caucho.v5.kraken.table.PodHashGeneratorColumn;
import com.caucho.v5.kraken.table.TableKraken;
import com.caucho.v5.kraken.table.TableManagerKraken;
import com.caucho.v5.ramp.keyvalue.StoreSync;
/*
* Entry to the store.
*/
@Service
public class StoreRootRamp
{
private final StoreSchemeRamp _scheme;
private final String _podName;
private final String _tableName;
private DatabaseService _db;
private TableKraken _table;
private String _insertSql;
private String _selectSql;
private String _removeSql;
private TableManagerKraken _tableManager;
private QueryKraken _insertQuery;
private QueryKraken _removeQuery;
private QueryKraken _selectQuery;
private ServiceRef _self;
public StoreRootRamp(StoreSchemeRamp scheme,
String podName)
{
_scheme = scheme;
if (podName == null || podName.isEmpty()) {
PodBartender pod = BartenderSystem.getCurrentPod();
podName = pod.name();
}
_podName = podName;
//_tableName = podName + ".baratine_store";
_tableName = podName + ".baratine_store";
}
@OnInit
private void onInit()
{
_self = ServiceRef.current();
}
@OnLookup
StoreRamp onLookup(String path)
{
return new StoreRamp(this, path);
}
StoreSync> lookup(String path)
{
return _self.service(_scheme + "://" + _podName + path).as(StoreSync.class);
}
@OnLoad
void onLoad(Result result)
{
if (_table != null) {
result.ok(true);
return;
}
_tableManager = KrakenSystem.current().getTableManager();
QueryKraken query = _tableManager.query("create table " + _tableName + " ("
+ " id string,"
+ " hash int16,"
+ " value object,"
+ " primary key (id, hash)"
+ ") with hash '" + PodHashGeneratorColumn.class.getName() + "'");
query.exec(result.of(table->completeCreate((TableKraken) table)));
// _db = db;
}
private boolean completeCreate(TableKraken table)
{
_table = table;
String insertSql = "insert into " + _tableName + " (id,hash,value) values (?,?,?)";
_insertQuery = _tableManager.query(insertSql);
String removeSql = "delete from " + _tableName + " where id=? and hash=?";
_removeQuery = _tableManager.query(removeSql);
String selectSql = "select value from " + _tableName + " where id=? and hash=?";
_selectQuery = _tableManager.query(selectSql);
return true;
}
public void get(String key, Result
© 2015 - 2025 Weber Informatics LLC | Privacy Policy