
com.caucho.v5.kraken.query.TableBuilderKraken 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 Baratine(TM)
*
* Each copy or derived work must preserve the copyright notice and this
* notice unmodified.
*
* Baratine 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.
*
* Baratine 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 Baratine; 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.kraken.query;
import io.baratine.service.Result;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import com.caucho.v5.kelp.DatabaseKelp;
import com.caucho.v5.kelp.TableBuilderKelp;
import com.caucho.v5.kelp.TableKelp;
import com.caucho.v5.kraken.table.KelpManager;
import com.caucho.v5.kraken.table.PodHashGenerator;
import com.caucho.v5.kraken.table.TableManagerKraken;
import com.caucho.v5.util.L10N;
public class TableBuilderKraken
{
private static final L10N L = new L10N(TableBuilderKraken.class);
private final String _podName;
private final String _name;
private final String _sql;
private final Map _columnMap = new LinkedHashMap<>();
private ArrayList _key;
private PodHashGenerator _hashGen;
private HashExprGenerator _hashBuilder;
public TableBuilderKraken(String podName,
String name,
String sql)
{
_podName = podName;
_name = name;
_sql = sql;
}
public String getPodName()
{
return _podName;
}
public String getName()
{
return _name;
}
public String getId()
{
return getPodName() + '.' + getName();
}
public String getSql()
{
return _sql;
}
public void addInt16(String name)
{
_columnMap.put(name, new Int16Col(name));
}
public void addInt32(String name)
{
_columnMap.put(name, new Int32Col(name));
}
public void addInt64(String name)
{
_columnMap.put(name, new Int64Col(name));
}
public void addBytes(String name, int length)
{
_columnMap.put(name, new BytesCol(name, length));
}
public void addVarchar(String name, int length)
{
_columnMap.put(name, new StringCol(name));
}
public void addString(String name)
{
_columnMap.put(name, new StringCol(name));
}
public void addObject(String name)
{
_columnMap.put(name, new ObjectCol(name));
}
public void addVersion(String name)
{
_columnMap.put(name, new VersionCol(name));
}
public void addVarbinary(String name, int length)
{
}
public void addDateTime(String name)
{
}
public void addIdentity(String name)
{
throw new UnsupportedOperationException(getClass().getName());
}
public void setPrimaryKey(String name)
{
if (_key != null) {
throw new RuntimeException(L.l("primary key is already defined {0}",
name));
}
_key = new ArrayList<>();
_key.add(name);
}
/**
* @param parseColumnNames
*/
public void addPrimaryKey(ArrayList keys)
{
if (_key != null) {
throw new RuntimeException(L.l("primary key is already defined {0}",
keys));
}
_key = new ArrayList<>(keys);
}
/**
* @param name
*/
public void setNotNull(String name)
{
// TODO Auto-generated method stub
}
/**
* @param name
*/
public void addBlob(String name)
{
_columnMap.put(name, new BlobCol(name));
}
/**
* @param name
*/
public void addDouble(String name)
{
_columnMap.put(name, new DoubleCol(name));
}
public void setHashClass(Class> cl)
{
try {
_hashGen = (PodHashGenerator) cl.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void setHashGenerator(PodHashGenerator gen)
{
_hashGen = gen;
}
public void setHashBuilder(HashExprGenerator gen)
{
_hashBuilder = gen;
}
public PodHashGenerator buildHashGenerator(TableKelp tableKelp)
{
if (_hashGen != null) {
return _hashGen;
}
else if (_hashBuilder != null) {
return _hashBuilder.build(tableKelp);
}
else {
return null;
}
}
boolean isColumnPresent(String name)
{
return _columnMap.get(name) != null;
}
Col getColumn(String name)
{
return _columnMap.get(name);
}
public void create(TableManagerKraken tableManager,
Result
© 2015 - 2025 Weber Informatics LLC | Privacy Policy