Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qwazr.database;
import com.fasterxml.jackson.core.type.TypeReference;
import com.qwazr.database.model.ColumnDefinition;
import com.qwazr.database.model.TableDefinition;
import com.qwazr.database.model.TableRequest;
import com.qwazr.database.model.TableRequestResult;
import com.qwazr.database.model.TableStatus;
import com.qwazr.database.store.KeyStore;
import com.qwazr.database.store.Query;
import com.qwazr.server.AbstractServiceImpl;
import com.qwazr.server.ServerException;
import com.qwazr.utils.LoggerUtils;
import com.qwazr.utils.ObjectMappers;
import javax.annotation.PostConstruct;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.logging.Logger;
class TableServiceImpl extends AbstractServiceImpl implements TableServiceInterface {
private static final Logger LOGGER = LoggerUtils.getLogger(TableServiceImpl.class);
private TableManager tableManager;
TableServiceImpl(TableManager tableManager) {
this.tableManager = tableManager;
}
public TableServiceImpl() {
this(null);
}
@PostConstruct
public void init() {
this.tableManager = getContextAttribute(TableManager.class);
}
@Override
public SortedSet list() {
return Collections.unmodifiableSortedSet(tableManager.getNameSet());
}
@Override
public TableDefinition createTable(final String tableName, KeyStore.Impl storeImplementation) {
try {
if (storeImplementation == null)
storeImplementation = KeyStore.Impl.leveldb;
tableManager.createTable(tableName, storeImplementation);
return new TableDefinition(storeImplementation, tableManager.getColumns(tableName));
} catch (Exception e) {
throw ServerException.getJsonException(LOGGER, e);
}
}
@Override
public TableStatus getTableStatus(String tableName) {
try {
return tableManager.getStatus(tableName);
} catch (IOException | ServerException e) {
throw ServerException.getJsonException(LOGGER, e);
}
}
@Override
public Boolean deleteTable(String tableName) {
try {
tableManager.deleteTable(tableName);
return true;
} catch (IOException | ServerException e) {
throw ServerException.getJsonException(LOGGER, e);
}
}
@Override
public Map getColumns(String tableName) {
try {
return tableManager.getColumns(tableName);
} catch (ServerException | IOException e) {
throw ServerException.getJsonException(LOGGER, e);
}
}
@Override
public ColumnDefinition getColumn(final String tableName, final String columnName) {
try {
return tableManager.getColumns(tableName).get(columnName);
} catch (ServerException | IOException e) {
throw ServerException.getJsonException(LOGGER, e);
}
}
@Override
public List