/** * getJoinColumn method return ColumnInfo for the join column * * @param columnType * * @param String * joinColumnName. * @return ColumnInfo object columnInfo. */ private ColumnInfo getJoinColumn(TableInfo tableInfo, String joinColumnName, Class columnType) { ColumnInfo columnInfo = new ColumnInfo(); columnInfo.setColumnName(joinColumnName); columnInfo.setIndexable(true); IndexInfo indexInfo = new IndexInfo(joinColumnName); tableInfo.addToIndexedColumnList(indexInfo); columnInfo.setType(columnType); return columnInfo; }
/** * Contains composite key. * * @param tableInfo * the table info * @return true, if successful */ private boolean containsCompositeKey(TableInfo tableInfo) { return tableInfo.getTableIdType() != null && tableInfo.getTableIdType().isAnnotationPresent(Embeddable.class); }
/** * Adds the to indexed column list. * * @param indexInfo * the index info */ public void addToIndexedColumnList(IndexInfo indexInfo) { ColumnInfo columnInfo = new ColumnInfo(); columnInfo.setColumnName(indexInfo.getColumnName()); if (getEmbeddedColumnMetadatas().isEmpty() || !getEmbeddedColumnMetadatas().get(0).getColumns().contains(columnInfo)) { if (!columnToBeIndexed.contains(indexInfo)) { columnToBeIndexed.add(indexInfo); } } } }
/** * @param tableInfo * @param collection */ private void createIndexes(TableInfo tableInfo, DBCollection collection) { // index normal column for (ColumnInfo columnInfo : tableInfo.getColumnMetadatas()) { if (columnInfo.isIndexable()) { IndexInfo indexInfo = tableInfo.getColumnToBeIndexed(columnInfo.getColumnName()); indexColumn(indexInfo, collection); } } // index embedded column. for (EmbeddedColumnInfo info : tableInfo.getEmbeddedColumnMetadatas()) { for (ColumnInfo columnInfo : info.getColumns()) { if (columnInfo.isIndexable()) { IndexInfo indexInfo = tableInfo.getColumnToBeIndexed(columnInfo.getColumnName()); indexEmbeddedColumn(indexInfo, info.getEmbeddedColumnName(), collection); } } } }
/** * Creates the index on table. * * @param tableInfo * the table info */ private void createIndexOnTable(TableInfo tableInfo) { List<IndexInfo> indexColumns = tableInfo.getColumnsToBeIndexed(); for (IndexInfo indexInfo : indexColumns) { if (indexInfo.getIndexType() != null && indexInfo.getIndexType().toLowerCase().equals(Constants.COMPOSITE)) { String[] columnNames = indexInfo.getColumnName().split(Constants.COMMA); createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), columnNames); } else { createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), indexInfo.getColumnName()); } } }
@Override protected void validate(List<TableInfo> tableInfos) { for (TableInfo tableInfo : tableInfos) { try { if (tableAPI.getTable(tableInfo.getTableName()) == null) { logger.error("No table found for " + tableInfo.getTableName()); throw new SchemaGenerationException("No table found for " + tableInfo.getTableName()); } } catch (FaultException e) { logger.error("Error while getting table " + tableInfo.getTableName() + ". Caused By: ", e); throw new SchemaGenerationException(e, "Error while getting table " + tableInfo.getTableName() + ". Caused By: "); } } }
/** * Validate compound key. * * @param tableInfo * the table info */ private void validateCompoundKey(TableInfo tableInfo) { if (tableInfo.getType() != null && tableInfo.getType().equals(Type.SUPER_COLUMN_FAMILY.name())) { throw new SchemaGenerationException( "Composite/Compound columns are not yet supported over Super column family by Cassandra", "cassandra", databaseName); } }
private void buildColumnsFromEmbeddableColumn(EmbeddedColumnInfo embColumnInfo, List<ColumnSchema> columns) { for (ColumnInfo columnInfo : embColumnInfo.getColumns()) { ColumnSchemaBuilder columnSchemaBuilder = new ColumnSchema.ColumnSchemaBuilder(columnInfo.getColumnName(), KuduDBValidationClassMapper.getValidTypeForClass(columnInfo.getType())); columns.add(columnSchemaBuilder.build()); } }
@Override protected void validate(List<TableInfo> tableInfos) { if (!clusterManager.hasBucket(databaseName)) { throw new SchemaGenerationException("Bucket [" + databaseName + "] does not exist."); } }
/** * Adds the column info. * * @param columnInfo * the column info */ public void addColumnInfo(ColumnInfo columnInfo) { if (this.columnMetadatas == null) { this.columnMetadatas = new ArrayList<ColumnInfo>(); } if (!columnMetadatas.contains(columnInfo) && !this.getIdColumnName().equals(columnInfo.getColumnName())) { columnMetadatas.add(columnInfo); } }
private HColumnDescriptor getColumnDescriptor(TableInfo tableInfo) { HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(tableInfo.getTableName()); setColumnFamilyProperties(hColumnDescriptor, tableInfo.getTableName()); return hColumnDescriptor; }
/** * Gets the column to be indexed. * * @param columnName * the column name * @return the column to be indexed */ public IndexInfo getColumnToBeIndexed(String columnName) { IndexInfo idxInfo = new IndexInfo(columnName); if (columnToBeIndexed.contains(idxInfo)) { int index = columnToBeIndexed.indexOf(idxInfo); return getColumnsToBeIndexed().get(index); } return idxInfo; }
/** * Contains embedded columns. * * @param tableInfo * the table info * @return true, if successful */ private boolean containsEmbeddedColumns(TableInfo tableInfo) { return !tableInfo.getEmbeddedColumnMetadatas().isEmpty(); }
/** * Contains collection columns. * * @param tableInfo * the table info * @return true, if successful */ private boolean containsCollectionColumns(TableInfo tableInfo) { return !tableInfo.getCollectionColumnMetadatas().isEmpty(); }
/** * Contains element collection columns. * * @param tableInfo * the table info * @return true, if successful */ private boolean containsElementCollectionColumns(TableInfo tableInfo) { return !tableInfo.getElementCollectionMetadatas().isEmpty(); }
private void checkMultipleLobs(TableInfo tableInfo) { if (tableInfo.getLobColumnInfo().size() > 1) throw new KunderaException("Multiple Lob fields in a single Entity are not supported in Kundera"); }
@Override public void dropSchema() { for (TableInfo tableInfo : tableInfos) { try { client.deleteTable(tableInfo.getTableName()); } catch (Exception ex) { logger.error("Error during deleting tables in kudu, Caused by: ", ex); throw new SchemaGenerationException(ex, "Kudu"); } } }
/** * Add {@link DiscriminatorColumn} for schema generation. * * @param tableInfo * table info. * @param entityType * entity type. */ private void onInheritedProperty(TableInfo tableInfo, EntityType entityType) { String discrColumn = ((AbstractManagedType) entityType).getDiscriminatorColumn(); if (discrColumn != null) { ColumnInfo columnInfo = new ColumnInfo(); columnInfo.setColumnName(discrColumn); columnInfo.setType(String.class); columnInfo.setIndexable(true); IndexInfo idxInfo = new IndexInfo(discrColumn); tableInfo.addColumnInfo(columnInfo); tableInfo.addToIndexedColumnList(idxInfo); } }
/** * Creates schema and table for the list of tableInfos. * * @param tableInfos * list of TableInfos. */ protected void create(List<TableInfo> tableInfos) { try { createOrUpdateKeyspace(tableInfos); } catch (Exception ex) { throw new SchemaGenerationException(ex); } }
/** * Checks whether the given table is a capped collection */ protected boolean isCappedCollection(TableInfo tableInfo) { return MongoDBPropertyReader.msmd != null ? MongoDBPropertyReader.msmd.isCappedCollection(databaseName, tableInfo.getTableName()) : false; }