本文整理汇总了Java中org.voltdb.types.ConstraintType.get方法的典型用法代码示例。如果您正苦于以下问题:Java ConstraintType.get方法的具体用法?Java ConstraintType.get怎么用?Java ConstraintType.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.voltdb.types.ConstraintType
的用法示例。
在下文中一共展示了ConstraintType.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cloneConstraints
import org.voltdb.types.ConstraintType; //导入方法依赖的package包/类
/**
* @param src_db
* @param dest_db
*/
public static void cloneConstraints(Database src_db, Database dest_db) {
Catalog dest_catalog = dest_db.getCatalog();
for (Table src_tbl : src_db.getTables()) {
Table dest_tbl = dest_db.getTables().get(src_tbl.getName());
if (dest_tbl != null) {
for (Constraint src_cons : src_tbl.getConstraints()) {
// Only clone FKEY constraint if the other table is in the catalog
ConstraintType cons_type = ConstraintType.get(src_cons.getType());
if (cons_type != ConstraintType.FOREIGN_KEY || (cons_type == ConstraintType.FOREIGN_KEY && dest_db.getTables().get(src_cons.getForeignkeytable().getName()) != null)) {
Constraint dest_cons = clone(src_cons, dest_catalog);
assert (dest_cons != null);
}
} // FOR
}
} // FOR
}
示例2: ConstraintFailureException
import org.voltdb.types.ConstraintType; //导入方法依赖的package包/类
/**
* Constructor for deserializing an exception returned from the EE.
* @param exceptionBuffer
*/
public ConstraintFailureException(ByteBuffer exceptionBuffer) {
super(exceptionBuffer);
type = ConstraintType.get(exceptionBuffer.getInt());
try {
tableName = FastDeserializer.readString(exceptionBuffer);
}
catch (IOException e) {
// implies that the EE created an invalid constraint
// failure, which would be a corruption/defect.
throw new ServerFaultException("Unexpected error when deserializing exception from EE", e);
}
if (exceptionBuffer.hasRemaining()) {
int tableSize = exceptionBuffer.getInt();
buffer = ByteBuffer.allocate(tableSize);
//Copy the exception details.
exceptionBuffer.get(buffer.array());
} else {
buffer = ByteBuffer.allocate(0);
}
}
示例3: ConstraintFailureException
import org.voltdb.types.ConstraintType; //导入方法依赖的package包/类
/**
* Constructor for deserializing an exception returned from the EE.
* @param exceptionBuffer
*/
public ConstraintFailureException(ByteBuffer exceptionBuffer) {
super(exceptionBuffer);
type = ConstraintType.get(exceptionBuffer.getInt());
try {
tableName = FastDeserializer.readString(exceptionBuffer);
}
catch (IOException e) {
// implies that the EE created an invalid constraint
// failure, which would be a corruption/defect.
VoltDB.crashLocalVoltDB(e.getMessage(), true, e);
}
if (exceptionBuffer.hasRemaining()) {
int tableSize = exceptionBuffer.getInt();
buffer = ByteBuffer.allocate(tableSize);
//Copy the exception details.
exceptionBuffer.get(buffer.array());
} else {
buffer = ByteBuffer.allocate(0);
}
}
示例4: testToSchema
import org.voltdb.types.ConstraintType; //导入方法依赖的package包/类
/**
*
*/
public void testToSchema() {
String search_str = "";
// Simple check to make sure things look ok...
for (Table catalog_tbl : catalog_db.getTables()) {
String sql = CatalogUtil.toSchema(catalog_tbl);
assertTrue(sql.startsWith("CREATE TABLE " + catalog_tbl.getTypeName()));
// Columns
for (Column catalog_col : catalog_tbl.getColumns()) {
assertTrue(sql.indexOf(catalog_col.getTypeName()) != -1);
}
// Constraints
for (Constraint catalog_const : catalog_tbl.getConstraints()) {
ConstraintType const_type = ConstraintType.get(catalog_const.getType());
Index catalog_idx = catalog_const.getIndex();
// 2011-07-15: Skip all foreign keys
if (catalog_const.getType() == ConstraintType.FOREIGN_KEY.getValue()) continue;
assertNotNull("Missing index for " + catalog_const.fullName(), catalog_idx);
List<ColumnRef> columns = CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index");
if (!columns.isEmpty()) {
search_str = "";
String add = "";
for (ColumnRef catalog_colref : columns) {
search_str += add + catalog_colref.getColumn().getTypeName();
add = ", ";
}
assertTrue(sql.indexOf(search_str) != -1);
}
switch (const_type) {
case PRIMARY_KEY:
assertTrue(sql.indexOf("PRIMARY KEY") != -1);
break;
case FOREIGN_KEY:
search_str = "REFERENCES " + catalog_const.getForeignkeytable().getTypeName();
assertTrue(sql.indexOf(search_str) != -1);
break;
}
}
}
}
示例5: testForeignKeys
import org.voltdb.types.ConstraintType; //导入方法依赖的package包/类
public void testForeignKeys() {
String schemaPath = "";
try {
final URL url = new TPCCProjectBuilder().getDDLURL(true);
schemaPath = URLDecoder.decode(url.getPath(), "UTF-8");
} catch (final UnsupportedEncodingException e) {
e.printStackTrace();
System.exit(-1);
}
final String simpleProject =
"<?xml version=\"1.0\"?>\n" +
"<project>" +
"<database name='database'>" +
"<schemas><schema path='" + schemaPath + "' /></schemas>" +
"<procedures><procedure class='org.voltdb.compiler.procedures.TPCCTestProc' /></procedures>" +
"</database>" +
"</project>";
//System.out.println(simpleProject);
final File projectFile = VoltProjectBuilder.writeStringToTempFile(simpleProject);
final String projectPath = projectFile.getPath();
final VoltCompiler compiler = new VoltCompiler();
final ClusterConfig cluster_config = new ClusterConfig(1, 1, 0, "localhost");
final Catalog catalog = compiler.compileCatalog(projectPath, cluster_config);
assertNotNull(catalog);
// Now check that CUSTOMER correctly references DISTRICT
// (1) Make sure CUSTOMER has a fkey constraint
// (2) Make sure that each source column in CUSTOMER points to the constraint
// (3) Make sure that the fkey constraint points to DISTRICT
final Database catalog_db = catalog.getClusters().get("cluster").getDatabases().get("database");
assertNotNull(catalog_db);
final Table cust_table = catalog_db.getTables().get("CUSTOMER");
assertNotNull(cust_table);
final Table dist_table = catalog_db.getTables().get("DISTRICT");
assertNotNull(dist_table);
// In the code below, we will refer to the column that is pointed to by another column
// in the dependency as the parent, and the column with the fkey constraint as the child
boolean found = false;
for (final Constraint catalog_const : cust_table.getConstraints()) {
final ConstraintType const_type = ConstraintType.get(catalog_const.getType());
if (const_type == ConstraintType.FOREIGN_KEY) {
found = true;
assertEquals(dist_table, catalog_const.getForeignkeytable());
assertEquals(catalog_const.getForeignkeycols().size(), 2);
for (final ColumnRef catalog_parent_colref : catalog_const.getForeignkeycols()) {
// We store the name of the child column in the name of the ColumnRef catalog
// object to the parent
final Column catalog_child_col = cust_table.getColumns().get(catalog_parent_colref.getTypeName());
assertNotNull(catalog_child_col);
// Lame
boolean found_const_for_child = false;
for (final ConstraintRef catalog_constref : catalog_child_col.getConstraints()) {
if (catalog_constref.getConstraint().equals(catalog_const)) {
found_const_for_child = true;
break;
}
}
assertTrue(found_const_for_child);
final Column catalog_parent_col = catalog_parent_colref.getColumn();
assertEquals(dist_table, catalog_parent_col.getParent());
}
break;
}
}
assertTrue(found);
}
示例6: testToSchema
import org.voltdb.types.ConstraintType; //导入方法依赖的package包/类
/**
*
*/
public void testToSchema() {
String search_str = "";
// Simple check to make sure things look ok...
for (Table catalog_tbl : catalog_db.getTables()) {
StringBuilder sb = new StringBuilder();
CatalogSchemaTools.toSchema(sb, catalog_tbl, null, null);
String sql = sb.toString();
assertTrue(sql.startsWith("CREATE TABLE " + catalog_tbl.getTypeName()));
// Columns
for (Column catalog_col : catalog_tbl.getColumns()) {
assertTrue(sql.indexOf(catalog_col.getTypeName()) != -1);
}
// Constraints
for (Constraint catalog_const : catalog_tbl.getConstraints()) {
ConstraintType const_type = ConstraintType.get(catalog_const.getType());
Index catalog_idx = catalog_const.getIndex();
List<ColumnRef> columns = CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index");
if (!columns.isEmpty()) {
search_str = "";
String add = "";
for (ColumnRef catalog_colref : columns) {
search_str += add + catalog_colref.getColumn().getTypeName();
add = ", ";
}
assertTrue(sql.indexOf(search_str) != -1);
}
switch (const_type) {
case PRIMARY_KEY:
assertTrue(sql.indexOf("PRIMARY KEY") != -1);
break;
case FOREIGN_KEY:
search_str = "REFERENCES " + catalog_const.getForeignkeytable().getTypeName();
assertTrue(sql.indexOf(search_str) != -1);
break;
}
}
}
}